Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the last column index reading excel file?

How do i get the index of the last column when reading a xlsx file using the Apache POI API?

There's a getLastRowNum method, but I can't find nothing related to the number of columns...


EDIT: I'm dealing with XLSX files

like image 687
marcosbeirigo Avatar asked Feb 03 '10 18:02

marcosbeirigo


People also ask

How do I find the last column of data in Excel?

Locate the last cell that contains data or formatting on a worksheet. To locate the last cell that contains data or formatting, click anywhere in the worksheet, and then press CTRL+END.

What is the last column letter in Excel?

ADDRESS function The maximum number of columns in an Excel worksheet is 16,384, so the final column in a worksheet is "XFD".

How do you find last column in Excel macro?

Step 1: Add a shape (Find Last Row/Column/Cell) on your worksheet. Step 2: Right-click on “Find Last Row/Column/Cell” and “Assign Macro..” Step 5: Click “Find Last Row/Column/Cell” to execute the VBA code.


2 Answers

I think you'll have to iterate through the rows and check HSSFRow.getLastCellNum() on each of them.

like image 105
Henning Avatar answered Oct 06 '22 13:10

Henning


Check each Row and call Row.getLastCellNum() the max cell number is the last column number.

Row r = sheet.getRow(rowNum);
int maxCell=  r.getLastCellNum();
like image 35
Helenice Silva Avatar answered Oct 06 '22 13:10

Helenice Silva