[python-win32] win32com client Workbooks.Open throws exeption

@©ħα® preempt at gmail.com
Thu Aug 12 15:34:32 CEST 2010


Workbooks.Open fails randomly throws an exception

Code:

def logToXLS(fileNameXLS,worksheetNum,row,col,data):

            import win32com.client

            fileName=fileNameXLS     # Xls File name to be updated
            path=os.getcwd()

            filePath=os.path.join(os.getcwd(),fileNameXLS)
            xl = win32com.client.Dispatch("Excel.Application")

            try :
                        wb = xl.Workbooks.Open(filePath)
            except:
                     print "Failed to open spreadsheet for the path %s"
%(filePath)
            sh = wb.worksheets(worksheetNum)
            sh.Cells(row,col).Value = data
            wb.Save()
            wb.Close()

calling logToXLS() occasionally throws the mentioned error at

xl.Workbooks.Open(filePath)

 File "C:\Python25\Lib\site-packages\win32com\client\dynamic.py",

> line 496, in
> __getattr__
>    raise AttributeError, "%s.%s" % (self._username_, attr)
> AttributeError: Excel.Application.Workbooks


1)is there any limitation on number of characters on filepath?
2)How this issue can be overcome?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20100812/25f36b95/attachment.html>


More information about the python-win32 mailing list