How to: Change the PivotTable Layout
- 3 minutes to read
To change the layout form of a PivotTable report, pass the appropriate PivotReportLayout enumeration member to the PivotLayout.SetReportLayout method.
The table below describes the available report layouts and lists additional options that can be set for each layout form.
Layout Form | Description | Additional Layout Options |
---|---|---|
Compact Form | This is the default layout for a newly created PivotTable report. This layout enables you to keep your report as narrow as possible. It displays items from different row fields in a single column and subsidiary row field items are shown indented to the left. |
|
Outline Form | This layout displays each row field in its own column. Subsidiary row field items begin one row below the parent field item. |
|
Tabular Form | This layout displays each row field in its own column. Subsidiary row field items begin on the same row. Subtotals for items in the outer row fields are always shown at the bottom. |
|
The following code example shows how to change the default PivotTable layout to outline form.
Worksheet worksheet = workbook.Worksheets["Report1"];
workbook.Worksheets.ActiveWorksheet = worksheet;
// Access the pivot table by its name in the collection.
PivotTable pivotTable = worksheet.PivotTables["PivotTable1"];
// Display the pivot table in the outline form.
pivotTable.Layout.SetReportLayout(PivotReportLayout.Outline);
Note
Besides changing the layout of the entire pivot table, you can also change the layout of a specific field in the report. To do this, use the corresponding properties of the PivotFieldLayout object, which can be accessed using the field’s PivotField.Layout property.