Forum Discussion

msap's avatar
msap
Frequent Contributor
7 years ago

compare Excel files:

Hi 

 

Getting an error "  Cannot read property 'ExcelCompare' of undefined Error location:

The below script I copied from the smartbear testcomplete article.

When I  am trying to compare two  excel files matches  values using below code: 

function Main()
{
var objectExcel, ExcelCompare;
xlfile1 = "C:\excel1.xlsm";
xlfile2 = "C:\excel2.xlsm";
resfile = "C:\excel3.xlsm";
objectExcel.ExcelCompare("C:\excel1.xlsm","C:\excel2.xlsm","C:\excel3.xlsm");
}

Please let me know what I am missing here.

I installed script extensions too.

  • If this is the article (https://support.smartbear.com/viewarticle/42199/)

     

    then change your code to

    function Main()
    {
    
    xlfile1 = "C:\\excel1.xlsm";
    xlfile2 = "C:\\excel2.xlsm";
    resfile = "C:\\excel3.xlsm";
    Log.Message(objectExcel.ExcelCompare(xlfile1,xlfile2,resfile));
    }

    Note several changes

     

    1) Removed the variable declaration.  That is probably the main cause of your problem.

    2) Added the extra backslash to the file paths. JavaScript uses the backslash as an "escape" character so to actually send a backslash, you need to double it up.

    3) Wrapped the extension call in a Log.Message so you actually get an output.

     

    Basically... I recreated the actual script code that was in the article with the only exception being that I'm actually using real paths.  Please try the above code and see if that works.

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    If this is the article (https://support.smartbear.com/viewarticle/42199/)

     

    then change your code to

    function Main()
    {
    
    xlfile1 = "C:\\excel1.xlsm";
    xlfile2 = "C:\\excel2.xlsm";
    resfile = "C:\\excel3.xlsm";
    Log.Message(objectExcel.ExcelCompare(xlfile1,xlfile2,resfile));
    }

    Note several changes

     

    1) Removed the variable declaration.  That is probably the main cause of your problem.

    2) Added the extra backslash to the file paths. JavaScript uses the backslash as an "escape" character so to actually send a backslash, you need to double it up.

    3) Wrapped the extension call in a Log.Message so you actually get an output.

     

    Basically... I recreated the actual script code that was in the article with the only exception being that I'm actually using real paths.  Please try the above code and see if that works.

    • msap's avatar
      msap
      Frequent Contributor

      Thanks. It worked.