]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
CellDataResolverBase causes an exception when processing empty rows. 32/4832/1 release/1.35.3
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Tue, 11 Jan 2022 13:53:47 +0000 (15:53 +0200)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Tue, 11 Jan 2022 13:53:47 +0000 (15:53 +0200)
gitlab #34

Change-Id: Iae3a922e01c7c98edc432d7d2f1c9ba06bf38b1a

org.simantics.excel.poi/src/org/simantics/excel/poi/parser/CellDataResolverBase.java

index 6788b82f8d6c825d1318dae313f593df81e9e1d8..99412bbab884d385dadf58088f49d009950ffa70 100644 (file)
@@ -1,93 +1,97 @@
-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;
+       }
+
+}