0

Clone Style from a Cell to another -- ZK Spredasheet

asked 2011-03-21 05:45:56 +0800

Gunny gravatar image Gunny
27

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);"

delete flag offensive retag edit
Be the first one to reply this discussion!
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2011-03-21 05:45:56 +0800

Seen: 270 times

Last updated: Mar 21 '11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More