Ask a Question

Troubleshooting creating an Excel file in TestComplete (using Python)

SOLVED
DSmachineWorld
Contributor

Troubleshooting creating an Excel file in TestComplete (using Python)

I am pretty well using the standard sample code from the main TestComplete site.

 

def writeExcel():
# https://support.smartbear.com/testcomplete/docs/testing-with/working-with-external-data-sources/exce...
# https://support.smartbear.com/testcomplete/docs/testing-with/working-with-external-data-sources/exce...
    #curTime = aqDateTime.Now()
    emailDataFilename = r'C:\foo\bar\redacted.xlsx'
    Log.Message(aqString.Format("Data file name is %s.",emailDataFilename))

    if (aqFile.Exists(emailDataFilename)):
        excelDataFile = Excel.Open(emailDataFilename)
    else:
# Create a new Excel file and add a new empty sheet to it
        Log.Message(aqString.Format("The %s file does not exist and will be created.", emailDataFilename))
        excelDataFile = Excel.Create(emailDataFilename)
        excelSheet = excelDataFile.AddSheet("Sheet1")

 

The if/else logic works fine, but nothing happens in terms of file activity.

 

 

 

--
You might not like AI, but it doesn't care about you.
4 REPLIES 4
ebarbera
Staff

@DSmachineWorld 

 

To confirm - nothing happens as far as the file being created?

 

Thanks, 


Emma

Correct. When I set watches in the code, I can see objects being created, but the new file is not being created. Or updated, if I put in a file with the name in the script.

--
You might not like AI, but it doesn't care about you.

Hello @DSmachineWorld - 

 

excelFile.Save()

 

Please add this and it should be fixed! Let me know if you have further questions.

 

Emma

Thank you! I knew I missed something elementary!

--
You might not like AI, but it doesn't care about you.
cancel
Showing results for 
Search instead for 
Did you mean: