List of usage examples for org.apache.poi.ss.usermodel Cell getErrorCellValue
byte getErrorCellValue();
From source file:org.formulacompiler.spreadsheet.internal.excel.xls.loader.ExcelXLSLoader.java
License:Open Source License
private void loadCell(Cell _xlsCell, RowBuilder _rowBuilder) { final int xlsType = _xlsCell.getCellType(); if (xlsType == Cell.CELL_TYPE_FORMULA) { final String expression; expression = _xlsCell.getCellFormula(); _rowBuilder.addCellWithExpression(new LazySpreadsheetExpressionParser(expression, CellRefFormat.A1)); if (this.config.loadAllCellValues) { final int cachedFormulaResultType = _xlsCell.getCachedFormulaResultType(); if (Cell.CELL_TYPE_NUMERIC == cachedFormulaResultType) { _rowBuilder.setValue(getNumberValue(_xlsCell)); } else if (Cell.CELL_TYPE_BOOLEAN == cachedFormulaResultType) { _rowBuilder.setValue(_xlsCell.getBooleanCellValue()); } else if (Cell.CELL_TYPE_STRING == cachedFormulaResultType) { _rowBuilder.setValue(_xlsCell.getStringCellValue()); }/*from w w w.j a v a 2s.c o m*/ } } else if (Cell.CELL_TYPE_BLANK == xlsType) { _rowBuilder.addEmptyCell(); } else if (Cell.CELL_TYPE_BOOLEAN == xlsType) { _rowBuilder.addCellWithConstant(_xlsCell.getBooleanCellValue()); } else if (Cell.CELL_TYPE_NUMERIC == xlsType) { _rowBuilder.addCellWithConstant(getNumberValue(_xlsCell)); } else if (Cell.CELL_TYPE_STRING == xlsType) { _rowBuilder.addCellWithConstant(_xlsCell.getStringCellValue()); } else if (xlsType == Cell.CELL_TYPE_ERROR) { final int errorCode = _xlsCell.getErrorCellValue(); switch (errorCode) { case 7: _rowBuilder.addCellWithError(CellWithError.DIV0); break; case 15: _rowBuilder.addCellWithError(CellWithError.VALUE); break; case 23: _rowBuilder.addCellWithError(CellWithError.REF); break; case 36: _rowBuilder.addCellWithError(CellWithError.NUM); break; case 42: _rowBuilder.addCellWithError(CellWithError.NA); break; default: _rowBuilder.addCellWithError("#ERR:" + errorCode); } } }
From source file:org.generationcp.middleware.util.PoiUtil.java
License:Open Source License
private static void cloneCell(final Cell cNew, final Cell cOld) { cNew.setCellComment(cOld.getCellComment()); cNew.setCellStyle(cOld.getCellStyle()); switch (cNew.getCellType()) { case Cell.CELL_TYPE_BOOLEAN: { cNew.setCellValue(cOld.getBooleanCellValue()); break;//from w w w . j a v a2 s . co m } case Cell.CELL_TYPE_NUMERIC: { cNew.setCellValue(cOld.getNumericCellValue()); break; } case Cell.CELL_TYPE_STRING: { cNew.setCellValue(cOld.getStringCellValue()); break; } case Cell.CELL_TYPE_ERROR: { cNew.setCellValue(cOld.getErrorCellValue()); break; } case Cell.CELL_TYPE_FORMULA: { cNew.setCellFormula(cOld.getCellFormula()); break; } } }
From source file:org.is.jxlpoi.JXLPOIWorkbook.java
License:Apache License
public String getCellContentAsString(Cell c) { if (c == null) return null; switch (c.getCellType()) { case Cell.CELL_TYPE_BOOLEAN: if (c.getBooleanCellValue()) return "Y"; else//from ww w . j a va 2s . c o m return "N"; case Cell.CELL_TYPE_NUMERIC: String result = ""; int datatype = c.getCellStyle().getDataFormat(); String formatString = c.getCellStyle().getDataFormatString(); if (datatype == 174 && "yyyy/mm/dd".equals(formatString)) { java.util.Date date = c.getDateCellValue(); return fmter.format(date); } else if (datatype == 49 || datatype == 0) { int d = (int) c.getNumericCellValue(); result = Integer.toString(d); } else { result = Double.toString(c.getNumericCellValue()); } //return Double.toString(c.getNumericCellValue()); //System.out.println(" number = "+c.getNumericCellValue()+" *** value ="+twoPlaces.format(c.getNumericCellValue())+""); //return twoPlaces.format(c.getNumericCellValue())+""; return result; case Cell.CELL_TYPE_STRING: return c.getStringCellValue(); case Cell.CELL_TYPE_BLANK: return ""; case Cell.CELL_TYPE_ERROR: return "#ERROR" + c.getErrorCellValue(); case Cell.CELL_TYPE_FORMULA: String formulaCellValue; if (formulaEvaluator == null) { formulaEvaluator = workbook.getCreationHelper().createFormulaEvaluator(); //formulaEvaluator.setIgnoreFormulaException(); //System.out.println(formulaEvaluator); } //formulaEvaluator.evaluateFormulaCell(c); //formulaEvaluator.evaluateInCell(c); CellValue cv = formulaEvaluator.evaluate(c); switch (cv.getCellType()) { //switch (formulaEvaluator.evaluateInCell(c).getCellType()) { case Cell.CELL_TYPE_BOOLEAN: if (cv.getBooleanValue()) formulaCellValue = "Y"; else formulaCellValue = "F"; break; case Cell.CELL_TYPE_NUMERIC: formulaCellValue = Double.toString(cv.getNumberValue()); break; case Cell.CELL_TYPE_STRING: formulaCellValue = cv.getStringValue(); break; case Cell.CELL_TYPE_BLANK: formulaCellValue = ""; break; case Cell.CELL_TYPE_ERROR: formulaCellValue = Byte.toString(cv.getErrorValue()); break; default: formulaCellValue = ""; break; }//switch return formulaCellValue; default: return ""; }//switch }
From source file:org.joeffice.spreadsheet.cell.CellUtils.java
License:Apache License
public static void copyCell(Cell oldCell, Cell newCell) { newCell.setCellStyle(oldCell.getCellStyle()); if (newCell.getCellComment() != null) { newCell.setCellComment(oldCell.getCellComment()); }//w w w. j a v a 2s . c o m if (oldCell.getHyperlink() != null) { newCell.setHyperlink(oldCell.getHyperlink()); } newCell.setCellType(oldCell.getCellType()); // Set the cell data value switch (oldCell.getCellType()) { case Cell.CELL_TYPE_BLANK: break; case Cell.CELL_TYPE_BOOLEAN: newCell.setCellValue(oldCell.getBooleanCellValue()); break; case Cell.CELL_TYPE_ERROR: newCell.setCellErrorValue(oldCell.getErrorCellValue()); break; case Cell.CELL_TYPE_FORMULA: newCell.setCellFormula(oldCell.getCellFormula()); break; case Cell.CELL_TYPE_NUMERIC: newCell.setCellValue(oldCell.getNumericCellValue()); break; case Cell.CELL_TYPE_STRING: newCell.setCellValue(oldCell.getRichStringCellValue()); break; } }
From source file:org.lisapark.octopus.util.json.ExcelSardineUtils.java
License:Open Source License
/** * /*from w ww . j av a2s . c om*/ * @param row * @param cellIndex * @return */ public static Object cellValue(Row row, int cellIndex) { Cell cell = row.getCell(cellIndex); if (cell.getCellType() == Cell.CELL_TYPE_STRING) { return cell.getStringCellValue(); } else if (cell.getCellType() == Cell.CELL_TYPE_BLANK) { return null; } else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { return cell.getNumericCellValue(); } else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) { return cell.getBooleanCellValue(); } else if (cell.getCellType() == Cell.CELL_TYPE_ERROR) { return cell.getErrorCellValue(); } else { return null; } }
From source file:org.lisapark.octopus.util.json.JsonUtils.java
License:Open Source License
/** * // ww w.j av a 2 s . c o m * @param row * @param cells * @throws JSONException */ private JSONArray jsonFromRow(Row row) throws JSONException { JSONArray cells = new JSONArray(); for (Iterator<Cell> cellsIT = row.cellIterator(); cellsIT.hasNext();) { Cell cell = cellsIT.next(); if (cell.getCellType() == Cell.CELL_TYPE_STRING || cell.getCellType() == Cell.CELL_TYPE_BLANK) { cells.put(cell.getStringCellValue()); } else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { cells.put(cell.getNumericCellValue()); } else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) { cells.put(cell.getBooleanCellValue()); } else if (cell.getCellType() == Cell.CELL_TYPE_ERROR) { cells.put(cell.getErrorCellValue()); } else { cells.put("N/A"); } } return cells; }
From source file:org.lisapark.octopus.util.json.JsonUtils.java
License:Open Source License
private String jsonFromRowAsString(Row row) throws JSONException { StringBuilder cells = new StringBuilder(); Boolean first = Boolean.TRUE; Boolean dirty = Boolean.FALSE; // cells.append("["); int i = 0;/* w ww . j av a 2 s.co m*/ for (Iterator<Cell> cellsIT = row.cellIterator(); cellsIT.hasNext();) { if (dataFieldNames().size() <= i) break; Cell cell = cellsIT.next(); if (cell.getCellType() == Cell.CELL_TYPE_STRING) { if (first) { cells.append(key(dataFieldNames().get(i))).append(quotes(cell.getStringCellValue())); first = Boolean.FALSE; } else { cells.append(",").append(key(dataFieldNames().get(i))) .append(quotes(cell.getStringCellValue())); } dirty = Boolean.TRUE; } else if (cell.getCellType() == Cell.CELL_TYPE_BLANK) { if (first) { cells.append(key(dataFieldNames().get(i))).append(quotes(cell.getStringCellValue())); first = Boolean.FALSE; } else { cells.append(",").append(key(dataFieldNames().get(i))) .append(quotes(cell.getStringCellValue())); } } else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { if (first) { cells.append(key(dataFieldNames().get(i))).append(cell.getNumericCellValue()); first = Boolean.FALSE; } else { cells.append(",").append(key(dataFieldNames().get(i))).append(cell.getNumericCellValue()); } dirty = Boolean.TRUE; } else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) { if (first) { cells.append(key(dataFieldNames().get(i))).append(cell.getBooleanCellValue()); first = Boolean.FALSE; } else { cells.append(",").append(key(dataFieldNames().get(i))).append(cell.getBooleanCellValue()); } dirty = Boolean.TRUE; } else if (cell.getCellType() == Cell.CELL_TYPE_ERROR) { if (first) { cells.append(key(dataFieldNames().get(i))).append(cell.getErrorCellValue()); first = Boolean.FALSE; } else { cells.append(",").append(key(dataFieldNames().get(i))).append(cell.getErrorCellValue()); } dirty = Boolean.TRUE; } else { if (first) { cells.append(key(dataFieldNames().get(i))).append("N/A"); first = Boolean.FALSE; } else { cells.append(",").append(key(dataFieldNames().get(i))).append("N/A"); } dirty = Boolean.TRUE; } i++; } if (dirty) { return "{" + cells.append("}").toString(); } else { return ""; } }
From source file:org.lisapark.octopus.util.xml.XmlConverterUtils.java
License:Open Source License
/** * //from w w w . j a v a 2s.c o m * @param row * @return * @throws JSONException */ private static String tagAttributesAsString(Row row) throws JSONException { StringBuilder cells = new StringBuilder(); Boolean dirty = Boolean.FALSE; int i = 0; for (Iterator<Cell> cellsIT = row.cellIterator(); cellsIT.hasNext();) { if (dataFieldNames.size() <= i) { break; } Cell cell = cellsIT.next(); if (cell.getCellType() == Cell.CELL_TYPE_STRING) { cells.append(attribute(dataFieldNames.get(i), cell.getStringCellValue())); dirty = Boolean.TRUE; } else if (cell.getCellType() == Cell.CELL_TYPE_BLANK) { // cells.append(attribute(dataFieldNames.get(i), cell.getStringCellValue())); } else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { cells.append(attribute(dataFieldNames.get(i), cell.getNumericCellValue())); dirty = Boolean.TRUE; } else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) { cells.append(attribute(dataFieldNames.get(i), cell.getBooleanCellValue())); dirty = Boolean.TRUE; } else if (cell.getCellType() == Cell.CELL_TYPE_ERROR) { cells.append(attribute(dataFieldNames.get(i), cell.getErrorCellValue())); dirty = Boolean.TRUE; } else { cells.append(attribute(dataFieldNames.get(i), "N/A")); dirty = Boolean.TRUE; } i++; } if (dirty) { return cells.toString(); } else { return ""; } }
From source file:org.lisapark.octopus.util.xml.XmlConverterUtils.java
License:Open Source License
private static String buidNodeAsString(Cell cell, int i, int j) { StringBuilder cellStringBuilder = new StringBuilder(); if (cell.getCellType() == Cell.CELL_TYPE_STRING) { String string;//from w ww . j a v a 2 s.com if (i == 0 && cell.getCellStyle().getIndention() == 2 && treeNodeNames.get(1).equalsIgnoreCase(SHIFT)) { string = extractDateAndShiftAsNodes(cell.getStringCellValue()); if (string != null) { cellStringBuilder.append(string); } else { cellStringBuilder.append(node(dataFieldNames.get(j), cell.getStringCellValue())); } } else { cellStringBuilder.append(node(dataFieldNames.get(j), cell.getStringCellValue())); } } else if (cell.getCellType() == Cell.CELL_TYPE_BLANK) { // cells.append(attribute(dataFieldNames.get(i), cell.getStringCellValue())); } else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { cellStringBuilder.append(node(dataFieldNames.get(j), cell.getNumericCellValue())); } else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) { cellStringBuilder.append(node(dataFieldNames.get(j), cell.getBooleanCellValue())); } else if (cell.getCellType() == Cell.CELL_TYPE_ERROR) { cellStringBuilder.append(node(dataFieldNames.get(j), cell.getErrorCellValue())); } else { cellStringBuilder.append(node(dataFieldNames.get(j), "N/A")); } return cellStringBuilder.toString(); }
From source file:org.nuclos.server.common.ooxml.ExcelReader.java
License:Open Source License
private static Object getCellValue(Cell cell, int cellType) { switch (cellType) { case Cell.CELL_TYPE_BLANK: return null; case Cell.CELL_TYPE_BOOLEAN: return cell.getBooleanCellValue(); case Cell.CELL_TYPE_NUMERIC: if (DateUtil.isCellDateFormatted(cell)) { return cell.getDateCellValue(); } else {/*from w w w . ja v a2 s. co m*/ return cell.getNumericCellValue(); } case Cell.CELL_TYPE_STRING: return cell.getStringCellValue(); case Cell.CELL_TYPE_ERROR: return FormulaError.forInt(cell.getErrorCellValue()).getString(); case Cell.CELL_TYPE_FORMULA: return cell.getCellFormula(); default: throw new IllegalArgumentException("Unknown POI cell type " + cellType); } }