View on GitHub ClosedXML.Report


To perform grouping and create subtotals for the columns in ClosedXML.Report there is a tag <<group>>. The range is pre-sorted by all columns for which the tags are <<group>>, <<sort>>, <<desc>> and <<asc>>. The sort order for the <<group>> option is specified by an additional parameter - <<desc>> or <<asc>> (default asc). By default (without the use of additional options) the work of the <<group>> tag is similar to the work of the Subtotal method of the Range object in Excel. If the <<group>> tag is specified for several columns, the subtotals are grouped by all these columns. Grouping takes place from right to left, that is, first the totals are grouped by the rightmost column, for which the <<group>> tag is specified, then by the column with the <<group>> tag to the left of it, etc. The format of the service line of the range is used to format the rows of subtotals. After the subtotals are created, the service line is removed from the range.

To get subtotals you can use aggregation tags in the corresponding columns:

To change behavior, the <<group>> tag has a number of options:

Also, to change the behavior of a grouping, there are range tags: