How to find highest row of particular column in PHP Excel?

10,651

There is no built-in method to do this, you would need to write your own function to loop through the cells in that column and return the row number for the last cell.

Note that getHighestRow() and getHighestColumn() return the highest row and column in the spreadsheet, as long as they are referenced by something in the worksheet; but that could simply be an empty cell that contains style information.

Nobody has every actually requested this; but I have seen a couple of questions asking how to do it: so I may consider adding an optional argument to the getHighestDataRow() and getHighestDataColumn() methods for the next release.

EDIT

With effect from PHPExcel version 1.8.0, it is possible to pass a row number to the getHighestColumn() or getHighestDataColumn(), to return the highest column containing cell data in the specified row; or a column letter to the getHighestRow() or getHighestDataRow() methods to return the highest row number containing cell data in that column.

Share:
10,651
Dhee
Author by

Dhee

Updated on June 09, 2022

Comments

  • Dhee
    Dhee almost 2 years

    How can I find the last row of particular column?

    i know that getHighestRow() will give you the highest row of the sheet.

    Is there a way to find highest row for specified column??

    To be more specific

    If you have two columns A and B

    Column A has data in 5 rows and Column B has data in 7 rows.

    I would like to get row 5 as my response, since it is the last entry under column A and would like to ignore rows 6 and 7

    When I use getHighestRow method I would get row 7 as highest row.

    Regards, Dheeraj