从 JavaScript 读取 Excel 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6939135/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 22:24:50  来源:igfitidea点击:

Reading Excel file from JavaScript

javascriptexcelactivexobject

提问by Pratik

I have following code for reading excel in javascript:

我有以下用于在javascript 中读取 excel 的代码:

<html>
<head>
<script type="text/javascript">
function readData(x,y)
{

      var excel = new ActiveXObject("Excel.Application");

      alert(excel);

      var excel_file = excel.Workbooks.Open("D:\File1.xlsx");
      Excel.Visible = true;

      alert(excel_file);

      var excel_sheet = excel_file.Worksheets("DEPT INC UPDATE");

      alert(excel_sheet);

      var data = excel_sheet.Cells(x,y).Value;

      alert(data);

      return data;


}



</script>
</head>
<body>

<input type="button" value="SimpleButton" onclick="readData(2,3);" />
</body>
</html>

But dunno where it is going wrong ??

但不知道哪里出错了??

回答by Peter Perhá?

your input element is a submit button, but is not inside a form. When readData returns the data, nothing ever makes any use of it. and as to the rest, i dunno. you don't say where it's going wrong. does it show any one alert box?

您的输入元素是一个提交按钮,但不在表单内。当 readData 返回数据时,没有任何东西使用它。至于其余的,我不知道。你不会说哪里出了问题。它是否显示任何一个警报框?

回答by Kiran

i think there is an error in giving the path. Use double backward slashes instead of single.

我认为给出路径有误。使用双反斜杠而不是单斜杠。

In your case..

在你的情况下..

D:\File1.xlsx

D:\File1.xlsx

Hope this might be helpful..:)

希望这可能会有所帮助..:)