From 80a8e39879c9a9a7a7a81e818642b8c61be920f4 Mon Sep 17 00:00:00 2001 From: Hishida Masato Date: Thu, 30 Nov 2023 15:28:52 +0900 Subject: [PATCH] fix: SheetWrapper.getCellAsInteger(): Added STRING --- .../generate/util/SheetWrapper.java | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/generate/util/SheetWrapper.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/generate/util/SheetWrapper.java index fea93fb7..a471bbc2 100755 --- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/generate/util/SheetWrapper.java +++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/generate/util/SheetWrapper.java @@ -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())); } } @@ -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())); } } @@ -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())); } } }