cancel
Showing results for 
Search instead for 
Did you mean: 

Not able to open Excel File in TestComplete

Contributor

Not able to open Excel File in TestComplete

I am using the hashtable to pass excel files path . In hashtable we use '\\' in the path and it has worked fine in my previous web project. But now when I am using it on iOS project, this code is not working.When TestComplete try to open this file, I get error below error:

JavaScript runtime error.
'' could not be found. Check the spelling of the file name, and verify that the file location is correct.
If you are trying to open the file from your list of most recently used files, make sure that the file has not been renamed, moved, or deleted. 

File file very much exist , I am able to open the file using same path from cmd propmt.One thing I have noticed that when I evaluate 'ExcelPath' using cntrl F12..it is being taken litteral as mentioned in hastable i.e. ("D:\\A360_AutoQA\\TestData\\Book1.xlsx") but If I provide single '\' in path then path is being taken as  ("D:A360_AutoQATestDataBook1.xlsx").This is confusing me.

below is the code for the same:

 Hastable:

var Excel_Path = 

{

//Test

TestSheet : "D:\\A360_AutoQA\\TestData\\Book1.xlsx"

 This is my Test Unit:

function Test() 

{  

//Datasheet Path  

ExcelPath = Excel_Path.TestSheet; 

//To get the valid Row count in Excel sheet

var RowCnt = get_valid_row_count ();

Log.Message(RowCnt)

}

 

This is my excel lib:

var objExcel = Sys.OleObject("Excel.Application");

var astrSheetName = "Sheet1";

var ExcelPath;  

function get_valid_row_count ()

{

var aobjWorkbook = objExcel.Workbooks.Open(ExcelPath);

var objExcelSheet = aobjWorkbook.Sheets(astrSheetName).Activate;

var iUsedRowCount = aobjWorkbook.ActiveSheet.UsedRange.Rows.Count; 

var ValidRowCnt = (iUsedRowCount-1); 

return ValidRowCnt;

can anyone suggest what should I do to resolve it.

Thanks in advance!!

 

*************************************

To be sure that error is not because of the way path is defined , I have removed hastable and just used two function mentione below still the file could not be opened.same error is occuring and I can still can open the file by pasting same file path in Run command.

 

Test Unit-------

function Test() 

{  

//Datasheet Path

ExcelPath = "D:\A360_AutoQA\TestData\Book1.xlsx"; 

Open_Excel(ExcelPath);

}

 

Excel Library code-------------

var ExcelPath;

function Open_Excel(){

var objExcel = new getActiveXObject("Excel.Application");

objExcel.Visible = true;

var objWorkbook = objExcel.Workbooks.Open(ExcelPath); ------(Getting error on this line)

 

}

 

Please guide me what am I doing wrong.

 

 

 

 

3 REPLIES 3
Community Hero

Re: Not able to open Excel File in TestComplete


@meenakshiyadav1 wrote:

Test Unit-------

function Test() 

{  

//Datasheet Path

ExcelPath = "D:\A360_AutoQA\TestData\Book1.xlsx"; 

Open_Excel(ExcelPath);

}

 

Excel Library code-------------

var ExcelPath;

function Open_Excel(){

var objExcel = new getActiveXObject("Excel.Application");

objExcel.Visible = true;

var objWorkbook = objExcel.Workbooks.Open(ExcelPath); ------(Getting error on this line)

 

}

 

Please guide me what am I doing wrong.

 


 

You are calling Open_Excel(ExcelPath) function with ExcelPath parameter but in your library code Open_Excel does not have parameter.

 

Put a breakpoint on the line var objWorkbook = objExcel.Workbooks.Open(ExcelPath); ------(Getting error on this line) and see the value for ExcelPath and share us.


 

function get_valid_row_count ()

{

var aobjWorkbook = objExcel.Workbooks.Open(ExcelPath);

 

 It should be like this 

var aobjWorkbook = objExcel.Workbooks.Open(ExcelPath.TestSheet);


Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”


Extension Available

Contributor

Re: Not able to open Excel File in TestComplete

Thanks Shankar, This seems to have solved my issue of opening the excel file.

Community Hero

Re: Not able to open Excel File in TestComplete

Glad it worked for you!


Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”


Extension Available

New Here?
Join us and watch the welcome video:
6 / 7 API Testing Mistakes Video
Top Kudoed Authors