Forum Discussion

MarkSchofer's avatar
MarkSchofer
Frequent Contributor
3 years ago

Problem with writing to Excel in Python

We just migrated to the latest version of TestComplete.  I have a ton of complex code that works great until I write to an excel file.

if itemswebpage == itemsexcel:
Log.Message('Group is as expected: ' + str(itemswebpage))
excelFile = Excel.Open(Project.Variables.LogFile)
# excelSheet = excelFile.SheetByTitle["2022"]
# excelFile = Excel.Open("C:\SVN_Test\Mark's\CheckProcessing\Doc & Data\ManualCheckLog.xlsx'"
excelSheet = excelFile.SheetByTitle["2022"]
# Write the obtained data into a new row of the file
RowIndex = excelSheet.RowCount

 

This code has always worked fine. The python codes compares two lists and when they are the same we write to a file.

And it blows up with this message.

 

Excel internal error 'Error while removing a file (The process cannot access the file because it is being used by another process.
).'. 13:16:59 Normal 1.59

AttributeError: 'NoneType' object has no attribute 'SheetByTitle' 13:24:05 Normal 425.45
RowIndex = RowIndex+1
excelSheet.Cell["A", RowIndex].Value = DDT.CurrentDriver.Value[37]
excelSheet.Cell["B", RowIndex].Value = "Check Details Passed"
excelFile.Save()
return True

 

  • No other changes?  (Yes I have to ask lol) New machine or new code or new version of Excel etc etc?

     

    I suggest reverting to your backed up earlier version for now and since this happened with a new version I would report it to Support directly. Here's the link:

    https://support.smartbear.com/testcomplete/message/