There are two Things you can do
use
int noOfColumns = sh.getRow(0).getPhysicalNumberOfCells();
or
int noOfColumns = sh.getRow(0).getLastCellNum();
There is a fine difference between them
- Option 1 gives the no of columns which are actually filled with contents(If the 2nd column of 10 columns is not filled you will get 9)
- Option 2 just gives you the index of last column. Hence done 'getLastCellNum()'
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…