List of usage examples for org.apache.poi.ss.usermodel Cell getErrorCellValue
byte getErrorCellValue();
From source file:com.rapidminer.operator.nio.Excel2007SheetTableModel.java
License:Open Source License
@Override public Object getValueAt(int rowIndex, int columnIndex) { Cell cell; if (config != null) { Row row = sheet.getRow(rowIndex + config.getRowOffset()); if (row == null) { return null; }/*from www. j a va 2 s . c o m*/ cell = row.getCell(columnIndex + config.getColumnOffset()); } else { Row row = sheet.getRow(rowIndex); if (row == null) { return null; } cell = row.getCell(columnIndex); } if (cell == null) { return null; } if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) { return cell.getBooleanCellValue(); } else if (cell.getCellType() == Cell.CELL_TYPE_STRING) { return cell.getStringCellValue(); } else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { if (HSSFDateUtil.isCellDateFormatted(cell)) { return cell.getDateCellValue(); } else { return cell.getNumericCellValue(); } } else if (cell.getCellType() == Cell.CELL_TYPE_ERROR) { return cell.getErrorCellValue(); } else if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) { return cell.getNumericCellValue(); } else { // last resort, should not come to this // maybe return null? return ""; } }
From source file:com.tecacet.jflat.excel.PoiExcelReader.java
License:Apache License
private String getCellContentAsString(Cell cell) { switch (cell.getCellType()) { case Cell.CELL_TYPE_STRING: return cell.getRichStringCellValue().getString(); case Cell.CELL_TYPE_NUMERIC: if (DateUtil.isCellDateFormatted(cell)) { return cell.getDateCellValue().toString(); } else {/*w ww .j av a 2 s .com*/ double d = cell.getNumericCellValue(); // TODO find a flexible enough format for all numeric types return numberFormat.format(d); // return Double.toString(d); } case Cell.CELL_TYPE_BOOLEAN: boolean b = cell.getBooleanCellValue(); return Boolean.toString(b); case Cell.CELL_TYPE_FORMULA: return cell.getCellFormula(); case Cell.CELL_TYPE_BLANK: return ""; case Cell.CELL_TYPE_ERROR: byte bt = cell.getErrorCellValue(); return Byte.toString(bt); default: return cell.getStringCellValue(); } }
From source file:com.vaadin.addon.spreadsheet.CellSelectionShifter.java
License:Open Source License
/** * "Shifts" cell value. Shifting here is an Excel term and means the * situation where the user has selected one or more cells, and grabs the * bottom right hand square of the selected area to extend or curtail the * selection and fill the new area with values determined from the existing * values.//from w w w . j av a2 s.c o m * * @param shiftedCell * Source cell * @param newCell * Resulting new cell * @param removeShifted * true to remove the source cell at the end * @param sequenceIncrement * increment added to shifted cell value */ protected void shiftCellValue(Cell shiftedCell, Cell newCell, boolean removeShifted, Double sequenceIncrement) { // clear the new cell first because it might have errors which prevent // it from being set to a new type if (newCell.getCellType() != Cell.CELL_TYPE_BLANK || shiftedCell.getCellType() == Cell.CELL_TYPE_BLANK) { newCell.setCellType(Cell.CELL_TYPE_BLANK); } newCell.setCellType(shiftedCell.getCellType()); newCell.setCellStyle(shiftedCell.getCellStyle()); spreadsheet.getSpreadsheetStyleFactory().cellStyleUpdated(newCell, true); switch (shiftedCell.getCellType()) { case Cell.CELL_TYPE_FORMULA: shiftFormula(shiftedCell, newCell); break; case Cell.CELL_TYPE_BOOLEAN: newCell.setCellValue(shiftedCell.getBooleanCellValue()); break; case Cell.CELL_TYPE_ERROR: newCell.setCellValue(shiftedCell.getErrorCellValue()); break; case Cell.CELL_TYPE_NUMERIC: shiftNumeric(shiftedCell, newCell, sequenceIncrement); break; case Cell.CELL_TYPE_STRING: shiftString(shiftedCell, newCell, sequenceIncrement); break; case Cell.CELL_TYPE_BLANK: // cell is cleared when type is set default: break; } spreadsheet.getCellValueManager().cellUpdated(newCell); if (removeShifted) { shiftedCell.setCellValue((String) null); spreadsheet.getCellValueManager().cellDeleted(shiftedCell); } }
From source file:com.vaadin.addon.spreadsheet.CellValueManager.java
License:Open Source License
private String getCachedFormulaCellValue(Cell formulaCell) { String result = null;//from w w w .j a va 2 s .c o m switch (formulaCell.getCachedFormulaResultType()) { case Cell.CELL_TYPE_STRING: result = formulaCell.getStringCellValue(); break; case Cell.CELL_TYPE_BOOLEAN: result = String.valueOf(formulaCell.getBooleanCellValue()); break; case Cell.CELL_TYPE_ERROR: result = ErrorEval.getText(formulaCell.getErrorCellValue()); break; case Cell.CELL_TYPE_NUMERIC: CellStyle style = formulaCell.getCellStyle(); result = formatter.formatRawCellContents(formulaCell.getNumericCellValue(), style.getDataFormat(), style.getDataFormatString()); break; } return result; }
From source file:com.vaadin.addon.spreadsheet.CellValueManager.java
License:Open Source License
public String getOriginalCellValue(Cell cell) { if (cell == null) { return ""; }/*ww w . j av a 2 s .c om*/ int cellType = cell.getCellType(); switch (cellType) { case Cell.CELL_TYPE_FORMULA: return cell.getCellFormula(); case Cell.CELL_TYPE_NUMERIC: if (DateUtil.isCellDateFormatted(cell)) { Date dateCellValue = cell.getDateCellValue(); if (dateCellValue != null) { return new SimpleDateFormat().format(dateCellValue); } return ""; } return originalValueDecimalFormat.format(cell.getNumericCellValue()); case Cell.CELL_TYPE_STRING: return cell.getStringCellValue(); case Cell.CELL_TYPE_BOOLEAN: return String.valueOf(cell.getBooleanCellValue()); case Cell.CELL_TYPE_BLANK: return ""; case Cell.CELL_TYPE_ERROR: return String.valueOf(cell.getErrorCellValue()); } return ""; }
From source file:com.vaadin.addon.spreadsheet.command.CellValueCommand.java
License:Open Source License
/** * Returns the current value of the given Cell * /*w ww .j a v a2 s . com*/ * @param cell * Target cell * @return Current value of the cell or null if not available */ protected Object getCellValue(Cell cell) { if (cell == null) { return null; } else { switch (cell.getCellType()) { case Cell.CELL_TYPE_BOOLEAN: return cell.getBooleanCellValue(); case Cell.CELL_TYPE_ERROR: return cell.getErrorCellValue(); case Cell.CELL_TYPE_FORMULA: return "=" + cell.getCellFormula(); case Cell.CELL_TYPE_NUMERIC: return cell.getNumericCellValue(); case Cell.CELL_TYPE_STRING: return cell.getStringCellValue(); default: return null; } } }
From source file:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java
License:Apache License
/** * Adds the values from excel.// www . j a v a 2s . com * * @param path * the path * @param index * the index * @return the string[][] * @throws IOException * Signals that an I/O exception has occurred. * @throws InvalidFormatException * the invalid format exception */ public final String[][] addValuesFromExcel(final String path, final String index) throws IOException, InvalidFormatException { String cellStringValue = null; double cellDoubleValue = 0; Boolean cellBooleanValue; byte cellErrorValue = 0; String[][] arrExcelContent; FileInputStream file = null; Workbook workbook = null; Sheet sheet = null; try { file = new FileInputStream(new File(path)); workbook = WorkbookFactory.create(file); sheet = workbook.getSheetAt(Integer.parseInt(index)); Iterator<Row> rowIterator = sheet.iterator(); arrExcelContent = new String[sheet.getPhysicalNumberOfRows()][]; while (rowIterator.hasNext()) { Row row = rowIterator.next(); int rowNumber = row.getRowNum(); Iterator<Cell> cellIterator = row.cellIterator(); arrExcelContent[rowNumber] = new String[sheet.getRow(rowNumber).getPhysicalNumberOfCells()]; while (cellIterator.hasNext()) { Cell cell = cellIterator.next(); int cellNumber = cell.getColumnIndex(); if (cell.getCellType() == Cell.CELL_TYPE_STRING) { cellStringValue = cell.getStringCellValue(); arrExcelContent[rowNumber][cellNumber] = cellStringValue; } else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) { cellBooleanValue = cell.getBooleanCellValue(); arrExcelContent[rowNumber][cellNumber] = cellBooleanValue.toString(); } else if (cell.getCellType() == Cell.CELL_TYPE_ERROR) { cellErrorValue = cell.getErrorCellValue(); arrExcelContent[rowNumber][cellNumber] = Byte.toString(cellErrorValue); } else if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) { cellStringValue = cell.getCellFormula(); arrExcelContent[rowNumber][cellNumber] = cellStringValue; } else { cellDoubleValue = cell.getNumericCellValue(); arrExcelContent[rowNumber][cellNumber] = Double.toString(cellDoubleValue); } } } } finally { if (((InputStream) workbook) != null) { ((InputStream) workbook).close(); } } return arrExcelContent; }
From source file:com.xl.main.ReadExcelSampleSilk.java
public static String read(String filename) { Gson gson = new Gson(); Map<String, List<SampleSinkBean>> values = new HashMap<String, List<SampleSinkBean>>(); List<SampleSinkBean> byRow = new ArrayList<SampleSinkBean>(); try {//w ww .j av a 2 s. c om FileInputStream file = null; if (filename == null) { file = new FileInputStream(new File("H:\\anil\\sample-sink.xlsx")); } else { file = new FileInputStream(new File(filename)); } //Create Workbook instance holding reference to .xlsx file XSSFWorkbook workbook = new XSSFWorkbook(file); //Get first/desired sheet from the workbook XSSFSheet sheet = workbook.getSheetAt(0); //Iterate through each rows one by one Iterator<Row> rowIterator = sheet.iterator(); while (rowIterator.hasNext()) { Row row = rowIterator.next(); //For each row, iterate through all the columns Iterator<Cell> cellIterator = row.cellIterator(); if (row.getRowNum() > 0 && row.getRowNum() < 20) { SampleSinkBean sb = new SampleSinkBean(); //System.out.println("row value" + sheet.getRow(3).getCell(3)); while (cellIterator.hasNext()) {// Cell cell = cellIterator.next(); String cellString = " "; switch (cell.getCellType()) { case Cell.CELL_TYPE_NUMERIC: cellString = cell.getNumericCellValue() + ""; break; case Cell.CELL_TYPE_FORMULA: cellString = cell.getStringCellValue() + ""; break; case Cell.CELL_TYPE_ERROR: cellString = cell.getErrorCellValue() + ""; break; default: cellString = cell.getStringCellValue() + ""; } switch (cell.getColumnIndex()) { case 0: sb.setFrYear(cellString); break; case 1: sb.setVpmod(cellString); case 2: sb.setProjectName(cellString); case 3: sb.setProjectWorktype(cellString); case 4: sb.setBusinessObjective(cellString); } } byRow.add(sb); } // System.out.println(""); } values.put("sink", byRow); System.out.println("output *********" + gson.toJson(values)); file.close(); } catch (Exception e) { e.printStackTrace(); } return gson.toJson(values); }
From source file:csv.impl.ExcelReader.java
License:Open Source License
/** * Returns the value of the specified cell. * If the cell contained//from w ww.j a va 2 s . co m * a formula, the formula is evaluated before returning the row. * @param cell cell object * @return value of cell */ public Object getValue(Cell cell) { if (cell == null) return null; int cellType = cell.getCellType(); if (cellType == Cell.CELL_TYPE_FORMULA && !isEvaluateFormulas()) { cellType = cell.getCachedFormulaResultType(); } switch (cellType) { case Cell.CELL_TYPE_STRING: return cell.getStringCellValue(); case Cell.CELL_TYPE_NUMERIC: if (DateUtil.isCellDateFormatted(cell)) { return cell.getDateCellValue(); } else { return cell.getNumericCellValue(); } case Cell.CELL_TYPE_BLANK: return null; case Cell.CELL_TYPE_BOOLEAN: return cell.getBooleanCellValue(); case Cell.CELL_TYPE_FORMULA: return evaluateCellValue(cell); case Cell.CELL_TYPE_ERROR: return cell.getErrorCellValue(); } return null; }
From source file:de.jlo.talendcomp.excel.SpreadsheetReferencedCellInput.java
License:Apache License
private boolean fetchCurrentCellValue(Cell cell) { if (cell != null) { currentCell = cell;// w w w . j a v a 2 s .c o m currentCellValueString = getStringCellValue(cell); Comment comment = cell.getCellComment(); if (comment != null) { currentCellComment = comment.getString().getString(); currentCellCommentAuthor = comment.getAuthor(); } CellType cellType = cell.getCellTypeEnum(); if (cellType == CellType.BLANK) { currentCellValueClassName = "Object"; } else if (cellType == CellType.STRING) { currentCellValueClassName = "String"; currentCellValueObject = currentCellValueString; } else if (cellType == CellType.BOOLEAN) { currentCellValueClassName = "Boolean"; currentCellValueBool = cell.getBooleanCellValue(); currentCellValueObject = currentCellValueBool; } else if (cellType == CellType.ERROR) { currentCellValueClassName = "Byte"; currentCellValueObject = cell.getErrorCellValue(); } else if (cellType == CellType.FORMULA) { currentCellValueClassName = "String"; currentCellFormula = cell.getCellFormula(); currentCellValueString = getDataFormatter().formatCellValue(cell, getFormulaEvaluator()); currentCellValueObject = currentCellValueString; } else if (cellType == CellType.NUMERIC) { if (DateUtil.isCellDateFormatted(cell)) { currentCellValueClassName = "java.util.Date"; currentCellValueDate = cell.getDateCellValue(); currentCellValueObject = currentCellValueDate; } else { currentCellValueClassName = "Double"; currentCellValueNumber = cell.getNumericCellValue(); currentCellValueObject = currentCellValueNumber; } } currentCellBgColor = getBgColor(cell); currentCellFgColor = getFgColor(cell); return currentCellValueObject != null; } else { return false; } }