views:

156

answers:

1

Welcome,

I'm exporting results of my script into Excel spreadsheet. Everything works fine, I put big sets of data into SpreadSheet, but sometimes an error occurs:

             File "C:\Python26\lib\site-packages\win32com\client\dynamic.py", line 550, in __setattr__
                self._oleobj_.Invoke(entry.dispid, 0, invoke_type, 0, value)
            pywintypes.com_error: (-2147352567, 'Exception.', (0, None, None, None, 0, -2146777998), None)***

I suppose It's not a problem of input data format. I put several different types of data strings, ints, floats, lists and it works fine. When I run the sript for the second time it works fine - no error. What's going on?

PS. This is code that generates error, what's strange is that the error doesn't occur always. Say 30% of runs results in an error. :

import win32com.client
def Generate_Excel_Report():    
    Excel=win32com.client.Dispatch("Excel.Application")
    Excel.Workbooks.Add(1)    
    Cells=Excel.ActiveWorkBook.ActiveSheet.Cells
    for i in range(100):
        Row=int(35+i)
        for j in range(10):                      
            Cells(int(Row),int(5+j)).Value="string"
    for i in range(100):
        Row=int(135+i)
        for j in range(10):

            Cells(int(Row),int(5+j)).Value=32.32 #float

Generate_Excel_Report()

The strangest for me is that when I run the script with the same code, the same input many times, then sometimes an error occurs, sometimes not.

Thanks in advance for any help

A: 

edit: It doesn't change a thing. Error occurs, but leff often. Once in 10 simulations while with .xlsx file once in 3 simulations. Please help

The problem was with the file I was opening. It was .xlsx , while I've saved it as .xls the problem disappeared. So beware my little boys, do not ever use COM interface with .xlsx or You'll get in trouble !

Rafal