/** * 获取单元格值 * * @param cell {@link Cell}单元格 * @param isTrimCellValue 如果单元格类型为字符串,是否去掉两边空白符 * @return 值,类型可能为:Date、Double、Boolean、String */ public static Object getCellValue(Cell cell, boolean isTrimCellValue) { return getCellValue(cell, cell.getCellTypeEnum(), isTrimCellValue); }
/** * 获取单元格值 * * @param cell {@link Cell}单元格 * @param isTrimCellValue 如果单元格类型为字符串,是否去掉两边空白符 * @return 值,类型可能为:Date、Double、Boolean、String */ public static Object getCellValue(Cell cell, boolean isTrimCellValue) { return getCellValue(cell, cell.getCellTypeEnum(), isTrimCellValue); }
/** * 获取单元格值 * * @param cell {@link Cell}单元格 * @param cellEditor 单元格值编辑器。可以通过此编辑器对单元格值做自定义操作 * @return 值,类型可能为:Date、Double、Boolean、String */ public static Object getCellValue(Cell cell, CellEditor cellEditor) { if (null == cell) { return null; } return getCellValue(cell, cell.getCellTypeEnum(), cellEditor); }
/** * 获取单元格值 * * @param cell {@link Cell}单元格 * @param cellEditor 单元格值编辑器。可以通过此编辑器对单元格值做自定义操作 * @return 值,类型可能为:Date、Double、Boolean、String */ public static Object getCellValue(Cell cell, CellEditor cellEditor) { if (null == cell) { return null; } return getCellValue(cell, cell.getCellTypeEnum(), cellEditor); }
protected boolean currentRowIsEmpty() { if (currentRow.getPhysicalNumberOfCells() == 0) { return true; } for (Cell cell : currentRow) { if (cell.getCellTypeEnum() == CellType.STRING) { if (!cell.getStringCellValue().isEmpty()) { return false; } } else if (cell.getCellTypeEnum() != CellType.BLANK) { return false; } } return true; }
cellType = cell.getCellTypeEnum();
cellType = cell.getCellTypeEnum();
private static Object[] extract(Row row, Selection selection) { // selection.updateHorizontal(row.getFirstCellNum(),row.getLastCellNum()); Object[] result = new Object[selection.right-selection.left]; for (int i = selection.left; i < selection.right; i++) { Cell cell = row.getCell(i); if (cell == null) continue; result[i-selection.left] = getValue(cell, cell.getCellTypeEnum()); } return result; }
@Override public boolean isText() { return cell.getCellTypeEnum() == CellType.STRING; }
@Override public boolean isBoolean() { return cell.getCellTypeEnum() == CellType.BOOLEAN; }
@Override public boolean isNumber() { return cell.getCellTypeEnum() == CellType.NUMERIC; }
/** * 获取单元格值 * * @param cell {@link Cell}单元格 * @param isTrimCellValue 如果单元格类型为字符串,是否去掉两边空白符 * @return 值,类型可能为:Date、Double、Boolean、String */ public static Object getCellValue(Cell cell, boolean isTrimCellValue) { return getCellValue(cell, cell.getCellTypeEnum(), isTrimCellValue); }
private static String getStringCell(Sheet sheet, int rowIndex, int colIndex) { assert sheet != null; Row row = sheet.getRow(rowIndex); if (row == null) { return "?"; //$NON-NLS-1$ } Cell cell = row.getCell(colIndex); if (cell == null || cell.getCellTypeEnum() != CellType.STRING) { return "?"; //$NON-NLS-1$ } return cell.getStringCellValue(); }
private String getStringCell(Sheet sheet, int rowIndex, int colIndex) { assert sheet != null; Row row = sheet.getRow(rowIndex); if (row == null) { return null; } Cell cell = row.getCell(colIndex); if (cell == null || cell.getCellTypeEnum() != CellType.STRING) { return null; } return cell.getStringCellValue(); }
/** * 获取单元格值 * * @param cell {@link Cell}单元格 * @param cellEditor 单元格值编辑器。可以通过此编辑器对单元格值做自定义操作 * @return 值,类型可能为:Date、Double、Boolean、String */ public static Object getCellValue(Cell cell, CellEditor cellEditor) { if (null == cell) { return null; } return getCellValue(cell, cell.getCellTypeEnum(), cellEditor); }
public static Object getCellValue(final Workbook workbook, final Cell cell) { Object cellValue = null; if (cell.getCellTypeEnum() == CellType.STRING) { cellValue = getCellValueAsString(cell); } else if (cell.getCellTypeEnum() == CellType.NUMERIC) { cellValue = getNumericCellValue(cell); } else if (cell.getCellTypeEnum() == CellType.BOOLEAN) { cellValue = getCellValueAsBool(cell); } else if (cell.getCellTypeEnum() == CellType.FORMULA) { cellValue = evaluateCellFormula(workbook, cell); } return cellValue; }
private Object readCellValue(Cell cell) { return readCellValue(cell, cell.getCellTypeEnum()); }
/** * エラーセルの値を評価する。 * @param cell * @param locale * @return */ private CellFormatResult getErrorCellValue(final Cell cell, final Locale locale) { final CellType cellType = cell.getCellTypeEnum(); assert cellType == CellType.ERROR; return getErrorCellValue(cell.getErrorCellValue(), locale); }
@SuppressWarnings("deprecation") protected String getDataCellStringValue(int colNum) { Cell cell = getDataRow().getCell(colNum); if (cell == null) { return null; } else { if (cell.getCellTypeEnum() == CellType.NUMERIC) { return Double.toString(cell.getNumericCellValue()); } else { return cell.getStringCellValue(); } } }
@SuppressWarnings("deprecation") protected String getDataCellStringValue(int colNum) { Cell cell = getDataRow().getCell(colNum); if (cell == null) { return null; } else { if (cell.getCellTypeEnum() == CellType.NUMERIC) { return Double.toString(cell.getNumericCellValue()); } else { return cell.getStringCellValue(); } } }