user2571510
user2571510

Reputation: 11377

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.Workbooks.Open(filePath);
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 ?

Edit: 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

Upvotes: 0

Views: 5311

Answers (1)

Rick Hitchcock
Rick Hitchcock

Reputation: 35670

This seems to work:

var xlUp = -4162;
var sheet = objExcel.Workbooks.Open(filePath).ActiveSheet;
alert(sheet.cells(sheet.rows.count,1).end(xlUp).row);

Upvotes: 3

Related Questions