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