1 package org.simantics.excel.poi.parser;
\r
3 import org.apache.poi.ss.usermodel.Cell;
\r
4 import org.apache.poi.ss.usermodel.Row;
\r
6 public abstract class CellDataResolverBase<T> implements DataResolver<T> {
\r
9 protected Double getCellNumericValue(Cell cell) {
\r
12 switch (cell.getCellType()) {
\r
13 case Cell.CELL_TYPE_BLANK:
\r
15 case Cell.CELL_TYPE_BOOLEAN:
\r
17 case Cell.CELL_TYPE_ERROR:
\r
19 case Cell.CELL_TYPE_FORMULA:
\r
21 case Cell.CELL_TYPE_NUMERIC:
\r
22 return cell.getNumericCellValue();
\r
23 case Cell.CELL_TYPE_STRING:
\r
27 throw new RuntimeException();
\r
30 protected String getCellStringValue(Cell cell) {
\r
33 switch (cell.getCellType()) {
\r
34 case Cell.CELL_TYPE_BLANK:
\r
36 case Cell.CELL_TYPE_BOOLEAN:
\r
37 return Boolean.toString(cell.getBooleanCellValue());
\r
38 case Cell.CELL_TYPE_ERROR:
\r
40 case Cell.CELL_TYPE_FORMULA:
\r
42 case Cell.CELL_TYPE_NUMERIC:
\r
43 return Double.toString(cell.getNumericCellValue());
\r
44 case Cell.CELL_TYPE_STRING:
\r
45 return cell.getStringCellValue();
\r
48 throw new RuntimeException();
\r
51 protected Boolean getCellBooleanValue(Cell cell) {
\r
54 switch (cell.getCellType()) {
\r
55 case Cell.CELL_TYPE_BLANK:
\r
57 case Cell.CELL_TYPE_BOOLEAN:
\r
58 return cell.getBooleanCellValue();
\r
59 case Cell.CELL_TYPE_ERROR:
\r
61 case Cell.CELL_TYPE_FORMULA:
\r
63 case Cell.CELL_TYPE_NUMERIC:
\r
65 case Cell.CELL_TYPE_STRING:
\r
66 String value = cell.getStringCellValue();
\r
67 if ("true".equalsIgnoreCase(value))
\r
69 if ("1".equalsIgnoreCase(value))
\r
73 throw new RuntimeException();
\r
76 protected Cell getCell(Row row, int colIndex) {
\r
77 for (short i = row.getFirstCellNum(); i <= row.getLastCellNum(); i++) {
\r
78 Cell c = row.getCell(i);
\r
81 if (c.getColumnIndex() == colIndex)
\r