Skip to content

Grouping and Ungrouping Rows and Columns

Mats Alm edited this page Nov 6, 2023 · 7 revisions

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 the the row/colmns 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 collapsed and hidden, otherwise only the children on the level to the right will be collapsed,
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 row/column lower than the visible level should be collapsed or left as is.

The outline can also be set to be on top or bellow a group of rows or to the left or right of a group of columns. This is set by the following methods 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.

RowGroupOutline1

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