Forum Discussion

DSmachineWorld's avatar
DSmachineWorld
Contributor
3 years ago

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.

 

 

 

  • ebarbera's avatar
    ebarbera
    3 years ago

    Hello DSmachineWorld - 

     

    excelFile.Save()

     

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

     

    Emma

    • DSmachineWorld's avatar
      DSmachineWorld
      Contributor

      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.

      • ebarbera's avatar
        ebarbera
        Staff

        Hello DSmachineWorld - 

         

        excelFile.Save()

         

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

         

        Emma