-package org.simantics.excel.poi.parser;\r
-\r
-import org.apache.poi.ss.usermodel.Cell;\r
-import org.apache.poi.ss.usermodel.Row;\r
-\r
-public abstract class CellDataResolverBase<T> implements DataResolver<T> {\r
- \r
- \r
- protected Double getCellNumericValue(Cell cell) {\r
- if (cell == null)\r
- return null;\r
- switch (cell.getCellTypeEnum()) {\r
- case BLANK:\r
- return null;\r
- case BOOLEAN:\r
- return null;\r
- case ERROR:\r
- return null;\r
- case FORMULA:\r
- return null;\r
- case NUMERIC:\r
- return cell.getNumericCellValue();\r
- case STRING:\r
- return null;\r
- case _NONE:\r
- return null;\r
- }\r
- throw new RuntimeException();\r
- }\r
- \r
- protected String getCellStringValue(Cell cell) {\r
- if (cell == null)\r
- return null;\r
- switch (cell.getCellTypeEnum()) {\r
- case BLANK:\r
- return null;\r
- case BOOLEAN:\r
- return Boolean.toString(cell.getBooleanCellValue());\r
- case ERROR:\r
- return null;\r
- case FORMULA:\r
- return null;\r
- case NUMERIC:\r
- return Double.toString(cell.getNumericCellValue());\r
- case STRING:\r
- return cell.getStringCellValue();\r
- case _NONE:\r
- return null;\r
- }\r
- throw new RuntimeException();\r
- }\r
- \r
- protected Boolean getCellBooleanValue(Cell cell) {\r
- if (cell == null)\r
- return null;\r
- switch (cell.getCellTypeEnum()) {\r
- case BLANK:\r
- return null;\r
- case BOOLEAN:\r
- return cell.getBooleanCellValue();\r
- case ERROR:\r
- return null;\r
- case FORMULA:\r
- return null;\r
- case NUMERIC:\r
- return null;\r
- case STRING:\r
- String value = cell.getStringCellValue();\r
- if ("true".equalsIgnoreCase(value))\r
- return true;\r
- if ("1".equalsIgnoreCase(value))\r
- return true;\r
- return false;\r
- case _NONE:\r
- return null;\r
- \r
- }\r
- throw new RuntimeException();\r
- }\r
- \r
- protected Cell getCell(Row row, int colIndex) {\r
- for (short i = row.getFirstCellNum(); i <= row.getLastCellNum(); i++) {\r
- Cell c = row.getCell(i);\r
- if (c == null)\r
- continue;\r
- if (c.getColumnIndex() == colIndex)\r
- return c;\r
- \r
- }\r
- return null;\r
- }\r
-\r
-}\r
+package org.simantics.excel.poi.parser;
+
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+
+public abstract class CellDataResolverBase<T> implements DataResolver<T> {
+
+
+ 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;
+ }
+
+}