7

I have an excel file named test.xls. The following JS code retrieve data from Excel in Internet Explorer well. But I want to use Firefox as well as Chrome. What's the code for FF and Chrome?

<html>
<head>
<title>
Style Get data from excel sheet
</title>
<script language="javascript" >
  function GetData(cell,row){
  var excel = new ActiveXObject("Excel.Application");
  var excel_file = excel.Workbooks.Open("F:\\test.xls");
  var excel_sheet = excel.Worksheets("Sheet1");
  var data = excel_sheet.Cells(cell,row).Value;
  document.getElementById('div1').innerText =data;
  }
  </script>
</head>
<body>
<p>&nbsp;</p>
<div style="background: #009955; width:'100%';" align="center">
  <font color="#000080" size="12pt">
<b>Get data from excel sheets</b>
  </font>
</div>
<center>
<p>&nbsp;</p>
<div id="div1" style="background: #DFDFFF; width:'100%';" align="center">
Click buttons to fetch data from F:\\test.xls
</div>
<input type="button" value="cell(1),row(1)" onClick="GetData(1,1);" />
<input type="button" value="cell(1),row(2)" onClick="GetData(1,2);" />
<input type="button" value="cell(2),row(1)" onClick="GetData(2,1);" />
<input type="button" value="cell(2),row(2)" onClick="GetData(2,2);" />
</center>
</body>
</html>
2
  • I used the following code instead of "var excel = new ActiveXObject("Excel.Application");" var excel = GetObject("Excel.Application"); But, I found the following error: GetObject is not defined Commented Oct 8, 2012 at 5:46
  • If you can require modern Excel documents, js-xlsx might work for you: github.com/SheetJS/js-xlsx Commented Jun 21, 2014 at 8:25

1 Answer 1

1

I am fairly sure that this only works for Internet Explorer. Additionally, this solution depends on an installed excel on the client machine. A better solution would be using epplus and reading the file on the server (only works for xlsx files, there are other solutions for the old xlsx files).

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

3 Comments

What is epplus? Can you please guide me?
Epplus is a .Net component for reading excel-files It is not perfect but fairly fast: epplus.codeplex.com They have a host of great examples for download. If you cannot use .net on your server you are stuck :)
What's the component I can use for PHP?

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.