user2571510 user2571510 - 1 year ago 108
Javascript Question

How to count rows with data in an Excel table

I built a tool using JavaScript that allows to upload an Excel file through a website.

The below is my function to initialize the upload (I then loop through the rows of this table and do something with the data from each row).
Everything works as intended so far.

console.log('initializeExcel(' + filePath + ')');
objExcel = new ActiveXObject("Excel.Application");
objExcel.visible = true;

The only thing I would like to add here is a total row count, i.e. a count for the rows containing data in this table.
This can be simplified as the first row is always a header row which should be excluded and rows that I want to count always have some content in the first column (column A).

Can someone tell how I can achieve this ?

The way I can get this in VBA is the following so now I would only need a way to achieve the same in JavaScript:

Dim unusedRow As Long
unusedRow = Cells.SpecialCells(xlCellTypeLastCell).Offset(1, 0).Row

Answer Source

This seems to work:

var xlUp = -4162;
var sheet = objExcel.Workbooks.Open(filePath).ActiveSheet;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download