Skip to content

Row grouping

Sveinung edited this page Feb 8, 2026 · 1 revision

You can group rows using the OutlineLevel property on RowOptions.

While not strictly required, it's recommended to also set the MaxRowOutlineLevel on WorksheetOptions when using row grouping. This allows Excel to know how many levels of grouping to expect and can help with performance when opening the file in Excel. Due to the internal layout of Excel files and the streaming manner of this library, MaxRowOutlineLevel must be set when starting a worksheet (as opposed to having this calculated automatically after all rows have been added).

Example

await using var spreadsheet = await Spreadsheet.CreateNewAsync(stream);

// While not strictly required, it's recommended to also set the MaxRowOutlineLevel when using row grouping.
var worksheetOptions = new WorksheetOptions { MaxRowOutlineLevel = 2 };

await spreadsheet.StartWorksheetAsync("Sheet 1", worksheetOptions);

var group1Options = new RowOptions { OutlineLevel = 1 };
var group2Options = new RowOptions { OutlineLevel = 2 };

await spreadsheet.AddRowAsync([new Cell(10)]);
await spreadsheet.AddRowAsync([new Cell(20)], group1Options);
await spreadsheet.AddRowAsync([new Cell(30)], group2Options);
await spreadsheet.AddRowAsync([new Cell(40)], group2Options);
await spreadsheet.AddRowAsync([new Cell(50)]);

await spreadsheet.FinishAsync();
image

Clone this wiki locally