admin管理员组

文章数量:1330566

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>

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>
Share Improve this question asked Oct 8, 2012 at 4:53 Ripon Al WasimRipon Al Wasim 37.8k42 gold badges159 silver badges178 bronze badges 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 – Ripon Al Wasim Commented Oct 8, 2012 at 5:46
  • If you can require modern Excel documents, js-xlsx might work for you: github./SheetJS/js-xlsx – lyschoening Commented Jun 21, 2014 at 8:25
Add a ment  | 

1 Answer 1

Reset to default 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).

本文标签: Retrieving data from Excel by JavaScript using IEFF and ChromeStack Overflow