You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi! I think getLastCellNum() may be returning a value 1 more than intended.
With two columns (A and B), it returns a value of 3. (see implementation below - it's returning size() + 1).
With a blank column - let's say we have A populated, B blank, C blank, and D populated - it's not looking for the highest valued column index, just the number of populated columns, so the result there is not correct either.
/**
* Gets the index of the last cell contained in this row <b>PLUS ONE</b>.
*
* @return short representing the last logical cell in the row <b>PLUS ONE</b>,
* or -1 if the row does not contain any cells.
*/
@Override
public short getLastCellNum() {
return (short) (cellMap.size() == 0 ? -1 : cellMap.size() + 1);
}
Workaround, to get the number of cells in a row with either XLSX streaming or regular POI:
private int numCellsInRow(Row row) {
if (row instanceof StreamingRow) {
List<Integer> colIndexes = new ArrayList<>(((StreamingRow) row).getCellMap().keySet());
if (colIndexes.size() < 1) {
return 0;
}
colIndexes.sort(null);
return colIndexes.get(colIndexes.size()-1) + 1;
}
else {
// HSSFRow.getLastCellNum() returns the 1-based index of the last cell, or -1
return (row.getLastCellNum() < 1) ? 0 : row.getLastCellNum();
}
}
The text was updated successfully, but these errors were encountered:
Hi! I think getLastCellNum() may be returning a value 1 more than intended.
With two columns (A and B), it returns a value of 3. (see implementation below - it's returning size() + 1).
With a blank column - let's say we have A populated, B blank, C blank, and D populated - it's not looking for the highest valued column index, just the number of populated columns, so the result there is not correct either.
Workaround, to get the number of cells in a row with either XLSX streaming or regular POI:
The text was updated successfully, but these errors were encountered: