0

what I want to do is access an excel file, take the contents of a column and then store it in an array. I'm guessing this can be done by iterating through each element of the range object and copying it to an array. My current code is shown below:

    function GetData(){

          var excel = new ActiveXObject("Excel.Application");
          var excel_file = excel.Workbooks.Open("C:\\Data.xls");
          var excel_sheet = excel.Worksheets("Sheet2");

          //returns a RANGE object
          var myrow = excel_sheet.Columns(1);

          //doing this puts a single range object in myarray
          var myarray = new Array(myrow);

         //try printing the contents of the range object
          for (mycell in myrow){
              document.getElementById('div1').innerHTML = mycell;
          }
   }

1 Answer 1

1

Please check the following code to get data from an excel file. Hope this helps you:

CODE:

function GetData(){ 
          var excel = new ActiveXObject("Excel.Application"); 
          var excel_file = excel.Workbooks.Open("C:\\Data.xls"); 
          var excel_sheet = excel.Worksheets("Sheet2"); 
          for(var i=2;i<20;i++){
            var myrow = excel_sheet.Range("A"+i);    //to read values in row A
            document.getElementById('div1').innerHTML = myrow; 
          }
}

Tested in IE9.

Sign up to request clarification or add additional context in comments.

1 Comment

is there also a simple method to do this in chrome and firefox?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.