问题描述
def messagetoCal(path,calculatorName,argList,eventName,fucName,PCBName):
# location of LED calculator
loc = path+calculatorName
#print loc
# open excel,run macro called "external_Run" with argList
xls=win32com.client.dispatch("Excel.Application")
wb = xls.Workbooks.Open(Filename=loc)
try:
xls.Application.Run("external_Run",argList)
except Exception as e:
print "--------------- ERROR ------------------"
print(e)
print "=> No data was found,please check your input file"
raise
#xls.Visible = True
# disable asking dialog when close excel
xls.displayAlerts = False
# export first sheet (macro output) to csv
w=wb.Worksheets(1)
w.SaveAs(path +'#'+eventName+'_'+fucName+'_'+PCBName.replace(".","")+'_' +str(argList[3])+ '.csv',6)
xls.Application.Quit()
del xls
**w=wb.Worksheets(1)
AttributeError: 'nonetype' object has no attribute 'Worksheets'**
以前它运行良好。突然抛出错误。
解决方法
某种原因导致您的代码无法正确打开工作簿。这导致wb
被设置为None
。这就是为什么尝试访问wb.Worksheets(1)
时会出现AttributeError的原因。
如果代码中的任何内容均未更改,则可能是电子表格中的某些内容导致了错误。除了查看电子表格的最近更改以确定问题的真正原因之外,您还需要验证电子表格的位置是否正确。