X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.excel.poi%2Fsrc%2Forg%2Fsimantics%2Fexcel%2Fpoi%2Fparser%2FCellDataResolverBase.java;fp=org.simantics.excel.poi%2Fsrc%2Forg%2Fsimantics%2Fexcel%2Fpoi%2Fparser%2FCellDataResolverBase.java;h=5a78735ded0099f60e1b965e0c29f0ed7352b4cc;hb=7abd05645636ea510269d77005717f43c2c445ba;hp=0000000000000000000000000000000000000000;hpb=f11cbe76b3f4be142c9f84ef9a7b6bc9dcc8ff23;p=simantics%2Finterop.git 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 new file mode 100644 index 0000000..5a78735 --- /dev/null +++ b/org.simantics.excel.poi/src/org/simantics/excel/poi/parser/CellDataResolverBase.java @@ -0,0 +1,88 @@ +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.getCellType()) { + case Cell.CELL_TYPE_BLANK: + return null; + case Cell.CELL_TYPE_BOOLEAN: + return null; + case Cell.CELL_TYPE_ERROR: + return null; + case Cell.CELL_TYPE_FORMULA: + return null; + case Cell.CELL_TYPE_NUMERIC: + return cell.getNumericCellValue(); + case Cell.CELL_TYPE_STRING: + return null; + + } + throw new RuntimeException(); + } + + protected String getCellStringValue(Cell cell) { + if (cell == null) + return null; + switch (cell.getCellType()) { + case Cell.CELL_TYPE_BLANK: + return null; + case Cell.CELL_TYPE_BOOLEAN: + return Boolean.toString(cell.getBooleanCellValue()); + case Cell.CELL_TYPE_ERROR: + return null; + case Cell.CELL_TYPE_FORMULA: + return null; + case Cell.CELL_TYPE_NUMERIC: + return Double.toString(cell.getNumericCellValue()); + case Cell.CELL_TYPE_STRING: + return cell.getStringCellValue(); + + } + throw new RuntimeException(); + } + + protected Boolean getCellBooleanValue(Cell cell) { + if (cell == null) + return null; + switch (cell.getCellType()) { + case Cell.CELL_TYPE_BLANK: + return null; + case Cell.CELL_TYPE_BOOLEAN: + return cell.getBooleanCellValue(); + case Cell.CELL_TYPE_ERROR: + return null; + case Cell.CELL_TYPE_FORMULA: + return null; + case Cell.CELL_TYPE_NUMERIC: + return null; + case Cell.CELL_TYPE_STRING: + String value = cell.getStringCellValue(); + if ("true".equalsIgnoreCase(value)) + return true; + if ("1".equalsIgnoreCase(value)) + return true; + return false; + } + 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; + } + +}