Bug 47374 - [Patch] Leave all levels collapsed
Summary: [Patch] Leave all levels collapsed
Status: NEEDINFO
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.2-FINAL
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords: PatchAvailable
Depends on:
Blocks:
 
Reported: 2009-06-16 09:57 UTC by julien
Modified: 2016-03-12 15:08 UTC (History)
0 users



Attachments
The classe RowRecordsAggregate (18.47 KB, patch)
2009-06-16 09:57 UTC, julien
Details | Diff
test case (13.50 KB, application/vnd.ms-excel)
2009-06-17 06:44 UTC, julien
Details

Note You need to log in before you can comment on or make changes to this bug.
Description julien 2009-06-16 09:57:02 UTC
I create three groups being the root node. I collapse each group as well using setRowGroupCollapsed. However, when I expand the first node on the Excel File generated, all the other nodes are also expanded.
To prevent this I apply this patch in the class org.apache.poi.hssf.record.aggregates.RowRecordsAggregate, method collapseRow :

 public void collapseRow( int rowNumber )
    {
        // Find the start of the group.
        int startRow = findStartOfRowOutlineGroup( rowNumber );
        RowRecord rowRecord = getRow( startRow );

        //I add this line
        rowRecord.setColapsed(true);


        // Hide all the columns until the end of the group
        int lastRow = writeHidden( rowRecord, startRow, true );

        // Write collapse field
        if (getRow(lastRow + 1) != null)
        {
            getRow(lastRow + 1).setColapsed( true );
        }
        else
        {
            RowRecord row = createRow( lastRow + 1);
            row.setColapsed( true );
            insertRow( row );
        }
    }
Comment 1 julien 2009-06-16 09:57:44 UTC
Created attachment 23816 [details]
The classe RowRecordsAggregate
Comment 2 Josh Micich 2009-06-16 17:02:31 UTC
Your comment was:
Thanks for the bug-report and suggested fix.  So your proposed change was to
add the line "rowRecord.setColapsed(true);" in collapseRow(int):

    public void collapseRow(int rowNumber) {

        // Find the start of the group.
        int startRow = findStartOfRowOutlineGroup(rowNumber);
        RowRecord rowRecord = getRow(startRow);

+        rowRecord.setColapsed(true);
        // Hide all the columns until the end of the group
        int nextRowIx = writeHidden(rowRecord, startRow);


Unfortunately this is NQR.  I think we need to mark the previous row as
'collapsed', not the first row.

For example, with the following POI calls:

    sheet.setRowSumsBelow(false);
    sheet.groupRow(3, 5);
    sheet.setRowGroupCollapsed(3, true);

We should get the following 'outline levels' and flags in the rows:

2 ol=0 collapsed
3 ol=1 hidden
4 ol=1 hidden
5 ol=1 hidden

Currently POI does this:

3 ol=1 hidden
4 ol=1 hidden
5 ol=1 hidden
6 ol=0 collapsed
(Which is actually correct only if sheet.rowSumsBelow == true)

I've done some experimenting with how Excel collapses rows and it appears that
the row with the 'collapsed' flag should appear above *or* below the group
according to the state of the 'rowSumsBelow' flag on the sheet.  POI assumes
the 'collapsed' flag belongs on the group subsequent row which is wrong if
rowSumsBelow is false.

POI should also be changed so that the 'rowSumsBelow' property in HSSFSheet
gets coordinated with the underlying RowRecordsAggregate.  The
RowRecordsAggregate needs to know the value of this flag in order to find the
right row to update the 'collapsed' flag on.  Furthermore, when 'rowSumsBelow'
changes in the sheet, the RowRecordsAggregate will also need to transfer the
'collapsed' flags of each row group accordingly.


Note - Excel's overall model for collapsing row groups works OK as long as
every group has its own dedicated summary row (above or below).  It's not too
hard to create groups that have no summary row, and Excel behaves a little
weirdly in these cases.  POI probably shouldn't bother supporting such
anomalous use cases, and that should be mentioned in the javadoc.
Comment 3 julien 2009-06-17 06:37:58 UTC
Thank you for your comments. But I think I have not good explain my problem.
In my example, I have one root group, and two sub-group. And when I expand the root group, the sub-group are also expanded. I attach a file example.
My patch fixes the problem.
In my example the 'rowSumsBelow' property is false.
I hope you understand what I mean.
Comment 4 julien 2009-06-17 06:44:53 UTC
Created attachment 23824 [details]
test case
Comment 5 Dominik Stadler 2016-03-12 15:08:21 UTC
This patch is now quite outdated and thus it is very hard to see what the actual changes were here because a full file was provided instead of a clean patch with only the relevant changes. 

Setting this to NEEDINFO unless someone comes up with a refreshed patch that applies cleanly to the current version again.