cancel
Showing results for 
Search instead for 
Did you mean: 

Compare excel files(ExcelObj is undefined )

nsag_1512
Occasional Contributor

Compare excel files(ExcelObj is undefined )

 

I'm trying to compare two excel files using below code, I'm getting error 'ExcelObj' is undefined'. Please help...

 

Thanks 🙂

 

 

function Excel()
{
var oExcel = Sys.OleObject("Excel.Application");
var aSheets = Sys.OleObject("Scripting.Dictionary");

//You can specify the sheet to be compared
//var vSheet = "Sheet1";
//aSheets.Add(vSheet, vSheet);

var fileName = "C:\\Users\\ghaniabd\\Desktop\\excel";
var aInfo1 = aSheets.CreateInfo(oExcel, "1.xlsx", "Aging Summary (01 1 2017 - 03 1");


var fileName = "C:\\Users\\ghaniabd\\Desktop\\excel";
var aInfo2 = aSheets.CreateInfo(oExcel, "2.xlsx", "Aging Summary (01 1 2017 - 03 1");


var oResult = aSheets.Compare(aInfo1, aInfo2);
if (oResult.length > 0)
{
Log.Warning(oResult);
}
else
{
Log.Message("The files are the same.");
}
oExcel.Quit();
}

6 REPLIES 6
shankar_r
Community Hero

Re: Compare excel files(ExcelObj is undefined )

I'm not sure you can compare two excel files or excel sheets using Dictionary object. 

 

And also there is no way to get ExcelObj as undefined from your code since there is no ExcelObj is mentioned in your code.

 

Can you post log which you got for this.


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

nsag_1512
Occasional Contributor

Re: Compare excel files(ExcelObj is undefined )

function Main()
{
  var oExcel = Sys.OleObject("Excel.Application");
  var aSheets = Sys.OleObject("Scripting.Dictionary");
  
  //You can specify the sheet to be compared
  //var vSheet = "Sheet1";
  //aSheets.Add(vSheet, vSheet); 
  
  var fileName = "C:\\Users\\ghaniabd\\Desktop\\excel";
  var aInfo1 = ExcelObj.CreateInfo(oExcel, "1.xlsx", "Aging Summary (01 1 2017 - 03 1");
 
  var fileName = "C:\\Users\\ghaniabd\\Desktop\\excel";
  var aInfo2 = ExcelObj.CreateInfo(oExcel, "2.xlsx", "Aging Summary (01 1 2017 - 03 1");
  var oResult = ExcelObj.Compare(aInfo1, aInfo2);
  if (oResult.length > 0)
  {
    Log.Warning(oResult);
  }
  else
  {
    Log.Message("The files are the same.");  
  }
  oExcel.Quit();
}

Sorry this is latest the code with the ExcelObj.. 

shankar_r
Community Hero

Re: Compare excel files(ExcelObj is undefined )

Again ExcelObj is not initialized anywhere in your code hence you are getting ExcelObj is undefined error.

 

You have define a object like var ExcelObj = "Object value"

 

Also, I don't think using your code excel files or sheets can be compared


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

nsag_1512
Occasional Contributor

Re: Compare excel files(ExcelObj is undefined )

i get the above code from the test complete coampre excel file article..

Here is the articel path https://support.smartbear.com/viewarticle/9046/#_ga=1.140248566.49838654.1488187804

shankar_r
Community Hero

Re: Compare excel files(ExcelObj is undefined )

Gotcha...

 

1. Download the script extension from the link https://support.smartbear.com/images/support/kb/data/2010/6/1/ExcelSheetCompare.tcx

 

2. Place it into *\SmartBear\TestComplete 12\Bin\Extensions\ScriptExtensions

 

3. In Test Complete, File > Install Script Extension

 

4. Click on Reload

 

5. After reload you will see the Script Extension

 

Excel.PNG

 

 

Then you can use your existing code do a compare. let me know if this works

 


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

nsag_1512
Occasional Contributor

Re: Compare excel files(ExcelObj is undefined )

 

i able to see the extension after click the reload btn. But i get new error message when running the script. Below is the screenshot of the error.

 

 

Capture1.PNG

 

 

New Here?
Join us and watch the welcome video:
Announcements