List of usage examples for org.apache.poi.ss.usermodel Cell setCellErrorValue
void setCellErrorValue(byte value);
From source file:bad.robot.excel.cell.ErrorCell.java
License:Apache License
@Override public void update(org.apache.poi.ss.usermodel.Cell cell, Workbook workbook) { this.getStyle().applyTo(cell, workbook); cell.setCellErrorValue(errorCode); }
From source file:bad.robot.excel.matchers.StubCell.java
License:Apache License
static Cell createCell(int row, int column, Byte value) { Cell cell = create(row, column, CELL_TYPE_ERROR); cell.setCellErrorValue(value); return cell;/*from ww w . ja va2s . c om*/ }
From source file:bad.robot.excel.row.CopyRow.java
License:Apache License
private static void setCellDataValue(Cell oldCell, Cell newCell) { switch (oldCell.getCellType()) { case Cell.CELL_TYPE_BLANK: newCell.setCellValue(oldCell.getStringCellValue()); break;// ww w. j a v a2 s . c om 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; } }
From source file:com.dataart.spreadsheetanalytics.engine.ConverterUtils.java
License:Apache License
/** Inserts a value to a Cell based on a value type (class). */ static void populateCellValue(final Cell cell, final ICellValue value) { if (cell == null) { return;//w w w. j a v a2 s . c o m } int cellType = resolveCellType(value); cell.setCellType(cellType); switch (cellType) { case CELL_TYPE_BLANK: { break; } case CELL_TYPE_BOOLEAN: { cell.setCellValue((Boolean) value.get()); break; } case CELL_TYPE_NUMERIC: { cell.setCellValue((Double) value.get()); break; } case CELL_TYPE_FORMULA: { try { cell.setCellFormula(((String) value.get()).substring(1)); break; } catch (FormulaParseNameException e) { log.error("Formula parsing error while trying to set formula field in cell " + e.getMessage()); cell.setCellFormula(ErrorEval.NAME_INVALID.getErrorString()); break; } catch (FormulaParseNAException e) { log.error("Formula parsing error while trying to set formula field in cell " + e.getMessage()); cell.setCellFormula(ErrorEval.NA.getErrorString()); break; } } case CELL_TYPE_ERROR: { cell.setCellErrorValue(FormulaError.forString((String) value.get()).getCode()); break; } case CELL_TYPE_STRING: { cell.setCellValue((String) value.get()); break; } default: { throw new CalculationEngineException(String.format("Type of value %s is not supported: %s", value, value.getClass().getSimpleName())); } } }
From source file:com.dituiba.excel.ExcelUtility.java
License:Apache License
public static void copyCell(Cell srcCell, Cell distCell) { distCell.setCellStyle(srcCell.getCellStyle()); if (srcCell.getCellComment() != null) { distCell.setCellComment(srcCell.getCellComment()); }// w w w .ja v a 2s . c om int srcCellType = srcCell.getCellType(); distCell.setCellType(srcCellType); if (srcCellType == Cell.CELL_TYPE_NUMERIC) { if (DateUtil.isCellDateFormatted(srcCell)) { distCell.setCellValue(srcCell.getDateCellValue()); } else { distCell.setCellValue(srcCell.getNumericCellValue()); } } else if (srcCellType == Cell.CELL_TYPE_STRING) { distCell.setCellValue(srcCell.getRichStringCellValue()); } else if (srcCellType == Cell.CELL_TYPE_BLANK) { //nothing } else if (srcCellType == Cell.CELL_TYPE_BOOLEAN) { distCell.setCellValue(srcCell.getBooleanCellValue()); } else if (srcCellType == Cell.CELL_TYPE_ERROR) { distCell.setCellErrorValue(srcCell.getErrorCellValue()); } else if (srcCellType == Cell.CELL_TYPE_FORMULA) { distCell.setCellFormula(srcCell.getCellFormula()); } else { //nothing } }
From source file:com.github.camaral.sheeco.exceptions.OriginalCellValue.java
License:Apache License
public void setCellValue(final Cell cell) { switch (type) { case DATE://from w w w. j ava 2 s . c om cell.setCellValue((Date) value); break; case NUMERIC: cell.setCellValue(((Number) value).doubleValue()); break; case BOOLEAN: cell.setCellValue((Boolean) value); break; case STRING: cell.setCellValue(String.valueOf(value)); break; case ERROR: cell.setCellErrorValue((Byte) value); break; case FORMULA: cell.setCellFormula((String) value); break; default: } }
From source file:com.kybelksties.excel.ExcelSheetTableModel.java
License:Open Source License
/** * Insert a row at a given index.//from ww w . j a v a 2s . c o m * * @param createAtIndex row-number of the cell at which to create a new row * @param sourceRow the row to insert */ public void insertRowAt(int createAtIndex, Row sourceRow) { Row newRow = getRow(createAtIndex); if (newRow != null) { // shift all rows >= createAtIndex up by one getSheet().shiftRows(createAtIndex, getSheet().getLastRowNum(), 1); } else { newRow = getSheet().createRow(createAtIndex); } // Loop through source columns to add to new row for (int i = 0; i < sourceRow.getLastCellNum(); i++) { // Grab a copy of the old/new cell Cell oldCell = sourceRow.getCell(i); Cell newCell = newRow.createCell(i); // If the old cell is null jump to next cell if (oldCell == null) { continue; } // Copy style from old cell and apply to new cell CellStyle newCellStyle = workbook.createCellStyle(); newCellStyle.cloneStyleFrom(oldCell.getCellStyle()); newCell.setCellStyle(newCellStyle); // If there is a cell comment, copy if (oldCell.getCellComment() != null) { newCell.setCellComment(oldCell.getCellComment()); } // If there is a cell hyperlink, copy if (oldCell.getHyperlink() != null) { newCell.setHyperlink(oldCell.getHyperlink()); } // Set the cell data type newCell.setCellType(oldCell.getCellType()); // Set the cell data value 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; } } // If there are are any merged regions in the source row, copy to new row for (int i = 0; i < getSheet().getNumMergedRegions(); i++) { CellRangeAddress cellRangeAddress = getSheet().getMergedRegion(i); if (cellRangeAddress.getFirstRow() == sourceRow.getRowNum()) { CellRangeAddress newCellRangeAddress = new CellRangeAddress(newRow.getRowNum(), (newRow.getRowNum() + (cellRangeAddress.getLastRow() - cellRangeAddress.getFirstRow())), cellRangeAddress.getFirstColumn(), cellRangeAddress.getLastColumn()); getSheet().addMergedRegion(newCellRangeAddress); } } }
From source file:com.mimp.controllers.reporte.java
private static void copyRow(Sheet worksheet, int sourceRowNum, int destinationRowNum) { // Coge la fila antigua y nueva Row newRow = worksheet.getRow(destinationRowNum); Row sourceRow = worksheet.getRow(sourceRowNum); //Si existe una fila en el detino, pasa todas las filas 1 ms abajo antes de crear la nueva columna if (newRow != null) { worksheet.shiftRows(destinationRowNum, worksheet.getLastRowNum(), 1); } else {/* w w w . j ava2 s .co m*/ newRow = worksheet.createRow(destinationRowNum); } // Hace un loop entre las celdas de cada columna para aadir una por una a la nueva for (int i = 0; i < sourceRow.getLastCellNum(); i++) { // Copia la antigua y nueva celda Cell oldCell = sourceRow.getCell(i); Cell newCell = newRow.createCell(i); // Si la anterior celda es null, evalua la siguiente celda defrente if (oldCell == null) { newCell = null; continue; } // Usa el estilo de la celda antigua newCell.setCellStyle(oldCell.getCellStyle()); // Establece el tipo de valor de la celda newCell.setCellType(oldCell.getCellType()); // Establece el valor de la celda switch (oldCell.getCellType()) { case Cell.CELL_TYPE_BLANK: 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; } } }
From source file:com.miraisolutions.xlconnect.Workbook.java
License:Open Source License
private void writeData(DataFrame data, Sheet sheet, int startRow, int startCol, boolean header) { // Get styles Map<String, CellStyle> styles = getStyles(data, sheet, startRow, startCol); // Define row & column index variables int rowIndex = startRow; int colIndex = startCol; // In case of column headers ... if (header && data.hasColumnHeader()) { // For each column write corresponding column name for (int i = 0; i < data.columns(); i++) { Cell cell = getCell(sheet, rowIndex, colIndex + i); cell.setCellValue(data.getColumnName(i)); cell.setCellType(Cell.CELL_TYPE_STRING); setCellStyle(cell, styles.get(HEADER + i)); }//from w ww .j av a2s.c om ++rowIndex; } // For each column of data for (int i = 0; i < data.columns(); i++) { // Get column style CellStyle cs = styles.get(COLUMN + i); Column col = data.getColumn(i); // Depending on column type ... switch (data.getColumnType(i)) { case Numeric: double[] doubleValues = col.getNumericData(); for (int j = 0; j < data.rows(); j++) { Cell cell = getCell(sheet, rowIndex + j, colIndex); if (col.isMissing(j)) setMissing(cell); else { if (Double.isInfinite(doubleValues[j])) { cell.setCellType(Cell.CELL_TYPE_ERROR); cell.setCellErrorValue(FormulaError.NA.getCode()); } else { cell.setCellValue(doubleValues[j]); cell.setCellType(Cell.CELL_TYPE_NUMERIC); } setCellStyle(cell, cs); } } break; case String: String[] stringValues = col.getStringData(); for (int j = 0; j < data.rows(); j++) { Cell cell = getCell(sheet, rowIndex + j, colIndex); if (col.isMissing(j)) setMissing(cell); else { cell.setCellValue(stringValues[j]); cell.setCellType(Cell.CELL_TYPE_STRING); setCellStyle(cell, cs); } } break; case Boolean: boolean[] booleanValues = col.getBooleanData(); for (int j = 0; j < data.rows(); j++) { Cell cell = getCell(sheet, rowIndex + j, colIndex); if (col.isMissing(j)) setMissing(cell); else { cell.setCellValue(booleanValues[j]); cell.setCellType(Cell.CELL_TYPE_BOOLEAN); setCellStyle(cell, cs); } } break; case DateTime: Date[] dateValues = col.getDateTimeData(); for (int j = 0; j < data.rows(); j++) { Cell cell = getCell(sheet, rowIndex + j, colIndex); if (col.isMissing(j)) setMissing(cell); else { cell.setCellValue(dateValues[j]); cell.setCellType(Cell.CELL_TYPE_NUMERIC); setCellStyle(cell, cs); } } break; default: throw new IllegalArgumentException("Unknown column type detected!"); } ++colIndex; } // Force formula recalculation for HSSFSheet if (isHSSF()) { ((HSSFSheet) sheet).setForceFormulaRecalculation(true); } }
From source file:com.plugin.excel.util.ExcelUtil.java
License:Apache License
/** * @param oldCell/*from ww w. j a va 2 s . c om*/ * @param newCell * @param styleMap */ public static void copyCell(Cell oldCell, Cell newCell, Map<Integer, CellStyle> styleMap) { if (styleMap != null) { if (oldCell.getSheet().getWorkbook() == newCell.getSheet().getWorkbook()) { newCell.setCellStyle(oldCell.getCellStyle()); } else { int stHashCode = oldCell.getCellStyle().hashCode(); CellStyle newCellStyle = styleMap.get(stHashCode); if (newCellStyle == null) { newCellStyle = newCell.getSheet().getWorkbook().createCellStyle(); newCellStyle.cloneStyleFrom(oldCell.getCellStyle()); styleMap.put(stHashCode, newCellStyle); } newCell.setCellStyle(newCellStyle); } } switch (oldCell.getCellType()) { case Cell.CELL_TYPE_STRING: newCell.setCellValue(oldCell.getStringCellValue()); break; case Cell.CELL_TYPE_NUMERIC: newCell.setCellValue(oldCell.getNumericCellValue()); break; case Cell.CELL_TYPE_BLANK: newCell.setCellType(Cell.CELL_TYPE_BLANK); 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; default: break; } }