Am I correct in assuming that you are approaching this as a two step process? It is not clear from the code you posted, but it seems to me that you cloning the styles as one operation and then attempting to copy the cells and apply the coled styles as a separate operation. If this is the case, then I am forced to ask, why not perform both operations at the same time? In psuedo code, something like this;
Get a cell from the old workbook. Copy that cells contents into a cell you have created in the new workbook. Get the style object applied to the old cell. Check whether or not you have already cloned a similar style object. If you have not, clone the style, and apply the clone to the cell. Then store the reference to the old style object away using one of Java's Collections classes. As styles are shared objects, I think it is safe to assume - although you should test it - that if the same style is applied to two different cells, the reference returned (the style object) for the style will be the same and can simply be compared for equality. This way you do not have to store away the cloned styles and do not need to try and work out which is which when you come to apply styles to the copied cells. I cannot place my finger directly onto the method/class I am looking for at the moment, but seem to remember there is a way to ask POI to take a pass through the workbook once it has been populated and remove any duplicate style objects. Once I find it, I will post here. -- View this message in context: http://apache-poi.1045710.n5.nabble.com/How-do-I-copy-cell-styles-tp5615723p5618145.html Sent from the POI - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
