excel client in python

Scott Hathaway slhath at home.com
Tue Dec 26 18:09:13 EST 2000


Hello,

I have the following vba code from Excel that I want to convert to python
code to manipulate excel from python.  Can anyone help me translate?

  Workbooks.Open Filename="C:\test.html"
  ActiveWorkbook.SaveAs Filename:="C:\test2.xls", FileFormat:=xlNormal, _
        Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
        CreateBackup:=False

Here is what I have tried (among many other things):

import win32com.client
myExcel = win32com.client.Dispatch('Excel.Application')

myExcel.Workbooks.Open('c:\\test.html')
myExcel.ActiveWorkbook.SaveAs('c:\\test3.xls', 'xlNormal', '', '', 0, 0)

Here is the error I get:

C:\>python excel.py
Traceback (most recent call last):
  File "excel.py", line 7, in ?
    myExcel.ActiveWorkbook.SaveAs('c:\\test3.xls', 'xlNormal', '', '', 0, 0)
  File "<COMObject <unknown>>", line 2, in SaveAs
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft
Excel'
, 'SaveAs method of Workbook class failed', 'C:\\Program Files\\Microsoft
Office
\\Office\\1033\\xlmain9.chm', 0, -2146827284), None)

Can anyone help?

Scott








More information about the Python-list mailing list