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; } }