Skip to content

Commit

Permalink
fix: SheetWrapper.getCellAsInteger(): Added STRING
Browse files Browse the repository at this point in the history
  • Loading branch information
hishidama committed Nov 30, 2023
1 parent 74c3692 commit 80a8e39
Showing 1 changed file with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public String getCellAsString(Row row, int colIndex) {
case BLANK:
return null;
default:
throw new UnsupportedOperationException(cell.getCellType().name());
throw new UnsupportedOperationException(String.format("(row=%d, col=%d) %s", row.getRowNum(), colIndex, cell.getCellType().name()));
}
}

Expand All @@ -119,10 +119,20 @@ public Integer getCellAsInteger(Row row, int colIndex) {
case NUMERIC:
case FORMULA:
return (int) cell.getNumericCellValue();
case STRING:
String s = cell.getStringCellValue();
if (s.trim().isEmpty()) {
return null;
}
try {
return Integer.valueOf(s);
} catch (Exception e) {
throw new IllegalStateException(String.format("(row=%d, col=%d) %s", row.getRowNum(), colIndex, cell.getCellType().name()), e);
}
case BLANK:
return null;
default:
throw new UnsupportedOperationException(cell.getCellType().name());
throw new UnsupportedOperationException(String.format("(row=%d, col=%d) %s", row.getRowNum(), colIndex, cell.getCellType().name()));
}
}

Expand All @@ -135,10 +145,20 @@ public BigDecimal getCellAsDecimal(Row row, int colIndex) {
case NUMERIC:
case FORMULA:
return BigDecimal.valueOf(cell.getNumericCellValue());
case STRING:
String s = cell.getStringCellValue();
if (s.trim().isEmpty()) {
return null;
}
try {
return new BigDecimal(s);
} catch (Exception e) {
throw new IllegalStateException(String.format("(row=%d, col=%d) %s", row.getRowNum(), colIndex, cell.getCellType().name()), e);
}
case BLANK:
return null;
default:
throw new UnsupportedOperationException(cell.getCellType().name());
throw new UnsupportedOperationException(String.format("(row=%d, col=%d) %s", row.getRowNum(), colIndex, cell.getCellType().name()));
}
}
}

0 comments on commit 80a8e39

Please sign in to comment.