Forum Discussion

Jainsoumya's avatar
Jainsoumya
Contributor
3 years ago

how to open excel file using TestComplete

@Marsha_R

I am not able to open excel file using this methd , though its is getting passed but required action is not taking place

function ExcelExample()

{
// Get the sheet of the Excel file
var excelFile = Excel.Open("C:\\Users\\Public\\TestInput\\ChartInput.xlsx");
var excelSheet = excelFile.SheetByTitle("Sheet1");


}

 

  • Hi Jainsoumya!

     

    No action is taking place, because there is no action to perform in the code sample.

     

    In the small sample above, TestComplete is simply opening and closing the sheet in the background.

     

    Since there is no other action, such a Log event to post results, nothing is being returned. 

     

    Is there another action further down in your code that is not working? If you are only running the snippet provided, then no results in your logs is going to be the expected result.

      • Marsha_R's avatar
        Marsha_R
        Moderator

        You have the correct code to open the file but what npaisley is saying is the open does not count as an action for TestComplete so it does not log it.  The file has been opened  in the background and nothing is visible. Same for the sheet reference.  You set it to a variable but this is not a logged action.

         

        Try doing something next like getting a value from the sheet and putting it in a log message. That will show an action.

    • Marsha_R's avatar
      Marsha_R
      Moderator

      Your syntax is correct, so I would first look for an issue with file permissions. Make sure that TestComplete has access to that particular directory. You could try putting the Excel file on the desktop to begin with, just to confirm the permissions.

      • Jainsoumya's avatar
        Jainsoumya
        Contributor

        Marsha_R  I have tried this but no result , script got passed but no required action took place

    • AlexKaras's avatar
      AlexKaras
      Champion Level 3

      Hi,

       

      No action is taking place

      What action do you expect?

      Note, that Excel object provided by TestComplete does not require Excel application to be installed and thus does not provide any UI.

      If you need to open the file in Excel application, then you must start Excel as a COM object and use its object model. (https://support.smartbear.com/testcomplete/docs/testing-with/working-with-external-data-sources/excel/working-via-com.html as an example)

       

      • Jainsoumya's avatar
        Jainsoumya
        Contributor

        AlexKaras 

        I have tried this two methods and script got passed but required excel file didnt get open 

         

        function ReadDataFromExcel()
        {
        let Excel1 = Sys.OleObject("Excel.Application");
        Excel1.Workbooks.Open("C:\\Users\\Public\\TestInput\\ChartInput.xlsx");



        }

         

        and 

        function ReadDataFromExcel()
        {
        let Excel = getActiveXObject("Excel.Application");
        Excel.Workbooks.Open("C:\\Users\\Public\\TestInput\\ChartInput.xlsx");


        }