Bug 57517

Summary: [PATCH] Wrong result when calling HSSFOptimiser.optimiseCellStyles on workbook that uses user defined styles
Product: POI Reporter: Akira Shiratsuki <p50p100>
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: major CC: p50p100
Priority: P2 Keywords: APIBug, PatchAvailable
Version: 3.11-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: Renumber parent indexes and Synchronized StyleRecord with ExFormats.
Renumber parent indexes and Synchronized StyleRecord with ExFormats. I modified it morely. ColumnStyle RowStyle only used cell style is preserved.
I modified my regression bug.
Synchoronized XF Record with style record. Adjust parent index of XF Record for deleted record. Don't delete style record. It's bultin style or user style. And start off from index(16) of style XF record. Delete unused duplicated style at one time.
test case
input file
bad output file
Test case
Input file. (Test case write this file. Before calling HSSFOptimiser.optimiseCellStyles .)
Correct result file. (Test case write this file. After calling HSSFOptimiser.optimiseCellStyles .)
Bad result file. (Test case write this file. After calling HSSFOptimiser.optimiseCellStyles .)

Description Akira Shiratsuki 2015-01-31 00:41:16 UTC
I called HSSFOptimiser for workbook.
The workbook has user defined styles.

The result is wrong.
Because parent style index is miss matching.
And user defined style is miss matching.

This arise when user defined style and hidden styel is mixing.
Comment 1 Akira Shiratsuki 2015-01-31 00:43:45 UTC
I called HSSFOptimiser.optimiseCellStyles for workbook.
The workbook has user defined styles.

The result is wrong.
Because parent style index is miss matching.
And user defined style is miss matching.

This arise when user defined style and hidden styel is mixing.
Comment 2 Akira Shiratsuki 2015-01-31 01:31:39 UTC
Created attachment 32415 [details]
Renumber parent indexes and Synchronized StyleRecord with ExFormats.
Comment 3 Akira Shiratsuki 2015-01-31 09:06:24 UTC
Created attachment 32416 [details]
Renumber parent indexes and Synchronized StyleRecord with ExFormats.
I modified it morely. ColumnStyle RowStyle only used cell style is preserved.
Comment 4 Akira Shiratsuki 2015-01-31 09:17:25 UTC
http://apache-poi.1045710.n5.nabble.com/Bug-with-HSSFOptimiser-cellStyles-td5711520.html

There is same case I distiguished.
Comment 5 Akira Shiratsuki 2015-02-12 22:24:47 UTC
Created attachment 32466 [details]
I modified my regression bug.
Comment 6 Akira Shiratsuki 2015-02-14 15:59:54 UTC
Created attachment 32474 [details]
Synchoronized XF Record with style record.
Adjust parent index of XF Record for deleted record.
Don't delete style record. It's bultin style or user style. And start off from index(16) of style XF record.
Delete unused duplicated style at one time.
Comment 7 Akira Shiratsuki 2015-02-14 16:03:27 UTC
Created attachment 32475 [details]
test case
Comment 8 Akira Shiratsuki 2015-02-14 16:10:58 UTC
Created attachment 32476 [details]
input file
Comment 9 Akira Shiratsuki 2015-02-14 16:11:40 UTC
Created attachment 32477 [details]
bad output file
Comment 10 Akira Shiratsuki 2015-02-15 00:50:18 UTC
Created attachment 32478 [details]
Test case
Comment 11 Akira Shiratsuki 2015-02-15 00:51:58 UTC
Created attachment 32479 [details]
Input file. (Test case write this file. Before calling HSSFOptimiser.optimiseCellStyles .)
Comment 12 Akira Shiratsuki 2015-02-15 00:53:16 UTC
Created attachment 32480 [details]
Correct result file. (Test case write this file. After calling HSSFOptimiser.optimiseCellStyles .)
Comment 13 Akira Shiratsuki 2015-02-15 00:55:20 UTC
Created attachment 32481 [details]
Bad result file. (Test case write this file. After calling HSSFOptimiser.optimiseCellStyles .)
Comment 14 Dominik Stadler 2017-11-05 20:34:41 UTC
Thanks for the suggested patch. 

The optimise-method had some more shortcomings which became apparent when separating the many different things from the test-case into smaller, more narrowed-down test-cases.

I re-did the changes in a somewhat different way, trying to handle some more cases/situations correctly.

All the things detected by the given tests should be fixed now via r1814373, please report additional bugs for anything that is still not working fine now.