Click here to Skip to main content
15,879,095 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,
I had a requirement where i need to group the rows in the excel using OpenXMl SDK.
I have gone through the several websites but was unlucky.Any help would be appreciated.

Thanks!!
Posted

1 solution

Hi, well the absurdly simplified solution would be something like this:
C#
SheetData sheetData = ...

int start = 5;
int count = 3;
foreach (var row in sheetData.Elements<Row>().Skip(start))
{
    if (count-- > 0)
        row.SetAttribute(new OpenXmlAttribute("outlineLevel", string.Empty, "1"));
    else
        break;
}

This results in grouping rows "6", "7" and "8", you may notice that you just need to add outlineLevel attribute with the level's value to the required rows.
But again I need to point out that this very very simplified solution with which I'm just showing you what your goal is.

You see you need to actually evaluate the row.RowIndex when doing the iteration. Also in case some rows, that you are targeting to be inside your group, are missing you need to add them and apply the outlineLevel attribute on them as well.

I hope this will get you started in the right direction, if you need more let me know.
 
Share this answer
 
Comments
Bhuvaanesh kumar 8-Feb-22 11:23am    
Thank you so much it worked for me after several hurdles

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900