get row count of excel sheet from javascript

本秂侑毒 提交于 2020-01-06 08:03:25

问题


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 .

Thanks


回答1:


Replace

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

with

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

or

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

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



来源:https://stackoverflow.com/questions/8060188/get-row-count-of-excel-sheet-from-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!