Using PivotTables.Add Method

Hi,

The Workbook.Worksheets.PivotTables.Add method contains 8 overloads, one of which is the following:

public int Add(string[] sourceData, bool isAutoPage, PivotPageFields pageFields, int row, byte column, string tableName)

Could you provide an example of how to call this method in .NET where isAutoPage is set to False? My issue is that I see no way of creating or retrieving a PivotPageFields object to pass to this method.

Hi,

We will get back to you soon for your query.

Thank you.

Hi,

Workbook workbook = new Workbook();
workbook.Open("F:\\FileTemp\\Book1.xls");
//workbook.Worksheets.Add();
Worksheet sheet = workbook.Worksheets[0];

PivotTables pivotTables = sheet.PivotTables;

String[] sourceData = new String[]{"=Sheet1!A1:C8","=Sheet2!A1:C8"};
PivotPageFields pageField = new PivotPageFields();
String[] pageItems = new String[2];
pageItems[0] = "Item1";
pageItems[1] = "Item2";
pageField.AddPageField(pageItems);
pageItems = new String[2];
pageItems[0] = "Item3";
pageItems[1] = "Item4";
pageField.AddPageField(pageItems);
int[] sxTBPG = new int[2];

sxTBPG[0] = 0;
sxTBPG[1] = 1;

//Sets which item label in each page field to use to identify the data range.
pageField.AddIdentify(0,sxTBPG);
sxTBPG = new int[2];
sxTBPG[0] = 1;
sxTBPG[1] = -1;
pageField.AddIdentify(1,sxTBPG);
int index = pivotTables.Add(sourceData,false,pageField,"E3","PivotTable1");

workbook.Save("F:\\FileTemp\\dest.xls");

Hi,

When trying to create a new PivotPageFields object in Visual Basic .NET with the following line:

Dim pageField As PivotPageFields = New PivotPageFields

I get the following error:

'Aspose.Cells.PivotPageFields.Private Sub New()' is not accessible in this context because it is 'Private'.

Is this a bug or am I instantiating the object incorrectly?

Hi,

Please try this fix.

We do not public PivotPageFields construct in the old version.

This worked, thank you.