public static void copyCell ( XSSFCell oldCell , XSSFCell 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 XSSFCell . CELL_TYPE_STRING : newCell . setCellValue ( oldCell . getStringCellValue ( ) ) ; break ; case XSSFCell . CELL_TYPE_NUMERIC : newCell . setCellValue ( oldCell . getNumericCellValue ( ) ) ; break ; case XSSFCell . CELL_TYPE_BLANK : newCell . setCellType ( XSSFCell . CELL_TYPE_BLANK ) ; break ; case XSSFCell . CELL_TYPE_BOOLEAN : newCell . setCellValue ( oldCell . getBooleanCellValue ( ) ) ; break ; case XSSFCell . CELL_TYPE_ERROR : newCell . setCellErrorValue ( oldCell . getErrorCellValue ( ) ) ; break ; case XSSFCell . CELL_TYPE_FORMULA : newCell . setCellFormula ( oldCell . getCellFormula ( ) ) ; break ; default : break ; } }
Copy a cell to another cell