1

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.

NorthCat
  • 9,643
  • 16
  • 47
  • 50
  • Can you tell us where nrow is defined? You should also add an 'r' in front of the path string to avoid the backslash interpretation file_location=(r'C:\Users\Lenovo\Desktop/calling.xlsx') – Vivian De Smedt Mar 22 '15 at 12:28
  • why are you mixing forward and backslash notation in your path? – agentp Mar 22 '15 at 14:31
  • http://stackoverflow.com/questions/19095796/how-to-print-backslash-with-python – agentp Mar 22 '15 at 14:34
  • It is better to use forward slashes for a [Windows path in Python](https://stackoverflow.com/questions/2953834/) anyway. – Karl Knechtel Aug 07 '22 at 04:43

1 Answers1

1

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