我無法使用pywin32打開word文件。我一直在試圖找到pywin32的教程,但沒有任何代碼的作品。 word文檔的位置是isn的C:\ Users \ User \ Documents \ python progs \ misc \ formatting。在pywin32中打開MS Word文件
import win32com.client as win32
word = win32.gencache.EnsureDispatch('Word.Application')
word.Visible = False
word.Documents.Open('C:\\sectarianism.doc')
Traceback (most recent call last):
File "C:\Users\User\Documents\python progs\misc\formatting for isn\formatting.py", line 5, in <module>
word.Documents.Open('C:\\sectarianism.doc')
File "C:\Python25\lib\site-packages\win32com\gen_py\00020905-0000-0000-C000-000000000046x0x8x4\Documents.py", line 96, in Open
, Visible, OpenAndRepair, DocumentDirection, NoEncodingDialog, XMLTransform
com_error: (-2147352567, 'Exception occurred.', (0, u'Microsoft Word', u'This file could not be found.\r (C:\\sectarianism.doc)', u'C:\\Program Files\\Microsoft Office\\Office12\\1033\\WDMAIN11.CHM', 24654, -2146823114), None)
>>>
我的確完成了Daniel Wigmore所做的事情,但它並沒有奏效,然後我做了@rattray所建議的事情,它讓我確切知道我需要去哪裏。優秀! – cjohnson318 2013-12-05 14:30:01