]> gerrit.simantics Code Review - simantics/interop.git/blobdiff - org.simantics.excel.poi/src/org/simantics/excel/poi/parser/streaming/CellImpl.java
Excel parsing interface
[simantics/interop.git] / org.simantics.excel.poi / src / org / simantics / excel / poi / parser / streaming / CellImpl.java
diff --git a/org.simantics.excel.poi/src/org/simantics/excel/poi/parser/streaming/CellImpl.java b/org.simantics.excel.poi/src/org/simantics/excel/poi/parser/streaming/CellImpl.java
new file mode 100644 (file)
index 0000000..c5ee733
--- /dev/null
@@ -0,0 +1,262 @@
+package org.simantics.excel.poi.parser.streaming;\r
+\r
+import java.util.Calendar;\r
+import java.util.Date;\r
+\r
+import org.apache.poi.ss.formula.FormulaParseException;\r
+import org.apache.poi.ss.usermodel.Cell;\r
+import org.apache.poi.ss.usermodel.CellStyle;\r
+import org.apache.poi.ss.usermodel.CellType;\r
+import org.apache.poi.ss.usermodel.Comment;\r
+import org.apache.poi.ss.usermodel.ExcelStyleDateFormatter;\r
+import org.apache.poi.ss.usermodel.Hyperlink;\r
+import org.apache.poi.ss.usermodel.RichTextString;\r
+import org.apache.poi.ss.usermodel.Row;\r
+import org.apache.poi.ss.usermodel.Sheet;\r
+import org.apache.poi.ss.util.CellAddress;\r
+import org.apache.poi.ss.util.CellRangeAddress;\r
+\r
+public class CellImpl implements Cell{\r
+       \r
+       private RowImpl row;\r
+       private int index;\r
+       \r
+       public CellImpl(RowImpl row, int index) {\r
+               this.row = row;\r
+               this.index = index;\r
+       }\r
+       \r
+       \r
+       private String getType() {\r
+               return row.cellTypes.get(index);\r
+       }\r
+       \r
+       @Override\r
+       public boolean getBooleanCellValue() {\r
+               return 1 == Integer.parseInt(getStringCellValue());\r
+       }\r
+       \r
+       @Override\r
+       public Date getDateCellValue() {\r
+               ExcelStyleDateFormatter formatter = new ExcelStyleDateFormatter(""); //FIXME: date format\r
+               try {\r
+                       return formatter.parse(getStringCellValue());\r
+               } catch (Exception e) {\r
+                       return null;\r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public byte getErrorCellValue() {\r
+               // TODO Auto-generated method stub\r
+               return 0;\r
+       }\r
+       \r
+       @Override\r
+       public double getNumericCellValue() {\r
+               return Double.parseDouble(getStringCellValue());\r
+       }\r
+       \r
+       @Override\r
+       public RichTextString getRichStringCellValue() {\r
+               return null;\r
+       }\r
+       \r
+       @Override\r
+       public String getStringCellValue() {\r
+               return row.cellData.get(index);\r
+       }\r
+       \r
+       \r
+       @Override\r
+       public int getCellType() {\r
+               String type = getType();\r
+               if ("v".equals(type)) {\r
+                       return CELL_TYPE_NUMERIC;\r
+               } else if ("n".equals(type)) {\r
+                       return CELL_TYPE_NUMERIC;\r
+               } else if ("s".equals(type)) {\r
+                       return CELL_TYPE_STRING;\r
+               } else if ("b".equals(type)) {\r
+                       return CELL_TYPE_STRING;\r
+               } else if ("inlineStr".equals(type)) {\r
+                       return CELL_TYPE_STRING;\r
+               }\r
+               return CELL_TYPE_STRING;\r
+       }\r
+       \r
+\r
+       \r
+       \r
+       @Override\r
+       public Row getRow() {\r
+               return row;\r
+       }\r
+       \r
+       @Override\r
+       public int getRowIndex() {\r
+               return row.getRowNum();\r
+       }\r
+       \r
+       \r
+       @Override\r
+       public CellRangeAddress getArrayFormulaRange() {\r
+               return null;\r
+       }\r
+       \r
+       \r
+       @Override\r
+       public int getCachedFormulaResultType() {\r
+               return 0;\r
+       }\r
+       \r
+       @Override\r
+       public Comment getCellComment() {\r
+               return null;\r
+       }\r
+       \r
+       @Override\r
+       public String getCellFormula() {\r
+               return null;\r
+       }\r
+       \r
+       @Override\r
+       public CellStyle getCellStyle() {\r
+               return null;\r
+       }\r
+       \r
+       @Override\r
+       public int getColumnIndex() {\r
+               return index;\r
+       }\r
+       \r
+       @Override\r
+       public Hyperlink getHyperlink() {\r
+               return null;\r
+       }\r
+       \r
+       \r
+       @Override\r
+       public Sheet getSheet() {\r
+               return row.getSheet();\r
+       }\r
+       \r
+       @Override\r
+       public boolean isPartOfArrayFormulaGroup() {\r
+               return false;\r
+       }\r
+       \r
+       @Override\r
+       public void removeCellComment() {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void setAsActiveCell() {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void setCellComment(Comment comment) {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void setCellErrorValue(byte value) {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void setCellFormula(String formula) throws FormulaParseException {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void setCellStyle(CellStyle style) {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void setCellType(int cellType) {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void setCellValue(boolean value) {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void setCellValue(Calendar value) {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void setCellValue(Date value) {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void setCellValue(double value) {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void setCellValue(RichTextString value) {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void setCellValue(String value) {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void setHyperlink(Hyperlink link) {\r
+               \r
+       }\r
+\r
+\r
+       @Override\r
+       public CellAddress getAddress() {\r
+               return new CellAddress(this);\r
+       }\r
+\r
+\r
+       @Override\r
+       public CellType getCachedFormulaResultTypeEnum() {\r
+               throw new UnsupportedOperationException();\r
+       }\r
+\r
+\r
+       @Override\r
+       public CellType getCellTypeEnum() {\r
+               String type = getType();\r
+               if ("v".equals(type)) {\r
+                       return CellType.NUMERIC;\r
+               } else if ("n".equals(type)) {\r
+                       return CellType.NUMERIC;\r
+               } else if ("s".equals(type)) {\r
+                       return CellType.STRING;\r
+               } else if ("b".equals(type)) {\r
+                       return CellType.STRING;\r
+               } else if ("inlineStr".equals(type)) {\r
+                       return CellType.STRING;\r
+               }\r
+               return CellType.STRING;\r
+       }\r
+       \r
+       @Override\r
+       public void setCellType(CellType arg0) {\r
+               throw new UnsupportedOperationException();\r
+       }\r
+       \r
+\r
+\r
+       @Override\r
+       public void removeHyperlink() {\r
+               throw new UnsupportedOperationException();\r
+       }\r
+       \r
+\r
+}\r