How to add pivot table

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

http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/create-pivot-tables-and-pivot-charts.html

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

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

Aspose.Cells.PivotField
Aspose.Cells.PivotFields
Aspose.Cells.PivotPageFields
Aspose.Cells.PivotTable
Aspose.Cells.PivotTables

List of classes I am having related to pivot.

Hi,


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.


Hi,


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…