简体   繁体   中英

Reading excel data from python script for abaqus

I am using abaqus and I want to read values from excel file like(x,y,z) and I want to get get an output for it, in the excel file itself. Plz guide me I been trying it but I didn't got much.

      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)

when I run this script an error pop out invalid file.

I recommend you use xlwings, here's how you interact with an excel file:

#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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM