Bug 59932 - Incorrect column grouping behavior
Summary: Incorrect column grouping behavior
Status: NEW
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: unspecified
Hardware: All All
: P2 minor (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2016-08-03 02:01 UTC by Javen O'Neal
Modified: 2021-08-18 08:03 UTC (History)
1 user (show)

File to reproduce issue (9.36 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2016-08-03 02:01 UTC, Javen O'Neal
Disabled unit test, currently failing (9.91 KB, application/x-gzip)
2016-08-03 03:20 UTC, Javen O'Neal
File to reproduce maybe the same error (3.68 KB, text/plain)
2017-04-23 21:01 UTC, Roland

Note You need to log in before you can comment on or make changes to this bug.
Description Javen O'Neal 2016-08-03 02:01:38 UTC
Created attachment 34097 [details]
File to reproduce issue

Since r1706789 (POI 3.14 beta 1)

In the attached example, all columns have the same style.

Columns A:C have the same width, and get grouped together with sheet.groupColumns(0, 2). The group is uncollapsed.

For columns E:G, column F has a different width. When grouping these columns, only the first 2 columns are grouped, and the column group is collapsed.

>  <cols>
>    <col min="1" max="5" width="13.42578125" style="1" customWidth="1"/>
>    <col min="6" max="6" width="31.7109375" style="1" customWidth="1"/>
>    <col min="7" max="7" width="13.42578125" style="1" customWidth="1"/>
>  </cols>
Comment 1 Javen O'Neal 2016-08-03 02:29:29 UTC
After executing the following code:
Workbook wb = WorkbookFactory.create(new File("59932.xlsx"));
Sheet sheet = wb.getSheetAt(0);
sheet.groupColumn(0, 2);
sheet.groupColumn(4, 6);
wb.write(new FileOutputStream("59932 after.xlsx"));

This is what POI writes:
>  <cols>
>    <col min="1" max="3" customWidth="true" style="1" width="13.42578125" collapsed="false" outlineLevel="1"/>
>    <col min="4" max="4" customWidth="true" style="1" width="13.42578125" collapsed="true"/>
>    <col min="5" max="5" customWidth="true" style="1" width="13.42578125" collapsed="false" outlineLevel="1"/>
>    <col min="6" max="6" customWidth="true" style="1" width="31.7109375" collapsed="false" outlineLevel="1"/>
>    <col min="6" max="7" collapsed="false" outlineLevel="1"/>
>    <col min="7" max="7" customWidth="true" style="1" width="13.42578125" collapsed="false"/>
>  </cols>

Should be:
>  <cols>
>    <col min="1" max="3" width="13.42578125" style="1" customWidth="1" outlineLevel="1"/>
>    <col min="4" max="4" width="13.42578125" style="1" customWidth="1"/>
>    <col min="5" max="5" width="13.42578125" style="1" customWidth="1" outlineLevel="1"/>
>    <col min="6" max="6" width="31.7109375" style="1" customWidth="1" outlineLevel="1"/>
>    <col min="7" max="7" width="13.42578125" style="1" customWidth="1" outlineLevel="1"/>
>  </cols>
Comment 2 Javen O'Neal 2016-08-03 03:20:06 UTC
Created attachment 34098 [details]
Disabled unit test, currently failing
Comment 3 Roland 2017-04-23 21:01:58 UTC
Created attachment 34944 [details]
File to reproduce maybe the same error

I have also the problem that the function groupColumn not working correctly.
And the size of the columns are also not correct after groupColumn.

If I call groupColumn after changing the size of the columns I have the problem.
If I call groupColumn before changing the size of the columns it seems to be good.

In my application it is very difficult to change the position of the function call.

I have tested the current version 3.16.
Comment 4 bukjai 2021-08-18 08:03:30 UTC
I ran into the same mistake. 
First use groupColumn, then setColumnWidth and it works.
The order is important.

version 4.0.1