public void copyValue(Cell destCell) { switch (_cellType) { case BLANK: destCell.setCellType(CellType.BLANK); return; case NUMERIC: destCell.setCellValue(_numberValue); return; case BOOLEAN: destCell.setCellValue(_booleanValue); return; case STRING: destCell.setCellValue(_stringValue); return; case ERROR: destCell.setCellErrorValue((byte)_errorValue); return; default: throw new IllegalStateException("Unexpected data type (" + _cellType + ")"); } }
protected void setCellValue(Cell cell, CellValue cv) { CellType cellType = cv.getCellType(); switch (cellType) { case BOOLEAN: cell.setCellValue(cv.getBooleanValue()); break; case ERROR: cell.setCellErrorValue(cv.getErrorValue()); break; case NUMERIC: cell.setCellValue(cv.getNumberValue()); break; case STRING: cell.setCellValue(createRichTextString(cv.getStringValue())); break; case BLANK: // never happens - blanks eventually get translated to zero case FORMULA: // this will never happen, we have already evaluated the formula default: throw new IllegalStateException("Unexpected cell value type (" + cellType + ")"); } }
break; case ERROR: destCell.setCellErrorValue(srcCell.getErrorCellValue()); break; case FORMULA:
public void copyValue(Cell destCell) { switch (_cellType) { case Cell.CELL_TYPE_BLANK: destCell.setCellType(Cell.CELL_TYPE_BLANK); return; case Cell.CELL_TYPE_NUMERIC: destCell.setCellValue(_numberValue); return; case Cell.CELL_TYPE_BOOLEAN: destCell.setCellValue(_booleanValue); return; case Cell.CELL_TYPE_STRING: destCell.setCellValue(_stringValue); return; case Cell.CELL_TYPE_ERROR: destCell.setCellErrorValue((byte)_errorValue); return; } throw new IllegalStateException("Unexpected data type (" + _cellType + ")"); }
public void copyValue(Cell destCell) { switch (_cellType) { case Cell.CELL_TYPE_BLANK: destCell.setCellType(Cell.CELL_TYPE_BLANK); return; case Cell.CELL_TYPE_NUMERIC: destCell.setCellValue(_numberValue); return; case Cell.CELL_TYPE_BOOLEAN: destCell.setCellValue(_booleanValue); return; case Cell.CELL_TYPE_STRING: destCell.setCellValue(_stringValue); return; case Cell.CELL_TYPE_ERROR: destCell.setCellErrorValue((byte)_errorValue); return; } throw new IllegalStateException("Unexpected data type (" + _cellType + ")"); }
public void copyValue(Cell destCell) { switch (_cellType) { case BLANK: destCell.setCellType(CellType.BLANK); return; case NUMERIC: destCell.setCellValue(_numberValue); return; case BOOLEAN: destCell.setCellValue(_booleanValue); return; case STRING: destCell.setCellValue(_stringValue); return; case ERROR: destCell.setCellErrorValue((byte)_errorValue); return; default: throw new IllegalStateException("Unexpected data type (" + _cellType + ")"); } }
@Override public void update(org.apache.poi.ss.usermodel.Cell cell, Workbook workbook) { this.getStyle().applyTo(cell, workbook); cell.setCellErrorValue(errorCode); }
private static void setCellValue(Cell cell, CellValue cv) { int cellType = cv.getCellType(); switch (cellType) { case HSSFCell.CELL_TYPE_BOOLEAN: cell.setCellValue(cv.getBooleanValue()); break; case HSSFCell.CELL_TYPE_ERROR: cell.setCellErrorValue(cv.getErrorValue()); break; case HSSFCell.CELL_TYPE_NUMERIC: cell.setCellValue(cv.getNumberValue()); break; case HSSFCell.CELL_TYPE_STRING: cell.setCellValue(new HSSFRichTextString(cv.getStringValue())); break; case HSSFCell.CELL_TYPE_BLANK: // never happens - blanks eventually get translated to zero case HSSFCell.CELL_TYPE_FORMULA: // this will never happen, we have already evaluated the formula default: throw new IllegalStateException("Unexpected cell value type (" + cellType + ")"); } }
private static void setCellValue(Cell cell, CellValue cv) { int cellType = cv.getCellType(); switch (cellType) { case HSSFCell.CELL_TYPE_BOOLEAN: cell.setCellValue(cv.getBooleanValue()); break; case HSSFCell.CELL_TYPE_ERROR: cell.setCellErrorValue(cv.getErrorValue()); break; case HSSFCell.CELL_TYPE_NUMERIC: cell.setCellValue(cv.getNumberValue()); break; case HSSFCell.CELL_TYPE_STRING: cell.setCellValue(new HSSFRichTextString(cv.getStringValue())); break; case HSSFCell.CELL_TYPE_BLANK: // never happens - blanks eventually get translated to zero case HSSFCell.CELL_TYPE_FORMULA: // this will never happen, we have already evaluated the formula default: throw new IllegalStateException("Unexpected cell value type (" + cellType + ")"); } }
private static void setCellValue(Cell cell, CellValue cv) { int cellType = cv.getCellType(); switch (cellType) { case XSSFCell.CELL_TYPE_BOOLEAN: cell.setCellValue(cv.getBooleanValue()); break; case XSSFCell.CELL_TYPE_ERROR: cell.setCellErrorValue(cv.getErrorValue()); break; case XSSFCell.CELL_TYPE_NUMERIC: cell.setCellValue(cv.getNumberValue()); break; case XSSFCell.CELL_TYPE_STRING: cell.setCellValue(new XSSFRichTextString(cv.getStringValue())); break; case XSSFCell.CELL_TYPE_BLANK: // never happens - blanks eventually get translated to zero case XSSFCell.CELL_TYPE_FORMULA: // this will never happen, we have already evaluated the formula default: throw new IllegalStateException("Unexpected cell value type (" + cellType + ")"); } }
protected void setCellValue(Cell cell, CellValue cv) { CellType cellType = cv.getCellType(); switch (cellType) { case BOOLEAN: cell.setCellValue(cv.getBooleanValue()); break; case ERROR: cell.setCellErrorValue(cv.getErrorValue()); break; case NUMERIC: cell.setCellValue(cv.getNumberValue()); break; case STRING: cell.setCellValue(createRichTextString(cv.getStringValue())); break; case BLANK: // never happens - blanks eventually get translated to zero case FORMULA: // this will never happen, we have already evaluated the formula default: throw new IllegalStateException("Unexpected cell value type (" + cellType + ")"); } }
private static void setCellDataValue(Cell oldCell, Cell newCell) { 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; } }
private static void moveCell(org.apache.poi.ss.usermodel.Cell srcCell, org.apache.poi.ss.usermodel.Cell destCell) { destCell.setCellStyle(srcCell.getCellStyle()); switch (srcCell.getCellType()) { case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_STRING: destCell.setCellValue(srcCell.getRichStringCellValue()); break; case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC: destCell.setCellValue(srcCell.getNumericCellValue()); break; case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_BLANK: destCell.setCellType(org.apache.poi.ss.usermodel.Cell.CELL_TYPE_BLANK); break; case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_BOOLEAN: destCell.setCellValue(srcCell.getBooleanCellValue()); break; case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_ERROR: destCell.setCellErrorValue(srcCell.getErrorCellValue()); break; case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_FORMULA: break; default: break; } srcCell.setCellType(org.apache.poi.ss.usermodel.Cell.CELL_TYPE_BLANK); }
private static void moveCell(org.apache.poi.ss.usermodel.Cell srcCell, org.apache.poi.ss.usermodel.Cell destCell) { destCell.setCellStyle(srcCell.getCellStyle()); switch (srcCell.getCellType()) { case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_STRING: destCell.setCellValue(srcCell.getRichStringCellValue()); break; case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC: destCell.setCellValue(srcCell.getNumericCellValue()); break; case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_BLANK: destCell.setCellType(org.apache.poi.ss.usermodel.Cell.CELL_TYPE_BLANK); break; case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_BOOLEAN: destCell.setCellValue(srcCell.getBooleanCellValue()); break; case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_ERROR: destCell.setCellErrorValue(srcCell.getErrorCellValue()); break; case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_FORMULA: break; default: break; } srcCell.setCellType(org.apache.poi.ss.usermodel.Cell.CELL_TYPE_BLANK); }
public static void copyCell(org.apache.poi.ss.usermodel.Cell oldCell, org.apache.poi.ss.usermodel.Cell newCell, boolean copyStyle) { if (copyStyle) { newCell.setCellStyle(oldCell.getCellStyle()); } switch (oldCell.getCellType()) { case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_STRING: newCell.setCellValue(oldCell.getRichStringCellValue()); break; case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC: newCell.setCellValue(oldCell.getNumericCellValue()); break; case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_BLANK: newCell.setCellType(org.apache.poi.ss.usermodel.Cell.CELL_TYPE_BLANK); break; case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_BOOLEAN: newCell.setCellValue(oldCell.getBooleanCellValue()); break; case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_ERROR: newCell.setCellErrorValue(oldCell.getErrorCellValue()); break; case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_FORMULA: newCell.setCellFormula(oldCell.getCellFormula()); break; default: break; } }
public static void copyCell(org.apache.poi.ss.usermodel.Cell oldCell, org.apache.poi.ss.usermodel.Cell newCell, boolean copyStyle) { if (copyStyle) { newCell.setCellStyle(oldCell.getCellStyle()); copyConditionalFormat(oldCell, newCell); } switch (oldCell.getCellType()) { case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_STRING: newCell.setCellValue(oldCell.getRichStringCellValue()); break; case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC: newCell.setCellValue(oldCell.getNumericCellValue()); break; case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_BLANK: newCell.setCellType(org.apache.poi.ss.usermodel.Cell.CELL_TYPE_BLANK); break; case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_BOOLEAN: newCell.setCellValue(oldCell.getBooleanCellValue()); break; case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_ERROR: newCell.setCellErrorValue(oldCell.getErrorCellValue()); break; case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_FORMULA: newCell.setCellFormula(oldCell.getCellFormula()); break; default: break; } }
public static void copyCell(Cell srcCell, Cell distCell){ distCell.setCellStyle(srcCell.getCellStyle()); if(srcCell.getCellComment() != null) { distCell.setCellComment(srcCell.getCellComment()); } 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 } }
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());
break; case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_ERROR: newCell.setCellErrorValue(oldCell.getErrorCellValue()); break; case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_FORMULA:
public static void copyCell(Cell src, Cell target, boolean copyValue) { if (src == null || target == null) { return; } // 复制样式 target.setCellStyle(src.getCellStyle()); // 单元格类型 int cellType = src.getCellType(); target.setCellType(cellType); if (cellType == Cell.CELL_TYPE_FORMULA) { // 公式 target.setCellFormula(src.getCellFormula()); } else if (copyValue) { // 复制内容 if (cellType == Cell.CELL_TYPE_ERROR) { // 错误 target.setCellErrorValue(src.getErrorCellValue()); } else { Object value = getCellValue(src); setCellValue(target, value); } // 评论 Comment comment = src.getCellComment(); if (comment == null) { target.removeCellComment(); } else { target.setCellComment(comment); } } }