Cell styles are shared between a number of cells so that if you do recover the style from a cell and modify it, you will see that change reflecetd in every cell the style is applied to.
The answer is to do something like the following; 1. Declare a cell style object that will hold a reference to the style you wish to apply to highlight these date cells. 2. Process the sheet until you find a date cell that needs to be modified. 3. Clone the style from that date cell - if you check, there is a cloneStyleFrom(CellStyle) method defined in the CellStyle interface and implemented in both HSSFCellStyle and XSSFCellStyle - and store the reference in the object you created at step one above. 4. Modify the cloned style - in you case change the background colour - and apply it to the date cell you wish to highlight. 5. Continue processing the sheet. Of course, when you come across any other date cells you wish to highlight subsequently, you do not need to clone the style and modify the clone again so add a check for the variable holding the clone being equal to null. Alternatively, you could simply declare and initialise the highliting style right at the top of you code and then simply apply it to a date cell if it needed to be highlighted. The choice between the two techniques is yours and depends upon whether you will find a date cell the needs to be highlighted, how many of these cells you will find, etc. Yours Mark B -- View this message in context: http://apache-poi.1045710.n5.nabble.com/reg-editing-and-upadion-of-cell-background-color-tp3284039p3284279.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]
