Free Support Forum -

How to add pivot table

I am trying to add a pivot table to worksheet.
I went to this URL

They have used pivot class.
I am not having pivot class in Aspose version

Can anyone tell me which class should I use and How?


List of classes I am having related to pivot.


You mean Aspose.Cells.Pivot nampespace? Yes, this namespace are included in the later/new versions and all the pivot tables related classes with their members are moved to that namespace.

For your older version e.g v4.8.1.x that you are using, all the relevant pivot tables are in the main Aspose.Cells namespace. So, you should or can only import Aspose.Cells namespace for your project/application. All your provided list of classes are there in the main Aspose.Cells namespace.

Using older version, your code might look like this:

//Adding a PivotTable to the worksheet
int index = worksheet.PivotTables.Add("=Data!A1:F30", “B3”, “PivotTable1”);
//Accessing the instance of the newly added PivotTable
Aspose.Cells.PivotTable pivotTable = worksheet.PivotTables[index];

Thank you.

I tried doing that…but it’s throwing an error.
saying"PivotTable Field name is Invalid"

I have written
int index = worksheet.PivotTables.Add("=Test!A1:F35", “C36”, “pivottable1”);

Test is the sheet name in the excel file.
I am attaching with the excel sheet.


Well, since your pivot fields start from A2 cell, so you should change your line of code, it works fine:

int index = worksheet.PivotTables.Add("=Test!A2:F35", “C36”, “pivottable1”);

Thanks Amjad…
I have just figured it out…
Thanks again…