Bug 60541 - Column collapsed attribute is incorrectly set when reading file
Summary: Column collapsed attribute is incorrectly set when reading file
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.15-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
: 58910 65852 (view as bug list)
Depends on:
Blocks:
 
Reported: 2017-01-02 20:02 UTC by Christian Schroeder
Modified: 2022-12-26 10:00 UTC (History)
2 users (show)



Attachments
Code to reproduce the erroneous behavior (1.77 KB, text/plain)
2017-01-02 20:02 UTC, Christian Schroeder
Details
Proposed patch from comment 0 (728 bytes, patch)
2017-01-03 02:21 UTC, Javen O'Neal
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Christian Schroeder 2017-01-02 20:02:30 UTC
Created attachment 34576 [details]
Code to reproduce the erroneous behavior

When reading an OOXML Excel document from a file, the "collapsed" attribute of any column is always set, even if the attribute was not set in the input file. If the attribute was not present in the input file, it will be set to "false". If the attribute was present in the input file, it will be set to "true", regardless of the actual value of the attribute. By saving and loading the document multiple times, the attribute will eventually have a true value, regardless of its initial state.

Example to reproduce this behavior is attached.

The error occurs in line 259 of org.apache.poi.xssf.usermodel.helpers.ColumnHelper. The existing line:

toCol.setCollapsed(fromCol.isSetCollapsed());

... should either be changed to:

toCol.setCollapsed(fromCol.getCollapsed());

... or removed at all.
Comment 1 Javen O'Neal 2017-01-03 02:21:46 UTC
Created attachment 34580 [details]
Proposed patch from comment 0

It looks like that line was added in r775731 for bug 46161 with the commit message "xssf support for setGroupColumnCollapsed() setGroupRowCollapsed()".

https://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java?annotate=775731&pathrev=775731#l221
> r636729       nick     public void setColumnAttributes(CTCol fromCol, CTCol toCol) {
> r1561435 kiwiwings         if(fromCol.isSetBestFit()) toCol.setBestFit(fromCol.getBestFit());
> ...
> r747895      yegor         if(fromCol.isSetCollapsed()) toCol.setCollapsed(fromCol.getCollapsed());
> ...
> r775731       nick         toCol.setCollapsed(fromCol.isSetCollapsed());
> r615258       nick     }

I'm in favor of deleting the unguarded toCol.setCollapsed, but it currently breaks TestXSSFSheet#setColumnGroupCollapsed.
This old unit test appears to have many problems, such as confusing isSetCollapsed with getCollapsed, assuming hidden is the same as collapsed, among many other problems. I am rewriting this unit test before making your changes to avoid regressions.
Comment 2 PJ Fanning 2022-01-27 11:58:43 UTC
*** Bug 65852 has been marked as a duplicate of this bug. ***
Comment 3 PJ Fanning 2022-01-27 21:11:06 UTC
I have https://github.com/apache/poi/pull/300 - still some work to be done on the unit tests
Comment 4 PJ Fanning 2022-02-01 23:06:45 UTC
added some changes using r1897678
Comment 5 Dominik Stadler 2022-12-26 10:00:30 UTC
*** Bug 58910 has been marked as a duplicate of this bug. ***