Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving data from Excel by JavaScript using IE, FF and Chrome

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>
like image 673
Ripon Al Wasim Avatar asked Oct 08 '12 04:10

Ripon Al Wasim


1 Answers

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).

like image 88
Christian Sauer Avatar answered Oct 20 '22 00:10

Christian Sauer