本文介绍了用javascript读取excel数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用javascript读取excel数据。我正在使用活动的xobject方法来获取它,但它不适用于我。 excel文件和html文件在我的桌面上,所以excel表的路径是:jitender.xls。
任何想法我错过了哪一部分?

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?

<!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>


推荐答案

在IE9中,您可以通过指定完成文件系统路径:

In IE9 you can make this work by specifying the complete file system path:

var excel_file = excel.Workbooks.Open("c:/temp/jitender.xlsx");

这篇关于用javascript读取excel数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 20:30