Skip to content

Grouping and Ungrouping Rows and Columns

Mats Alm edited this page Nov 10, 2026 · 8 revisions

This page has moved. The current version of this page is at https://epplussoftware.com/docs/worksheet-and-ranges/rows-and-columns/grouping-and-ungrouping-rows-and-columns/. The EPPlus documentation is no longer updated in this wiki; please use the EPPlus guides and update your bookmarks.

EPPlus can group rows and columns and add buttons to expand or collapse the groups.

Grouping of rows and columns is set by the OutlineLevel property. EPPlus 6.1 provides several new methods to group and expand and collapse rows and columns.

Member Description
OutlineLevel A property indicating the level of grouping for the row or column.
Collapsed A property indicating that the row/column's children are collapsed. Setting this property will not hide the children. Use the CollapseChildren() or SetVisibleOutlineLevel() methods to collapse and hide columns/rows.
Group() Groups rows or columns together. Adds one to OutlineLevel property from 1-8.
Ungroup() Ungroups rows or columns. Subtracts one from OutlineLevel property.
CollapseChildren(bool) Collapses and hides the children of the row/columns. If the first parameter is true, all children will be collapsed and hidden; otherwise, only the children on the level below will be collapsed.
ExpandChildren(bool) Expands and shows the children of the row/columns. If the first parameter is true, all children will be expanded; otherwise, only the children on the level directly below will be expanded.
SetVisibleOutlineLevel(int) Sets the visible level for a range of rows/columns.
SetVisibleOutlineLevel(int,bool) Sets the visible level for a range of rows/columns. The second parameter sets if rows/columns lower than the visible level should be collapsed or left as is.

The outline can also be set to be on top or below a group of rows or to the left or right of a group of columns. This is set by the following properties on the ExcelWorksheet:

Member Description
OutLineSummaryBelow If true, the expand/collapse buttons are below the row group; otherwise, on top.
OutLineSummaryRight If true, the expand/collapse buttons are to the right of the column group; otherwise, to the left.

Sample

worksheet.OutLineSummaryBelow = false;

worksheet.Rows[1, 15].Group();
worksheet.Rows[2, 15].Group();
worksheet.Rows[4, 15].Group();
worksheet.Rows[11, 12].Group();
worksheet.Rows[14, 15].Group();

worksheet.Cells["A3"].EntireRow.CollapseChildren(true); // Collapses the children rows of row 3. True means sub-levels are also collapsed.

See also

EPPlus wiki

Versions

Worksheet & Ranges

Styling

Import/Export data

Formulas and filters

Charts & Drawing objects

Tables & Pivot Tables

VBA & Protection

Clone this wiki locally

⌂ 换网址