从javascript获取Excel工作表的行数

问题描述:

我正在尝试使用javascript获取我的excel工作表中的总行数. 这是我的代码

i am trying to get total number of rows in my excel sheet with javascript . here is my code

      var Excel;
      Excel = new ActiveXObject("Excel.Application");
      Excel.Visible = false;
      a= Excel.Workbooks.open("C:/work/ind.xls").ActiveSheet.Cells(1,1).value;
      alert(a);

这显示了第一个索引的值,但是我想知道是否有任何选择获取此活动表的总行数.

this show the value at 1st index , but i was wondering if there is any option of getting the total rows of this active sheet .

谢谢

替换

a = Excel.Workbooks.open("C:/work/ind.xls").ActiveSheet.Cells(1,1).value;

使用

a = Excel.Rows.Count;   //Depending on excel version, you will get either 65536 or 1048576

a = Excel.Workbooks.open("C:/work/ind.xls").ActiveSheet.Cells.UsedRange.Count;    //It will provide total used rows.


注意:ActiveXObject仅在IE浏览器上可用.因此,每个其他用户代理都会引发错误


Note: ActiveXObject is available only on IE browser. So every other useragent will throw an error