Search code examples
epplus

How to set multi level collapsible outlines using EPPlus


I was looking at the POST to create a multi level collapsible grouping in Excel using EPPlus, but I am not able to create a inner group within an existing group. Please see the example file I am using hereenter image description here

It seems, I need to set the OutlineLevel for Row 14- 18 twice, first to set them at level 3 and also again to set them at level 2 as part of the larger group (Row 10 - 27), and it's only taking the level 2 value, not showing the inner level.enter image description here

Let me know if there is a way to achieve it using EPPlus.

Thanks in advance!!


Solution

  • You can achieve this if you think of creating outer level first, then create inner level (using C#).

    // 0. populate with basic data
    worksheet.Cells[1, 1].Value = "outside";    //  | outside |        |
    worksheet.Cells[2, 2].Value = "inside";     //  |         | inside |
    worksheet.Cells[3, 1].Value = "outside";    //  | outside |        |
    
    // 1. outter level
    for(int i=1; i<=3; i++)
    {
        worksheet.Row(i).OutlineLevel = 1;
        worksheet.Row(i).Collapsed = true;
    }
    
    // 2. inner level
    worksheet.Row(2).OutlineLevel = 2;
    worksheet.Row(2).Collapsed = true;
    

    Result:

    enter image description here

    enter image description here

    enter image description here