EPPlus icon indicating copy to clipboard operation
EPPlus copied to clipboard

Can't apply CollapseChildren() after using Group()

Open hansgfixed opened this issue 8 months ago • 7 comments

EPPlus usage

Noncommercial use

Environment

Windows

Epplus version

7.1.2

Spreadsheet application

Excel

Description

Seems I either can't figure out to properly apply CollapseChildren() or there's a bug. CollapsingChildren() has no effect at all, doesn't matter if I provide startRow or the whole range.

Affected code snipped:

        private static void ExportComponentsRecursiveToExcel(Component component, ExcelWorksheet worksheet, ref int row, bool isRoot)
        {
            int startRow = row;
            ExportComponentToExcel(component, worksheet, row);
            row++;

            if (component.IsComposite)
            {
                for (int i = 0; i < component.Children.Count; i++)
                {
                    var child = component.Children[i];
                    ExportComponentsRecursiveToExcel(child, worksheet, ref row, false);
                }

                worksheet.Rows[startRow + 1, row - 1].Group();
                if (!isRoot)
                {
                    worksheet.Rows[startRow].CollapseChildren();
                    // OR
                    worksheet.Cells[startRow + 1, 1, row - 1, 1].EntireRow.CollapseChildren();
                    // OR
                    worksheet.Cells[$"A{startRow}"].EntireRow.CollapseChildren();
                }
            }
        }

The documentation shows a sample by using Cells which doesn't work for me either. There's only one stackoverflow question in regard to this issue and it doesn't solve it.

Can someone help me out please?

hansgfixed avatar Jun 23 '24 12:06 hansgfixed