Forum Discussion

DSmachineWorld's avatar
DSmachineWorld
Contributor
4 years ago
Solved

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/excel/write.html
# https://support.smartbear.com/testcomplete/docs/testing-with/working-with-external-data-sources/excel/open.html
    #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.