2

I want to read excel data using javascript. I'm using active xobject method to get it but it won't work for me. The excel file and html files are on my desktop, so the path of the excel sheet is: "jitender.xls". Any idea which part I missed?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>excel</title>
<script type="text/javascript">
   function readFromExcel(x,y)
   {
      var excel = new ActiveXObject("Excel.Application");
      var excel_file = excel.Workbooks.Open("jitender.xlsx");
      var excel_sheet = excel_file.Worksheets("Sheet1");
      var data = excel_sheet.Cells(x,y).Value;
      //var value = readFromExcel(1,1).value; 
      document.write("Value from Excel file is " + data);
      return data;
   }
</script>
</head>
<body onload="readFromExcel(1,1)">
</body>
</html>
3
  • It certainly won't work in Firefox. ActiveX is a Microsoft technology that other browsers don't support. Mozilla have explicitly said they don't support it. Commented Feb 27, 2012 at 11:42
  • Your document.write deletes all in your page, exept the content of data. Use for example alert() to retrieve the value of data. Your out-commented line creates also recursive infinite loop when in use. Commented Feb 27, 2012 at 11:57
  • ActiveXObject works only on IE, It wouldn't work on FF. Can anybody Please provide the JS code for FF to read excel data? Commented Oct 8, 2012 at 5:01

1 Answer 1

3

In IE9 you can make this work by specifying the complete file system path:

var excel_file = excel.Workbooks.Open("c:/temp/jitender.xlsx");
Sign up to request clarification or add additional context in comments.

Comments

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.