I\'m looking for a cell in a spreadsheet that has the string \'Total\' and then use the row in which that cell is to find the total value in another cell which is always the
This method fix is the solution to your problem:
private static int findRow(HSSFSheet sheet, String cellContent) {
for (Row row : sheet) {
for (Cell cell : row) {
if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
if (cell.getRichStringCellValue().getString().trim().equals(cellContent)) {
return row.getRowNum();
}
}
}
}
return 0;
}
Keep in mind that your colnr
is still a fixed value.
You have a semicolon after your if
statement which means your if
won't work:
if(cell.getRichStringCellValue().getString () == cellContent);{
Even if this won't resolve your problem, I think your while
statement may not be proper for here;
while(cell.getCellType() == Cell.CELL_TYPE_STRING)
As far as I remember, there are other Cell types in POI. Try to put a breakpoint on these lines and check them if they have correct CellType.