我正在使用Word 2013自动创建一个报告文件并将其保存为pdf格式。
但是,当我调用SaveAs2()函数时,脚本弹出“另存为”窗口,并抛出以下异常:
(-2147352567, 'Exception occurred.', (0, u'Microsoft Word', u'Command failed', u'wdmain11.chm', 36966, -2146824090), None)
这是我的代码,用于打开并另存为一个新文件:
self.path = os.path.abspath(path)
self.wordApp = win32.Dispatch('Word.Application') #create a word application object
self.wordApp.Visible = False # if false hide the word application (app does't open but still usable)
self.document = self.wordApp.Documents.Open(self.path + "/" + documentRef) # opening the template file
absFileName = "D:\\test.pdf"
self.document.SaveAs2(FileName=absFileName,FileFormat=17)
我正在使用:
Python2.7和pywin32 (build 219)
有没有人知道为什么它无法工作?