【发布时间】:2017-05-20 10:04:39
【问题描述】:
这是上周的工作,但由于某种原因它今天停止工作,也许是因为新年?
def remove_strikethroughs(xlsx):
excel = win32com.client.Dispatch('Excel.Application')
xl = pd.ExcelFile(xlsx)
sheet_names = xl.sheet_names
for sheet in sheet_names:
if any(tab in sheet for tab in tabs_used):
#print (sheet)
wb = excel.Workbooks.Open(xlsx)
ws = wb.WorkSheets(sheet)
for cell in ws.Range('A5:B150'):
if cell.Font.Strikethrough == True:
cell.value = '[MDU]' + str(cell)
wb.Save()
wb.Close()
excel.Visible = True
excel.DisplayAlerts = True
excel.Application.Quit()
我收到以下错误消息:
"AttributeError: '<win32com.gen_py.Microsoft Excel 15.0 Object Library.Workbooks instance at 0x20920640>' object has no attribute 'open'"
有人可以帮忙吗?
谢谢!
【问题讨论】:
-
那里的任何地方都没有调用小写“open”,你确定你发布了你正在使用的代码吗?