我在用 python 编写的文件转换脚本中遇到了一个奇怪的错误。我正在使用 comtypes 库将不同类型的文件转换为 pdf,并且出于某种原因,module 'comtypes.gen.Excel' has no attribute '_Application'每当我尝试为 Excel 应用程序创建客户端对象时,都会出现这种情况。我似乎无法在网上找到任何针对此问题的信息。该脚本大约一两个月前工作正常,所以我很困惑为什么它不再工作了 - 我唯一能想到的是 Excel 更新或其他东西(如果这很重要的话)。如果相关的话,我有2016年的办公室。如果有人经历过这个错误或有任何想法,我们将不胜感激。这是脚本,供参考:
import comtypes.client
excel = comtypes.client.CreateObject("Excel.Application") # exception here
excel.Visible = False
in_file = "INPUT_FILE"
out_file = "OUT_FILE"
f = excel.Workbooks.Open(in_file)
f.ExportAsFixedFormat(0, out_file, 1, 0)
f.Close()
excel.Close()
Run Code Online (Sandbox Code Playgroud)