-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi,
I need to clone the CellStyle from a Cell to another in ZK Spreadsheet.
I've created this method:
public static void copyCellStyle(HSSFCell oldCell, HSSFCell newCell, Map<Integer, HSSFCellStyle> styleMap) { if(styleMap != null) { if(oldCell.getSheet().getWorkbook() == newCell.getSheet().getWorkbook()){ newCell.setCellStyle(oldCell.getCellStyle()); } else{ int stHashCode = oldCell.getCellStyle().hashCode(); HSSFCellStyle newHSSFCellStyle = styleMap.get(stHashCode); if(newHSSFCellStyle == null){ newHSSFCellStyle = (HSSFCellStyle) newCell.getSheet().getWorkbook().createCellStyle(); HSSFCellStyle oldHSSFCellStyle = (HSSFCellStyle) oldCell.getCellStyle(); System.out.println("oldCell.getCellStyle(): " + oldCell.getCellStyle()); newHSSFCellStyle.cloneStyleFrom(oldHSSFCellStyle); styleMap.put(stHashCode, newHSSFCellStyle); } newCell.setCellStyle(newHSSFCellStyle); } } }
but i get a nullpointer when i clone style "newHSSFCellStyle.cloneStyleFrom(oldHSSFCellStyle);"
Asked: 2011-03-21 05:45:56 +0800
Seen: 270 times
Last updated: Mar 21 '11