从abaqus的python脚本中读取excel数据

时间:2015-03-22 07:06:52

标签: python excel 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)

当我运行此脚本时,错误会弹出无效文件。

1 个答案:

答案 0 :(得分:1)

我建议你使用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