Bug 47582 - XSSFCellStyle.cloneStyleFrom not replicating all the style attributes
Summary: XSSFCellStyle.cloneStyleFrom not replicating all the style attributes
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.5-dev
Hardware: PC Mac OS X 10.4
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-07-25 21:34 UTC by David Agnew
Modified: 2010-09-20 16:10 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
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