List of usage examples for org.apache.poi.xssf.usermodel XSSFCell getCTCell
@Internal
public CTCell getCTCell()
From source file:com.opendoorlogistics.speedregions.excelshp.io.ExcelWriter.java
License:Apache License
private static void writeToCell(String value, JsonFormatTypes type, Cell cell) { if (type == JsonFormatTypes.STRING) { // HACK... POI is giving an exception when we try to write cells greater than // the Excel 2007 max length. However we don't care about this if we're just viewing // the results in ODL Studio, so we bypass the check for max cell length. XSSFCell hack = (XSSFCell) cell; hack.getCTCell().setV(value); } else {/* w ww . ja v a2 s .co m*/ cell.setCellValue(value); } if (value != null) { boolean numeric = isNumeric(value); boolean setToString = true; if (value.length() > 0 && (type == JsonFormatTypes.NUMBER || type == JsonFormatTypes.INTEGER || numeric)) { setToString = false; try { cell.setCellValue(Double.parseDouble(value)); cell.setCellType(Cell.CELL_TYPE_NUMERIC); } catch (Exception e) { setToString = true; } } if (setToString) { cell.setCellType(Cell.CELL_TYPE_STRING); } } }
From source file:org.bbreak.excella.core.util.PoiUtil.java
License:Open Source License
/** * ??? ??????<br>/*from w ww . j ava2 s . com*/ * <br> * ?[CELL_TYPE_ERROR]??<br> * xls? ?HSSFErrorConstants?<br> * xlsx? Excel??ex.#DIV/0!?#N/A?#REF! * * @param cell * @return */ public static Object getCellValue(Cell cell) { Object value = null; if (cell != null) { switch (cell.getCellTypeEnum()) { case BLANK: break; case BOOLEAN: value = cell.getBooleanCellValue(); break; case ERROR: value = cell.getErrorCellValue(); break; case NUMERIC: // ?? if (isCellDateFormatted(cell)) { value = cell.getDateCellValue(); } else { value = cell.getNumericCellValue(); } break; case STRING: value = cell.getStringCellValue(); break; case FORMULA: FormulaEvaluator evaluator = cell.getSheet().getWorkbook().getCreationHelper() .createFormulaEvaluator(); // ? CellValue cellValue = evaluator.evaluate(cell); CellType cellType = cellValue.getCellTypeEnum(); // ???? switch (cellType) { case BLANK: break; case BOOLEAN: value = cell.getBooleanCellValue(); break; case ERROR: if (cell instanceof XSSFCell) { // XSSF?????? XSSFCell xssfCell = (XSSFCell) cell; CTCell ctCell = xssfCell.getCTCell(); value = ctCell.getV(); } else if (cell instanceof HSSFCell) { // HSSF?????? value = cell.getErrorCellValue(); } break; case NUMERIC: // ?? if (isCellDateFormatted(cell)) { value = cell.getDateCellValue(); } else { value = cell.getNumericCellValue(); } break; case STRING: value = cell.getStringCellValue(); break; default: break; } default: break; } } return value; }