Excel provides the βTotalβ option from the menu Data β Outline β Subtotal . It automatically creates subavs and the ability to collapse data. The image below shows how an action converts a sheet.

And this is exactly what I need to do through the POI. I know how to set a subtotal function to a cell so that I can calculate subtotals myself. But how to enable this folding on the left border?
I realized that there is a groupRow() method, but these nested groups do not work as they should. If I use the following code, I get only two groups. One large (1-7) and (1-3). Group (5-7) is absent and changing the order of calls is not affected.
sheet.groupRow(1, 7); sheet.groupRow(1, 3); sheet.groupRow(5, 7);
source share