Java Code Examples for org.apache.poi.ss.usermodel.Cell#CELL_TYPE_ERROR
The following examples show how to use
org.apache.poi.ss.usermodel.Cell#CELL_TYPE_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: XssfWCellImpl.java From xlsbeans with Apache License 2.0 | 6 votes |
private String getCellFormulaContents(Cell cell) { String contents = null; switch (cell.getCachedFormulaResultType()) { case Cell.CELL_TYPE_NUMERIC: contents = getNumericContents(cell); break; case Cell.CELL_TYPE_STRING: contents = cell.getStringCellValue(); break; case Cell.CELL_TYPE_BOOLEAN: contents = String.valueOf(cell.getBooleanCellValue()); break; case Cell.CELL_TYPE_ERROR: contents = String.valueOf(cell.getCellFormula()); break; default: contents = ""; } return contents; }
Example 2
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 3
Source File: XssfWCellImpl.java From xlsbeans with Apache License 2.0 | 6 votes |
private String getCellFormulaContents(Cell cell) { String contents = null; switch (cell.getCachedFormulaResultType()) { case Cell.CELL_TYPE_NUMERIC: contents = getNumericContents(cell); break; case Cell.CELL_TYPE_STRING: contents = cell.getStringCellValue(); break; case Cell.CELL_TYPE_BOOLEAN: contents = String.valueOf(cell.getBooleanCellValue()); break; case Cell.CELL_TYPE_ERROR: contents = String.valueOf(cell.getCellFormula()); break; default: contents = ""; } return contents; }
Example 4
Source File: PoiSheetUtility.java From autopoi with Apache License 2.0 | 5 votes |
private static void cloneCell(Cell cNew, Cell cOld) { cNew.setCellComment(cOld.getCellComment()); cNew.setCellStyle(cOld.getCellStyle()); switch (cNew.getCellType()) { case Cell.CELL_TYPE_BOOLEAN: { cNew.setCellValue(cOld.getBooleanCellValue()); break; } 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; } } }
Example 5
Source File: AbstractExcelExtractor.java From wandora with GNU General Public License v3.0 | 5 votes |
public Topic getCellTypeTopic(Cell cell, TopicMap tm) throws TopicMapException { int type = cell.getCellType(); String typeStr = "string"; switch(type) { case Cell.CELL_TYPE_BLANK: { typeStr = "blank"; break; } case Cell.CELL_TYPE_BOOLEAN: { typeStr = "boolean"; break; } case Cell.CELL_TYPE_ERROR: { typeStr = "error"; break; } case Cell.CELL_TYPE_FORMULA: { typeStr = "formula"; break; } case Cell.CELL_TYPE_NUMERIC: { typeStr = "numeric"; break; } case Cell.CELL_TYPE_STRING: { typeStr = "string"; break; } } Topic t = getOrCreateTopic(tm, EXCEL_CELL_TYPE_SI_PREFIX+"/"+typeStr, "Excel cell type "+typeStr); t.addType(getCellTypeTypeTopic(tm)); return t; }
Example 6
Source File: SsioIntegrationTest.java From sep4j with Apache License 2.0 | 5 votes |
private Object getStringOrDateValue(Cell cell) { if (cell == null) { return null; } if (cell.getCellType() == Cell.CELL_TYPE_BLANK) { return null; } if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) { return String.valueOf(cell.getBooleanCellValue()); } if (cell.getCellType() == Cell.CELL_TYPE_ERROR) { return null; } if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) { return null; } if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { if (DateUtil.isCellDateFormatted(cell)) { return cell.getDateCellValue(); } else { double v = cell.getNumericCellValue(); return String.valueOf(v); } } if (cell.getCellType() == Cell.CELL_TYPE_STRING) { String s = cell.getStringCellValue(); return StringUtils.trimToNull(s); } return null; }
Example 7
Source File: Ssio.java From sep4j with Apache License 2.0 | 5 votes |
/** * read the cell. it only supports: boolean, numeric, date(numeric cell type * + date cell format) and string. * * @param cell * the cell to read * @return the date if it is a date cell, or else the string value (will be * trimmed to null) . <br/> * * */ static Object readCellAsStringOrDate(Cell cell) { if (cell == null) { return null; } if (cell.getCellType() == Cell.CELL_TYPE_BLANK) { return null; } if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) { return String.valueOf(cell.getBooleanCellValue()); } if (cell.getCellType() == Cell.CELL_TYPE_ERROR) { return null; } if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) { return null; } if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { if (DateUtil.isCellDateFormatted(cell)) { return cell.getDateCellValue(); } else { double v = cell.getNumericCellValue(); return String.valueOf(v); } } if (cell.getCellType() == Cell.CELL_TYPE_STRING) { String s = cell.getStringCellValue(); return StringUtils.trimToNull(s); } return null; }
Example 8
Source File: XssfWCellImpl.java From xlsbeans with Apache License 2.0 | 5 votes |
public String getContents() { String contents = null; // IllegalStateException occurs , if illegal type defined... switch (cell.getCellType()) { case Cell.CELL_TYPE_BLANK: contents = ""; break; case Cell.CELL_TYPE_BOOLEAN: contents = String.valueOf(cell.getBooleanCellValue()); break; case Cell.CELL_TYPE_ERROR: contents = String.valueOf(cell.getCellFormula()); break; case Cell.CELL_TYPE_FORMULA: contents = getCellFormulaContents(cell); break; case Cell.CELL_TYPE_NUMERIC: contents = getNumericContents(cell); break; case Cell.CELL_TYPE_STRING: contents = String.valueOf(cell.getStringCellValue()); break; default: contents = ""; break; } return contents; }
Example 9
Source File: SheetUtility.java From openbd-core with GNU General Public License v3.0 | 5 votes |
public static void cloneCell( Cell cNew, Cell cOld ){ cNew.setCellComment( cOld.getCellComment() ); cNew.setCellStyle( cOld.getCellStyle() ); cNew.setCellType( cOld.getCellType() ); switch ( cNew.getCellType() ){ case Cell.CELL_TYPE_BOOLEAN:{ cNew.setCellValue( cOld.getBooleanCellValue() ); break; } 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; } case Cell.CELL_TYPE_BLANK:{ cNew.setCellValue( cOld.getNumericCellValue() ); break; } } }
Example 10
Source File: ExcelTempletService.java From jeewx with Apache License 2.0 | 5 votes |
/** * 得到某个格子的值 已经对过时方法进行更新 * * @param cell * 格子对象 * @return 格子的值 */ public static String getCellValueString(Cell cell) { if (cell == null) { return null; } // 时间对象 特殊处理 int dataFormat = cell.getCellStyle().getDataFormat(); if (dataFormat == 14 || dataFormat == 178 || dataFormat == 180 || dataFormat == 181 || dataFormat == 182) { return getDateValue(cell); } String value = null; switch (cell.getCellType()) { case Cell.CELL_TYPE_NUMERIC : value = new DecimalFormat("0.##########").format(cell.getNumericCellValue()); break; case Cell.CELL_TYPE_STRING : // value = cell.getStringCellValue(); value = cell.getRichStringCellValue().toString(); break; case Cell.CELL_TYPE_FORMULA : value = String.valueOf(cell.getCellFormula()); break; case Cell.CELL_TYPE_BLANK : // value = String.valueOf(cell.getStringCellValue()); value = String.valueOf(cell.getRichStringCellValue().toString()); break; case Cell.CELL_TYPE_BOOLEAN : value = String.valueOf(cell.getBooleanCellValue()); break; case Cell.CELL_TYPE_ERROR : value = String.valueOf(cell.getErrorCellValue()); break; } return value; }
Example 11
Source File: Excel2007ResultSet.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
@Override public boolean isMissing(int columnIndex) { Cell cell = getCurrentCell(columnIndex); try { return cell == null || cell.getCellType() == Cell.CELL_TYPE_BLANK || cell.getCellType() == Cell.CELL_TYPE_ERROR || "".equals(cell.getStringCellValue().trim()); } catch (IllegalStateException e) { return false; } }
Example 12
Source File: PoiSheetUtility.java From easypoi with Apache License 2.0 | 5 votes |
private static void cloneCell(Cell cNew, Cell cOld) { cNew.setCellComment(cOld.getCellComment()); cNew.setCellStyle(cOld.getCellStyle()); switch (cNew.getCellType()) { case Cell.CELL_TYPE_BOOLEAN: { cNew.setCellValue(cOld.getBooleanCellValue()); break; } 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; } } }
Example 13
Source File: PoiCell.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public KCellType getType() { int type = cell.getCellType(); if ( type == Cell.CELL_TYPE_BOOLEAN ) { return KCellType.BOOLEAN; } else if ( type == Cell.CELL_TYPE_NUMERIC ) { if ( HSSFDateUtil.isCellDateFormatted( cell ) ) { return KCellType.DATE; } else { return KCellType.NUMBER; } } else if ( type == Cell.CELL_TYPE_STRING ) { return KCellType.LABEL; } else if ( type == Cell.CELL_TYPE_BLANK || type == Cell.CELL_TYPE_ERROR ) { return KCellType.EMPTY; } else if ( type == Cell.CELL_TYPE_FORMULA ) { switch ( cell.getCachedFormulaResultType() ) { case Cell.CELL_TYPE_BLANK: case Cell.CELL_TYPE_ERROR: return KCellType.EMPTY; case Cell.CELL_TYPE_BOOLEAN: return KCellType.BOOLEAN_FORMULA; case Cell.CELL_TYPE_STRING: return KCellType.STRING_FORMULA; case Cell.CELL_TYPE_NUMERIC: if ( HSSFDateUtil.isCellDateFormatted( cell ) ) { return KCellType.DATE_FORMULA; } else { return KCellType.NUMBER_FORMULA; } default: break; } } return null; }
Example 14
Source File: PoiSheetUtility.java From jeasypoi with Apache License 2.0 | 5 votes |
private static void cloneCell(Cell cNew, Cell cOld) { cNew.setCellComment(cOld.getCellComment()); cNew.setCellStyle(cOld.getCellStyle()); switch (cNew.getCellType()) { case Cell.CELL_TYPE_BOOLEAN: { cNew.setCellValue(cOld.getBooleanCellValue()); break; } 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; } } }
Example 15
Source File: ExcelTempletService.java From jeecg with Apache License 2.0 | 5 votes |
/** * 得到某个格子的值 已经对过时方法进行更新 * * @param cell * 格子对象 * @return 格子的值 */ public static String getCellValueString(Cell cell) { if (cell == null) { return null; } // 时间对象 特殊处理 int dataFormat = cell.getCellStyle().getDataFormat(); if (dataFormat == 14 || dataFormat == 178 || dataFormat == 180 || dataFormat == 181 || dataFormat == 182) { return getDateValue(cell); } String value = null; switch (cell.getCellType()) { case Cell.CELL_TYPE_NUMERIC : value = new DecimalFormat("0.##########").format(cell.getNumericCellValue()); break; case Cell.CELL_TYPE_STRING : // value = cell.getStringCellValue(); value = cell.getRichStringCellValue().toString(); break; case Cell.CELL_TYPE_FORMULA : value = String.valueOf(cell.getCellFormula()); break; case Cell.CELL_TYPE_BLANK : // value = String.valueOf(cell.getStringCellValue()); value = String.valueOf(cell.getRichStringCellValue().toString()); break; case Cell.CELL_TYPE_BOOLEAN : value = String.valueOf(cell.getBooleanCellValue()); break; case Cell.CELL_TYPE_ERROR : value = String.valueOf(cell.getErrorCellValue()); break; } return value; }
Example 16
Source File: ExcelUtils.java From onetwo with Apache License 2.0 | 4 votes |
public static void copyRow(Sheet worksheet, Row newRow, Row sourceRow) { Workbook workbook = worksheet.getWorkbook(); for (int i = 0; i < sourceRow.getLastCellNum(); i++) { Cell oldCell = sourceRow.getCell(i); Cell newCell = newRow.createCell(i); if (oldCell == null) { newCell = null; continue; } CellStyle newCellStyle = workbook.createCellStyle(); newCellStyle.cloneStyleFrom(oldCell.getCellStyle()); newCell.setCellStyle(newCellStyle); if (oldCell.getCellComment() != null) { newCell.setCellComment(oldCell.getCellComment()); } if (oldCell.getHyperlink() != null) { newCell.setHyperlink(oldCell.getHyperlink()); } newCell.setCellType(oldCell.getCellType()); switch (oldCell.getCellType()) { case Cell.CELL_TYPE_BLANK: newCell.setCellValue(oldCell.getStringCellValue()); 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; } } for (int i = 0; i < worksheet.getNumMergedRegions(); i++) { CellRangeAddress cellRangeAddress = worksheet.getMergedRegion(i); if (cellRangeAddress.getFirstRow() == sourceRow.getRowNum()) { CellRangeAddress newCellRangeAddress = new CellRangeAddress(newRow.getRowNum(), (newRow.getRowNum() + (cellRangeAddress.getLastRow() - cellRangeAddress.getFirstRow() )), cellRangeAddress.getFirstColumn(), cellRangeAddress.getLastColumn()); worksheet.addMergedRegion(newCellRangeAddress); } } }
Example 17
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 18
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 19
Source File: XSSFSheetXMLHandler.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void endElement(String uri, String localName, String name) throws SAXException { String thisStr = null; int cellType; // v => contents of a cell if (isTextTag(localName)) { vIsOpen = false; // Process the value contents as required, now we have it all switch (nextDataType) { case BOOLEAN: char first = value.charAt(0); thisStr = Character.toString(first); cellType = Cell.CELL_TYPE_BOOLEAN; break; case ERROR: thisStr = "ERROR:" + value.toString(); cellType = Cell.CELL_TYPE_ERROR; break; case FORMULA: if(formulasNotResults) { thisStr = formula.toString(); } else { thisStr = value.toString(); } cellType = Cell.CELL_TYPE_FORMULA; break; case INLINE_STRING: // TODO: Can these ever have formatting on them? XSSFRichTextString rtsi = new XSSFRichTextString(value.toString()); thisStr = rtsi.toString(); cellType = Cell.CELL_TYPE_STRING; break; case SST_STRING: String sstIndex = value.toString(); try { int idx = Integer.parseInt(sstIndex); XSSFRichTextString rtss = new XSSFRichTextString(sharedStringsTable.getEntryAt(idx)); thisStr = rtss.toString(); } catch (NumberFormatException ex) { System.err.println("Failed to parse SST index '" + sstIndex + "': " + ex.toString()); } cellType = Cell.CELL_TYPE_STRING; break; case NUMBER: String n = value.toString(); thisStr = n; cellType = Cell.CELL_TYPE_NUMERIC; break; default: thisStr = "(TODO: Unexpected type: " + nextDataType + ")"; cellType = -1; break; } // Output output.cell(cellRef, cellType, formulaType, thisStr, styleIndex); formulaType = -1; } else if ("is".equals(localName)) { isIsOpen = false; } else if ("row".equals(localName)) { output.endRow(); } else if ("oddHeader".equals(localName) || "evenHeader".equals(localName) || "firstHeader".equals(localName)) { hfIsOpen = false; output.headerFooter(headerFooter.toString(), true, localName); } else if ("oddFooter".equals(localName) || "evenFooter".equals(localName) || "firstFooter".equals(localName)) { hfIsOpen = false; output.headerFooter(headerFooter.toString(), false, localName); } }
Example 20
Source File: ExcelUtil.java From game-server with MIT License | 4 votes |
/** * 获取属性值 * * @param cell * @param type * @return */ public static Object getCellValue(Cell cell, String type) { String cellValue = ""; type = type.toLowerCase(); if (cell == null) { //表格未填数据设置默认值 switch (type) { case "int": case "short": case "byte": case "long": return 0; case "float": case "double": return 0.0; case "array": return new ArrayList<Document>(); case "object": return new Document(); case "boolean": return false; default: return cellValue; } } //把数字当成String来读,避免出现1读成1.0的情况 if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { cell.setCellType(Cell.CELL_TYPE_STRING); } //判断数据的类型 switch (cell.getCellType()) { case Cell.CELL_TYPE_NUMERIC: //数字 cellValue = String.valueOf(cell.getNumericCellValue()); break; case Cell.CELL_TYPE_STRING: //字符串 cellValue = String.valueOf(cell.getStringCellValue()); break; case Cell.CELL_TYPE_BOOLEAN: //Boolean cellValue = String.valueOf(cell.getBooleanCellValue()); break; case Cell.CELL_TYPE_FORMULA: //公式 cellValue = String.valueOf(cell.getCellFormula()); break; case Cell.CELL_TYPE_BLANK: //空值 cellValue = ""; break; case Cell.CELL_TYPE_ERROR: //故障 cellValue = "非法字符"; break; default: cellValue = "未知类型"; break; } if ("int".equalsIgnoreCase(type)) { return Integer.parseInt(cellValue); } else if ("long".equalsIgnoreCase(type)) { return Long.parseLong(cellValue); } else if ("byte".equalsIgnoreCase(type)) { return Byte.parseByte(cellValue); } else if ("short".equalsIgnoreCase(type)) { return Short.parseShort(cellValue); } else if ("Date".equalsIgnoreCase(type)) { return new Date(cellValue); } else if ("boolean".equalsIgnoreCase(type)) { return Boolean.parseBoolean(cellValue); } else if ("float".equalsIgnoreCase(type)) { return Float.parseFloat(cellValue); } else if ("double".equalsIgnoreCase(type)) { return Double.parseDouble(cellValue); } else if ("array".equalsIgnoreCase(type)) { return MongoUtil.getDocuments(cellValue); } else if ("object".equalsIgnoreCase(type)) { return MongoUtil.getDocument(cellValue); } return cellValue; }