How to: Outline Data Manually
- 4 minutes to read
You can group rows and columns to make it easier to analyze a large amount of data, and simplify navigation within large worksheets. This functionality provides the capability to split your data into separate groups and hide unnecessary details in a worksheet.
Group Rows
To group rows in a worksheet, call the RowCollection.Group method of the RowCollection object. This object represents a collection of all rows contained in a worksheet and is accessed via the Worksheet.Rows property. Pass the indexes of the first and last rows to be grouped, and a value indicating whether the new group should be expanded or collapsed.
Note that you can also place one group of rows inside another. But the number of nested groups is limited: you can create a maximum of seven levels of grouping. The example below demonstrates how two create two levels of grouping.
// Group four rows starting from the third row and collapse the group.
worksheet.Rows.Group(2, 5, true);
// Group four rows starting from the ninth row and expand the group.
worksheet.Rows.Group(8, 11, false);
// Create the outer group of rows by grouping rows 2 through 13.
worksheet.Rows.Group(1, 12, false);
The image below shows the result (the workbook is opened in Microsoft® Excel®).
Ungroup Rows
To ungroup rows in a worksheet, call the RowCollection.UnGroup method of the Worksheet.Rows collection. Pass indexes of the first and last rows to be ungrouped, and a value indicating whether or not collapsed rows should be shown after ungrouping.
// Ungroup four rows (from the third row to the sixth row) and display collapsed data.
worksheet.Rows.UnGroup(2, 5, true);
// Ungroup four rows (from the ninth row to the twelfth row).
worksheet.Rows.UnGroup(8, 11, false);
// Remove the outer group of rows.
worksheet.Rows.UnGroup(1, 12, false);
Group Columns
To group columns in a worksheet, call the ColumnCollection.Group method of the ColumnCollection object. This object represents a collection of all columns contained in a worksheet and is accessed using the Worksheet.Columns property. Pass the indexes of the first and last columns to be grouped, and a value indicating whether the new group should be expanded or collapsed.
Note that you can also place one group of columns inside another. But the number of nested groups is limited: you can create a maximum of seven levels of grouping.
// Group four columns starting from the third column "C" and expand the group.
worksheet.Columns.Group(2, 5, false);
The image below shows the result (the workbook is opened in Microsoft® Excel®).
Ungroup Columns
To ungroup columns in a worksheet, call the ColumnCollection.UnGroup method of the Worksheet.Columns collection. Pass indexes of the first and last columns to be ungrouped, and a value indicating whether or not collapsed columns should be shown after ungrouping.
// Ungroup four columns (from the column "C" to the column "F").
worksheet.Columns.UnGroup(2, 5, false);