gpt4 book ai didi

python - 尝试使用Win32保存Excel文件时出现属性错误

转载 作者:行者123 更新时间:2023-12-03 07:58:29 26 4
gpt4 key购买 nike

以下是来自代码的684行

try:
xlBook.SaveAs("%s/ContingencyFile.xlsx" %(os.getcwd()))
xlApp.DisplayAlerts = True
except:
xlApp.xlBook.Close
xlBook.SaveAs("%s/ContingencyFile.xlsx" %(os.getcwd()))
xlApp.DisplayAlerts = True

这是我在运行程序时遇到的错误-
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1410, in __call__
return self.func(*args)
File "H:\proj4\combine.py", line 684, in ProcessNewFile
xlApp.xlBook.Close
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 516,
in__getattr__
raise AttributeError("%s.%s" % (self._username_, attr))
AttributeError: Excel.Application.xlBook

我如何摆脱错误?

最佳答案

试试看

xlBook.Close() # or xlApp.xlBook.Close() ?

您不会在没有 ()的情况下调用方法,这就是它引发此 AttributeError的原因。

(也许在?之前做 SaveAs(...),我不确定...)

关于python - 尝试使用Win32保存Excel文件时出现属性错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44958020/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com