簡體   English   中英

從python腳本讀取Excel數據進行abaqus

[英]Reading excel data from python script for abaqus

我正在使用abaqus,我想從excel文件中讀取值(x,y,z),並希望在excel文件本身中獲得輸出。 請Plz指導我我一直在嘗試,但是我沒有太多。

      enter code here     
 # -*- coding: mbcs -*-
 from part import *
 from material import *
 from section import *
 from assembly import * 
 from step import *
 from interaction import *
 from load import *
 from mesh import *
 from optimization import *
 from job import *
 from sketch import *
 from visualization import *
 from connectorBehavior import *
 from xlrd import *
 file_location=('C:\Users\Lenovo\Desktop/calling.xlsx')
 workbook=xlrd.open_workbook(file_location)
 sheet=workbook.sheet_by_index(0)
 for col in range(sheet.ncols)
 sheet.cell_value(nrow,col)

當我運行此腳本時,錯誤彈出無效文件。

我建議您使用xlwings,這是與excel文件進​​行交互的方式:

#Import xlwings parts
from xlwings import Workbook, Sheet, Range, Chart
#import os
import os
#get workbook direction, I'm supposing it's in same folder than this script!

direction=os.path.join(os.getcwd(),"activo.xlsx")
#if it's not, put it yourself:
#direction="yourPathToFile/yourExcelFile.xls"


#open the workbook
wb = Workbook(direction) 
#select the sheet
shname=Sheet(1).name

#from python to excel

pythonVar="I'm writting in excel!"
Range(shname,'A1',wkb=wb).value = pythonVar

#from excel to python
readValue=Range(shname,'A1',wkb=wb).value
print readValue

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM