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> </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> </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> </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> </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
1 Answer
Reset to default 1I 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
版权声明:本文标题:Retrieving data from Excel by JavaScript using IE, FF and Chrome - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742257338a2441868.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论