Bug 58788

Summary: Colors are lost in headers in worksheets moving from left to right
Product: POI Reporter: Jim Showalter <jim_showalter>
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED WORKSFORME    
Severity: normal    
Priority: P2    
Version: 3.13-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: Program to reproduce this bug. See instructions for reproducing.

Description Jim Showalter 2016-01-02 23:09:46 UTC
Created attachment 33394 [details]
Program to reproduce this bug. See instructions for reproducing.

The same code used for all worksheets produces different results. The first few worksheets look fine but gradually colors drop off until there are no colors at all.

To reproduce:

Run the attached program with one command-line arg for the output file name.

In the generated file, click from left to right on the worksheets.

The first two worksheets look fine.

The third worksheet has only one row set to blue, and no row set to yellow.

The remaining worksheets have no color.

Change NUM_COLUMNS from 7 to 3 in the code.

Compile and run again.

Click from left to right on the worksheets.

The first four worksheets look fine.

The fifth worksheet only has yellow on the first column.

The sixth worksheet has no color.

Using poi version 3.13.

Same behavior with 3.12.
Comment 1 Dominik Stadler 2016-01-03 15:13:58 UTC
Styles are per Workbook and should be reused across cells, does it work when you just use two global  styles across the workbook?
Comment 2 Jim Showalter 2016-01-03 17:53:27 UTC
That was it. My mistake. Thank you!

When creating styles for each cell, they're separate objects, so it's odd that they don't wind up with the same effect on each worksheet (is that a bug?).
Comment 3 Jim Showalter 2016-01-03 19:26:25 UTC
That fixed it. Any idea why repeatedly creating cell styles would cause them to stop applying colors as defined? Also, when defining styles to be used globally, the API supports defining a user string for the style, but there's no way to look up a style by string, so the styles have to be passed as additional parameters, or assigned to globals. It would be nice to be able to look up by name.
Comment 4 Dominik Stadler 2016-01-03 19:50:39 UTC
Glad that it helped, I quickly tried it locally on Linux, LibreOffice shows the colors in the resulting file correctly, so it seems to be some strange behaviour with Excel. Anyway I don't see anything that we can fix here so I am closing this for now.