0

I've tried a couple of for loops, but that doesn't help me. Can anyone help me on this?

Following is there for to get a number of columns of a particular row in given excel using Java. But I want vice versa.

int noOfColumns = sh.getRow(0).getPhysicalNumberOfCells();
int noOfColumns = sh.getRow(0).getLastCellNum();
Fenio
  • 3,528
  • 1
  • 13
  • 27
Senthil
  • 77
  • 1
  • 1
  • 7
  • You'll need to provide more detail. What library are you using to access spreadsheets? – Riaan Nel Feb 15 '18 at 14:01
  • 2
    Possible duplicate of [How to get row count in an Excel file using POI library?](https://stackoverflow.com/questions/16234486/how-to-get-row-count-in-an-excel-file-using-poi-library) – GrahamA Feb 15 '18 at 15:36

1 Answers1

1

Looking at the methods you've mentioned, I'd guess you're using Apache POI. So assuming sh is your active sheet object and columnIndex is the index of the column you're inspecting:

int lastRow = sh.getLastRowNum();
    while (lastRow >= 0 && sh.getRow(lastRow).getCell(columnIndex) == null) {
        lastRow--;
    }
int columnSize = lastRow + 1;
Aneta
  • 119
  • 9