这个简单的代码不起作用。我确定文件路径是正确的,但似乎问题来自未能使用“Workbooks.Add”功能打开/添加工作簿。这是代码:
from win32com.client import Dispatch
#processing the results
excel = Dispatch('Excel.Application')
excel.Workbooks.Add('C:\\Documents and Settings\\dell600\\My Documents\\Webscraping Output\\Results\\Processed Results.xls')
excel.Run('Apply_Process')
excel.DisplayAlerts = 0
excel.Quit()
excel.DisplayAlerts = 0
这是错误消息:
Traceback (most recent call last):
File "TestMacro", line 6, in <module>
excel.Run('Apply_Process')
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line282, in _ApplyTypes_
result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes) + args)
pywintypes.com_error: (-2147352567, 'Exception occured.', (0, None, None, None, 0, -2146771191), None)