从 excel 表生成 pdf 时出现以下错误:
ws.ExportAsFixedFormat(0, save_as)
File "<COMObject <unknown>>", line 5, in ExportAsFixedFormat
com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024809), None)
下面是我的代码:
pythoncom.CoInitialize()
xlApp = client.Dispatch("Excel.Application")
logging.debug("Saving excel file {} to file {}".format(filename, save_as))
books = xlApp.Workbooks.Open(filename)
ws = books.Worksheets[0]
ws.Visible = 1
ws.ExportAsFixedFormat(0, save_as)
books.Close(True)
xlApp.Quit()
它在我安装了 office 365 的笔记本电脑上运行,但在安装了 Microsoft office 2007 的另一个系统上出现上述错误。
Python 版本:python 2.7
openpyxl : 2.4.5
pywin32: 224
没有足够的文档。如果有人可以提供调试它并理解错误的指针,那将是很大的帮助。
最佳答案
我在使用 xlwings 与 Excel 交互时遇到了同样的错误。 xlwings 还在后端使用 win32com 客户端。 我认为这不是 Excel 版本问题。 我意识到只要执行代码并且 excel 文件(包含数据)不在焦点中,就会弹出此错误。为了解决这个问题,我只需选择正在处理的文件并运行代码,它总是对我有效。
关于python - com_error : (-2147352567, 'Exception occurred.',(0,无,无,无,0,-2147024809),无),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55088710/