Java Code Examples for org.apache.poi.ss.usermodel.CellType#ERROR
The following examples show how to use
org.apache.poi.ss.usermodel.CellType#ERROR .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StreamingCell.java From excel-streaming-reader with Apache License 2.0 | 7 votes |
/** * Only valid for formula cells * @return one of ({@link CellType#NUMERIC}, {@link CellType#STRING}, * {@link CellType#BOOLEAN}, {@link CellType#ERROR}) depending * on the cached value of the formula */ @Override public CellType getCachedFormulaResultType() { if (formulaType) { if(contentsSupplier.getContent() == null || type == null) { return CellType.BLANK; } else if("n".equals(type)) { return CellType.NUMERIC; } else if("s".equals(type) || "inlineStr".equals(type) || "str".equals(type)) { return CellType.STRING; } else if("b".equals(type)) { return CellType.BOOLEAN; } else if("e".equals(type)) { return CellType.ERROR; } else { throw new UnsupportedOperationException("Unsupported cell type '" + type + "'"); } } else { throw new IllegalStateException("Only formula cells have cached results"); } }
Example 2
Source File: HSSFCell.java From lams with GNU General Public License v2.0 | 6 votes |
/** * used internally -- given a cell value record, figure out its type */ private static CellType determineType(CellValueRecordInterface cval) { if (cval instanceof FormulaRecordAggregate) { return CellType.FORMULA; } // all others are plain BIFF records Record record = ( Record ) cval; switch (record.getSid()) { case NumberRecord.sid : return CellType.NUMERIC; case BlankRecord.sid : return CellType.BLANK; case LabelSSTRecord.sid : return CellType.STRING; case BoolErrRecord.sid : BoolErrRecord boolErrRecord = ( BoolErrRecord ) record; return boolErrRecord.isBoolean() ? CellType.BOOLEAN : CellType.ERROR; } throw new RuntimeException("Bad cell value rec (" + cval.getClass().getName() + ")"); }
Example 3
Source File: StreamingCell.java From excel-streaming-reader with Apache License 2.0 | 6 votes |
/** * Return the cell type. * * @return the cell type */ @Override public CellType getCellType() { if(formulaType) { return CellType.FORMULA; } else if(contentsSupplier.getContent() == null || type == null) { return CellType.BLANK; } else if("n".equals(type)) { return CellType.NUMERIC; } else if("s".equals(type) || "inlineStr".equals(type) || "str".equals(type)) { return CellType.STRING; } else if("str".equals(type)) { return CellType.FORMULA; } else if("b".equals(type)) { return CellType.BOOLEAN; } else if("e".equals(type)) { return CellType.ERROR; } else { throw new UnsupportedOperationException("Unsupported cell type '" + type + "'"); } }
Example 4
Source File: ForkedEvaluationCell.java From lams with GNU General Public License v2.0 | 5 votes |
public void setValue(ValueEval value) { Class<? extends ValueEval> cls = value.getClass(); if (cls == NumberEval.class) { _cellType = CellType.NUMERIC; _numberValue = ((NumberEval)value).getNumberValue(); return; } if (cls == StringEval.class) { _cellType = CellType.STRING; _stringValue = ((StringEval)value).getStringValue(); return; } if (cls == BoolEval.class) { _cellType = CellType.BOOLEAN; _booleanValue = ((BoolEval)value).getBooleanValue(); return; } if (cls == ErrorEval.class) { _cellType = CellType.ERROR; _errorValue = ((ErrorEval)value).getErrorCode(); return; } if (cls == BlankEval.class) { _cellType = CellType.BLANK; return; } throw new IllegalArgumentException("Unexpected value class (" + cls.getName() + ")"); }
Example 5
Source File: ExcelUtil.java From supplierShop with MIT License | 4 votes |
/** * 获取单元格值 * * @param row 获取的行 * @param column 获取单元格列号 * @return 单元格值 */ public Object getCellValue(Row row, int column) { if (row == null) { return row; } Object val = ""; try { Cell cell = row.getCell(column); if (cell != null) { if (cell.getCellTypeEnum() == CellType.NUMERIC || cell.getCellTypeEnum() == CellType.FORMULA) { val = cell.getNumericCellValue(); if (HSSFDateUtil.isCellDateFormatted(cell)) { val = DateUtil.getJavaDate((Double) val); // POI Excel 日期格式转换 } else { if ((Double) val % 1 > 0) { val = new DecimalFormat("0.00").format(val); } else { val = new DecimalFormat("0").format(val); } } } else if (cell.getCellTypeEnum() == CellType.STRING) { val = cell.getStringCellValue(); } else if (cell.getCellTypeEnum() == CellType.BOOLEAN) { val = cell.getBooleanCellValue(); } else if (cell.getCellTypeEnum() == CellType.ERROR) { val = cell.getErrorCellValue(); } } } catch (Exception e) { return val; } return val; }
Example 6
Source File: ExcelUtil.java From RuoYi-Vue with MIT License | 4 votes |
/** * 获取单元格值 * * @param row 获取的行 * @param column 获取单元格列号 * @return 单元格值 */ public Object getCellValue(Row row, int column) { if (row == null) { return row; } Object val = ""; try { Cell cell = row.getCell(column); if (StringUtils.isNotNull(cell)) { if (cell.getCellTypeEnum() == CellType.NUMERIC || cell.getCellTypeEnum() == CellType.FORMULA) { val = cell.getNumericCellValue(); if (HSSFDateUtil.isCellDateFormatted(cell)) { val = DateUtil.getJavaDate((Double) val); // POI Excel 日期格式转换 } else { if ((Double) val % 1 > 0) { val = new DecimalFormat("0.00").format(val); } else { val = new DecimalFormat("0").format(val); } } } else if (cell.getCellTypeEnum() == CellType.STRING) { val = cell.getStringCellValue(); } else if (cell.getCellTypeEnum() == CellType.BOOLEAN) { val = cell.getBooleanCellValue(); } else if (cell.getCellTypeEnum() == CellType.ERROR) { val = cell.getErrorCellValue(); } } } catch (Exception e) { return val; } return val; }
Example 7
Source File: ExcelUtil.java From ruoyiplus with MIT License | 4 votes |
/** * 获取单元格值 * * @param row 获取的行 * @param column 获取单元格列号 * @return 单元格值 */ public Object getCellValue(Row row, int column) { if (row == null) { return row; } Object val = ""; try { Cell cell = row.getCell(column); if (cell != null) { if (cell.getCellTypeEnum() == CellType.NUMERIC) { val = cell.getNumericCellValue(); if (HSSFDateUtil.isCellDateFormatted(cell)) { val = DateUtil.getJavaDate((Double) val); // POI Excel 日期格式转换 } else { if ((Double) val % 1 > 0) { val = new DecimalFormat("0.00").format(val); } else { val = new DecimalFormat("0").format(val); } } } else if (cell.getCellTypeEnum() == CellType.STRING) { val = cell.getStringCellValue(); } else if (cell.getCellTypeEnum() == CellType.BOOLEAN) { val = cell.getBooleanCellValue(); } else if (cell.getCellTypeEnum() == CellType.ERROR) { val = cell.getErrorCellValue(); } } } catch (Exception e) { return val; } return val; }
Example 8
Source File: ExcelUtil.java From LuckyFrameWeb with GNU Affero General Public License v3.0 | 4 votes |
/** * 获取单元格值 * * @param row 获取的行 * @param column 获取单元格列号 * @return 单元格值 */ public Object getCellValue(Row row, int column) { if (row == null) { return null; } Object val = ""; try { Cell cell = row.getCell(column); if (cell != null) { if (cell.getCellTypeEnum() == CellType.NUMERIC) { val = cell.getNumericCellValue(); if (HSSFDateUtil.isCellDateFormatted(cell)) { val = DateUtil.getJavaDate((Double) val); // POI Excel 日期格式转换 } else { if ((Double) val % 1 > 0) { val = new DecimalFormat("0.00").format(val); } else { val = new DecimalFormat("0").format(val); } } } else if (cell.getCellTypeEnum() == CellType.STRING) { val = cell.getStringCellValue(); } else if (cell.getCellTypeEnum() == CellType.BOOLEAN) { val = cell.getBooleanCellValue(); } else if (cell.getCellTypeEnum() == CellType.ERROR) { val = cell.getErrorCellValue(); } } } catch (Exception e) { return val; } return val; }
Example 9
Source File: GetRowIndexByConditionService.java From cs-actions with Apache License 2.0 | 4 votes |
private static String getRowIndex(final Sheet worksheet, final int firstRow, final String input, final int columnIndex, final String operator) { String result = ""; double cellValueNumeric; String cellFormat; double inputNumeric = processValueInput(input); for (int i = firstRow; i <= worksheet.getLastRowNum(); i++) { Row row = worksheet.getRow(i); if (row == null) { row = worksheet.createRow(i); } if (row != null) { Cell cell = row.getCell(columnIndex); if (cell == null) { cell = row.createCell(columnIndex); } if (cell != null) { CellType cellType = cell.getCellType(); if (cellType != CellType.ERROR) { cellFormat = getCellType(cell); //string comparison if (cellFormat.equalsIgnoreCase("string") && inputFormat.equalsIgnoreCase("string")) { DataFormatter aFormatter = new DataFormatter(); String aCellString = aFormatter.formatCellValue(cell); if (compareStringValue(aCellString, input, operator)) { result += i + ","; } } //value input is empty, and the cell in the worksheet is in numeric type else if (!cellFormat.equalsIgnoreCase(inputFormat)) //((cellType != CellType.STRING && inputFormat.equalsIgnoreCase("string"))|| //(cellType != CellType.NUMERIC && !inputFormat.equalsIgnoreCase("string"))) { if (operator.equals("!=")) { result += i + ","; } } //numeric comparison else if (cellType == CellType.NUMERIC && !inputFormat.equalsIgnoreCase("string")) { cellValueNumeric = cell.getNumericCellValue(); //both are date or time if ((cellFormat.equalsIgnoreCase("date") && inputFormat.equalsIgnoreCase("date")) || (cellFormat.equalsIgnoreCase("time") && inputFormat.equalsIgnoreCase("time")) || (cellFormat.equalsIgnoreCase("num") && inputFormat.equalsIgnoreCase("num"))) { if (compareNumericValue(cellValueNumeric, inputNumeric, operator)) { result += i + ","; } } } } } } } if (!result.isEmpty()) { final int index = result.lastIndexOf(','); result = result.substring(0, index); } return result; }