From: Marko Luukkainen Date: Tue, 11 Jan 2022 13:53:47 +0000 (+0200) Subject: CellDataResolverBase causes an exception when processing empty rows. X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=1567ec65e61c843d558f97355a73df82598cee49;p=simantics%2Finterop.git CellDataResolverBase causes an exception when processing empty rows. gitlab #34 Change-Id: Iae3a922e01c7c98edc432d7d2f1c9ba06bf38b1a --- diff --git a/org.simantics.excel.poi/src/org/simantics/excel/poi/parser/CellDataResolverBase.java b/org.simantics.excel.poi/src/org/simantics/excel/poi/parser/CellDataResolverBase.java index 6788b82..99412bb 100644 --- a/org.simantics.excel.poi/src/org/simantics/excel/poi/parser/CellDataResolverBase.java +++ b/org.simantics.excel.poi/src/org/simantics/excel/poi/parser/CellDataResolverBase.java @@ -1,93 +1,97 @@ -package org.simantics.excel.poi.parser; - -import org.apache.poi.ss.usermodel.Cell; -import org.apache.poi.ss.usermodel.Row; - -public abstract class CellDataResolverBase implements DataResolver { - - - protected Double getCellNumericValue(Cell cell) { - if (cell == null) - return null; - switch (cell.getCellTypeEnum()) { - case BLANK: - return null; - case BOOLEAN: - return null; - case ERROR: - return null; - case FORMULA: - return null; - case NUMERIC: - return cell.getNumericCellValue(); - case STRING: - return null; - case _NONE: - return null; - } - throw new RuntimeException(); - } - - protected String getCellStringValue(Cell cell) { - if (cell == null) - return null; - switch (cell.getCellTypeEnum()) { - case BLANK: - return null; - case BOOLEAN: - return Boolean.toString(cell.getBooleanCellValue()); - case ERROR: - return null; - case FORMULA: - return null; - case NUMERIC: - return Double.toString(cell.getNumericCellValue()); - case STRING: - return cell.getStringCellValue(); - case _NONE: - return null; - } - throw new RuntimeException(); - } - - protected Boolean getCellBooleanValue(Cell cell) { - if (cell == null) - return null; - switch (cell.getCellTypeEnum()) { - case BLANK: - return null; - case BOOLEAN: - return cell.getBooleanCellValue(); - case ERROR: - return null; - case FORMULA: - return null; - case NUMERIC: - return null; - case STRING: - String value = cell.getStringCellValue(); - if ("true".equalsIgnoreCase(value)) - return true; - if ("1".equalsIgnoreCase(value)) - return true; - return false; - case _NONE: - return null; - - } - throw new RuntimeException(); - } - - protected Cell getCell(Row row, int colIndex) { - for (short i = row.getFirstCellNum(); i <= row.getLastCellNum(); i++) { - Cell c = row.getCell(i); - if (c == null) - continue; - if (c.getColumnIndex() == colIndex) - return c; - - } - return null; - } - -} +package org.simantics.excel.poi.parser; + +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.Row; + +public abstract class CellDataResolverBase implements DataResolver { + + + protected Double getCellNumericValue(Cell cell) { + if (cell == null) + return null; + switch (cell.getCellTypeEnum()) { + case BLANK: + return null; + case BOOLEAN: + return null; + case ERROR: + return null; + case FORMULA: + return null; + case NUMERIC: + return cell.getNumericCellValue(); + case STRING: + return null; + case _NONE: + return null; + } + throw new RuntimeException(); + } + + protected String getCellStringValue(Cell cell) { + if (cell == null) + return null; + switch (cell.getCellTypeEnum()) { + case BLANK: + return null; + case BOOLEAN: + return Boolean.toString(cell.getBooleanCellValue()); + case ERROR: + return null; + case FORMULA: + return null; + case NUMERIC: + return Double.toString(cell.getNumericCellValue()); + case STRING: + return cell.getStringCellValue(); + case _NONE: + return null; + } + throw new RuntimeException(); + } + + protected Boolean getCellBooleanValue(Cell cell) { + if (cell == null) + return null; + switch (cell.getCellTypeEnum()) { + case BLANK: + return null; + case BOOLEAN: + return cell.getBooleanCellValue(); + case ERROR: + return null; + case FORMULA: + return null; + case NUMERIC: + return null; + case STRING: + String value = cell.getStringCellValue(); + if ("true".equalsIgnoreCase(value)) + return true; + if ("1".equalsIgnoreCase(value)) + return true; + return false; + case _NONE: + return null; + + } + throw new RuntimeException(); + } + + protected Cell getCell(Row row, int colIndex) { + short first = row.getFirstCellNum(); + short last = row.getLastCellNum(); + if (first < 0) + return null; + for (short i = first; i <= last; i++) { + Cell c = row.getCell(i); + if (c == null) + continue; + if (c.getColumnIndex() == colIndex) + return c; + + } + return null; + } + +}