Summary: | XSSFCellStyle.cloneStyleFrom(...) failed, and always throw exception. | ||
---|---|---|---|
Product: | POI | Reporter: | Matthew <matthew.knl> |
Component: | XSSF | Assignee: | POI Developers List <dev> |
Status: | RESOLVED FIXED | ||
Severity: | normal | ||
Priority: | P2 | ||
Version: | 3.5-dev | ||
Target Milestone: | --- | ||
Hardware: | PC | ||
OS: | Windows XP | ||
Attachments: | CloneCellStyleFail.xlsx |
I ran into this too. Looking at the source code for XSSFCellStyle, the method appears to be implemented as follows: public void cloneStyleFrom(CellStyle source) { if(source instanceof XSSFCellStyle) { this.cloneStyleFrom(source); } throw new IllegalArgumentException("Can only clone from one XSSFCellStyle to another, not between HSSFCellStyle and XSSFCellStyle"); } This causes an endless loop that in turn causes a stack overflow error. Looking at HSSFCellStyle, it looks like it should be casting it to XXSFCellStyle and passing it to a method "public void cloneStyleFrom(XSSFCellStyle source)" to do the actual copy. It looks like that method hasn't been implemented. I'm not sure if that's an oversight or if XSSFCellStyle copying is difficult to implement for some reason. If XSSFCellStyle copying can't be easily implemented for the next beta, I'd suggest that at the very least an UnsupportedOperationException or similar be thrown instead of going into an endless loop. |
Created attachment 23460 [details] CloneCellStyleFail.xlsx I run following codes want to copy cell styles from one workbook to other. But when I calling XSSFCellStyle.cloneStyleFrom(...), it failed and always throw exception. -- XSSFWorkbook source = new XSSFWorkbook("CloneCellStyleFail.xlsx"); XSSFWorkbook target = new XSSFWorkbook("target.xlsx"); for(short i=0; i<source.getNumCellStyles(); i++) { XSSFCellStyle cs = target.createCellStyle(); cs.cloneStyleFrom(source.getCellStyleAt(i)); } -- A sample workbook is attached for your testing.