We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Removing subtotals

How do you remove subtotals from a pivot using .NET, similar to the Java solution in the following post?

Show/Hide Sub-totals in Pivot Tables


See the equivalent sample code in .NET for your reference:
Sample code:

Workbook book = new Workbook(dir + “Example.xlsx”);
PivotTable table = book.Worksheets[“Pivot Table”].PivotTables[0];
for (int i = 0; i < table.RowFields.Count; i++)
table.RowFields[i].SetSubtotals(PivotFieldSubtotalType.Automatic, false);
// table.RowFields[i].SetSubtotals(PivotFieldSubtotalType.None, true);
book.Save(dir + “output.xlsx”);

Thank you.

Hello Sahi

This code doesn’t have any effect. Please can you show a sample file and the output. I really need a solution to this urgently!


Could you provide us your input and output Excel file (after using the code segment), we will check it soon. Also give us your expected file which you could create/update in MS Excel manually.

Thank you


Find attached some sample input and expected output. In all I simply want to show the top level row data. This can be done either by removing the subtotals or collapsing the hierarchical tree.



Thanks for the sample files.

Well, your underlying PivotTable’s data source in you template files is some external Excel file. Please note, the Aspose.Cells APIs currently do not support Pivot Table recalculations/manipulations in case the data source is external. However, if the data source resides in the same spreadsheet, you can manipulate or refresh the Pivot Tables accordingly.

Thank you.