Java Code Examples for org.apache.poi.ss.usermodel.Cell#getErrorCellValue()
The following examples show how to use
org.apache.poi.ss.usermodel.Cell#getErrorCellValue() .
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: ImportExcel.java From Shop-for-JavaWeb with MIT License | 6 votes |
/** * 获取单元格值 * @param row 获取的行 * @param column 获取单元格列号 * @return 单元格值 */ public Object getCellValue(Row row, int column){ Object val = ""; try{ Cell cell = row.getCell(column); if (cell != null){ if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC){ val = cell.getNumericCellValue(); }else if (cell.getCellType() == Cell.CELL_TYPE_STRING){ val = cell.getStringCellValue(); }else if (cell.getCellType() == Cell.CELL_TYPE_FORMULA){ val = cell.getCellFormula(); }else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN){ val = cell.getBooleanCellValue(); }else if (cell.getCellType() == Cell.CELL_TYPE_ERROR){ val = cell.getErrorCellValue(); } } }catch (Exception e) { return val; } return val; }
Example 2
Source File: ExcelUtil.java From danyuan-application with Apache License 2.0 | 5 votes |
/*** * 读取单元格的值 * * @Title: getCellValue * @Date : 2014-9-11 上午10:52:07 * @param cell * @return */ @SuppressWarnings("deprecation") public String getCellValue(Cell cell) { Object result = ""; if (cell != null) { switch (cell.getCellTypeEnum()) { case STRING: result = cell.getStringCellValue(); break; case NUMERIC: result = cell.getNumericCellValue(); break; case BOOLEAN: result = cell.getBooleanCellValue(); break; case FORMULA: result = cell.getCellFormula(); break; case ERROR: result = cell.getErrorCellValue(); break; case BLANK: break; default: break; } } return result.toString(); }
Example 3
Source File: AbstractExcelExtractor.java From wandora with GNU General Public License v3.0 | 5 votes |
protected String getCellValueAsString(Cell cell, int type) { if(cell != null) { switch(type) { case Cell.CELL_TYPE_ERROR: { return "ERROR"+cell.getErrorCellValue(); } case Cell.CELL_TYPE_BOOLEAN: { return ""+cell.getBooleanCellValue(); } case Cell.CELL_TYPE_NUMERIC: { if(DateUtil.isCellDateFormatted(cell)) { return dateFormat.format(cell.getDateCellValue()); } else { double value = cell.getNumericCellValue(); String formatString = cell.getCellStyle().getDataFormatString(); int formatIndex = cell.getCellStyle().getDataFormat(); return formatter.formatRawCellContents(value, formatIndex, formatString); } } case Cell.CELL_TYPE_STRING: { return cell.getRichStringCellValue().getString(); } } } return null; }
Example 4
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 5
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 6
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 7
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 8
Source File: ExcelUtil.java From SI with BSD 2-Clause "Simplified" License | 4 votes |
/** * 엑셀파일로부터 데이터를 읽어 리턴한다. * */ public static List getData(Workbook wb) { List excelList = new ArrayList(); int sheetNum = wb.getNumberOfSheets(); for (int k=0; k<sheetNum; k++) { Sheet sheet = wb.getSheetAt(k); int rows = sheet.getPhysicalNumberOfRows(); for (int r=0; r<rows; r++) { Row row = sheet.getRow(r); if (row != null) { int cells = row.getPhysicalNumberOfCells(); String[] excelRow = new String[cells]; for(int c=0; c<cells; c++) { Cell cell = row.getCell(c); if (cell != null) { String value = null; switch (cell.getCellType()) { case Cell.CELL_TYPE_FORMULA: value = cell.getCellFormula(); break; case Cell.CELL_TYPE_NUMERIC: value = "" + Integer.parseInt(String.valueOf(Math.round(cell.getNumericCellValue()))); break; case Cell.CELL_TYPE_STRING: value = "" + cell.getStringCellValue(); break; case Cell.CELL_TYPE_BLANK: value = "" + cell.getBooleanCellValue(); break; case Cell.CELL_TYPE_ERROR: value = "" + cell.getErrorCellValue(); break; default: } excelRow[c] = value; } } excelList.add(excelRow); } } } return excelList; }
Example 9
Source File: ExcelUtil.java From SI with BSD 2-Clause "Simplified" License | 4 votes |
/** * 엑셀파일로부터 데이터를 읽어 리턴한다. * */ public static List getData(Workbook wb) { List excelList = new ArrayList(); int sheetNum = wb.getNumberOfSheets(); for (int k=0; k<sheetNum; k++) { Sheet sheet = wb.getSheetAt(k); int rows = sheet.getPhysicalNumberOfRows(); for (int r=0; r<rows; r++) { Row row = sheet.getRow(r); if (row != null) { int cells = row.getPhysicalNumberOfCells(); String[] excelRow = new String[cells]; for(int c=0; c<cells; c++) { Cell cell = row.getCell(c); if (cell != null) { String value = null; switch (cell.getCellType()) { case Cell.CELL_TYPE_FORMULA: value = cell.getCellFormula(); break; case Cell.CELL_TYPE_NUMERIC: value = "" + Integer.parseInt(String.valueOf(Math.round(cell.getNumericCellValue()))); break; case Cell.CELL_TYPE_STRING: value = "" + cell.getStringCellValue(); break; case Cell.CELL_TYPE_BLANK: value = "" + cell.getBooleanCellValue(); break; case Cell.CELL_TYPE_ERROR: value = "" + cell.getErrorCellValue(); break; default: } excelRow[c] = value; } } excelList.add(excelRow); } } } return excelList; }