Bug 47582

Summary: XSSFCellStyle.cloneStyleFrom not replicating all the style attributes
Product: POI Reporter: David Agnew <prescindor>
Component: XSSFAssignee: POI Developers List <dev>
Severity: normal    
Priority: P2    
Version: 3.5-dev   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X 10.4   

Description David Agnew 2009-07-25 21:34:45 UTC
XSSFCellStyle.cloneStyleFrom fails to reproduce the data format and the font and possibly other style attributes.

To copy the data format, you need to get the data format string from the source style and use an XSSFDataFormat instance to obtain a data format index valid in the target style's workbook. Similar legerdemain is required to handle the font. You have to ask the target style's workbook if it has a font with the same properties as the source style's font and create a new one if it doesn't.

I didn't investigate cloneStyleFrom's performance with respect to the full range of attributes, as I adopted a different approach to my problem, which does not to clone styles across workbooks.
Comment 1 radek.mensik 2010-09-14 04:18:01 UTC
If there are two workbooks then
XSSFCellStyle.cloneStyleFrom has problem with keys (of fonts...), which are copied from one workbook to other and thus even if there the font has id 5 in source workbook it is copied with this id to targetworkbook where is only one font =(max id is 0). Just try to run your test
public void testCloneStyleDiffWB() { ..} for XSSF
Comment 2 Nick Burch 2010-09-20 16:10:53 UTC
Support added in r999096, along with a unit test based on the HSSF one that shows we do copy things across