javascript 用javascript读取excel数据?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9464123/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Read excel data with javascript?
提问by Jitender Chand
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?
我想使用javascript读取excel数据。我正在使用 active xobject 方法来获取它,但它对我不起作用。我的桌面上有excel文件和html文件,所以excel表的路径是:“jitender.xls”。知道我错过了哪一部分吗?
<!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>
回答by squirrelchaser
In IE9 you can make this work by specifying the complete file system path:
在 IE9 中,您可以通过指定完整的文件系统路径来完成这项工作:
var excel_file = excel.Workbooks.Open("c:/temp/jitender.xlsx");