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

Free Support Forum - aspose.com

Pivot Field Row field value and Column field value

Dear Aspose support team,

I need to access the different values of Row field or the Column field. So i'm trying to assign these values to an array.

Please advise me if this is possible.

Thank you

Regards,

Suchindhraa

Hi,

Well, you may get the pivot item value using PivotField.Items property. Please try the attached version (4.5.1.20) and refer to the following code:

Sample code:

//Instantiating an Workbook object
Workbook workbook = new Workbook();
//Obtaining the reference of the newly added worksheet
Worksheet sheet = workbook.Worksheets[0];
Cells cells = sheet.Cells;
//Setting the value to the cells
Cell cell = cells["A1"];
cell.PutValue("Sport");
cell = cells["B1"];
cell.PutValue("Quarter test");
cell = cells["C1"];
cell.PutValue("Sales");
cell = cells["D1"];
cell.PutValue("Sales1");

cell = cells["A2"];
cell.PutValue("Golf");
cell = cells["A3"];
cell.PutValue("Golf");
cell = cells["A4"];
cell.PutValue("Tennis");
cell = cells["A5"];
cell.PutValue("Tennis");
cell = cells["A6"];
cell.PutValue("Tennis");
cell = cells["A7"];
cell.PutValue("Tennis");
cell = cells["A8"];
cell.PutValue("Golf");


cell = cells["B2"];
cell.PutValue("Qtr3");
cell = cells["B3"];
cell.PutValue("Qtr4");
cell = cells["B4"];
cell.PutValue("Qtr3");
cell = cells["B5"];
cell.PutValue("Qtr4");
cell = cells["B6"];
cell.PutValue("Qtr3");
cell = cells["B7"];
cell.PutValue("Qtr4");
cell = cells["B8"];
cell.PutValue("Qtr3");


cell = cells["C2"];
cell.PutValue(1500);
cell = cells["C3"];
cell.PutValue(2000);
cell = cells["C4"];
cell.PutValue(600);
cell = cells["C5"];
cell.PutValue(1500);
cell = cells["C6"];
cell.PutValue(4070);
cell = cells["C7"];
cell.PutValue(5000);
cell = cells["C8"];
cell.PutValue(6430);

cell = cells["D2"];
cell.PutValue(0);
cell = cells["D3"];
cell.PutValue(0);
cell = cells["D4"];
cell.PutValue(0);
cell = cells["D5"];
cell.PutValue(0);
cell = cells["D6"];
cell.PutValue(0);
cell = cells["D7"];
cell.PutValue(0);
cell = cells["D8"];
cell.PutValue(0);


cell = cells["G22"];
cell.Style.HorizontalAlignment = TextAlignmentType.Center;

PivotTables pivotTables = sheet.PivotTables;

//Adding a PivotTable to the worksheet
int index = pivotTables.Add("=A1:D8", "E20", "PivotTable1");

//Accessing the instance of the newly added PivotTable
PivotTable pivotTable = pivotTables[index];
//Draging the first field to the row area.
pivotTable.AddFieldToArea(PivotFieldType.Row, 0);
//Draging the second field to the column area.
pivotTable.AddFieldToArea(PivotFieldType.Column, 1);
pivotTable.AddFieldToArea(PivotFieldType.Data, 2);
string[] items = pivotTable.ColumnFields[0].Items;
Console.WriteLine(items[0]);
Console.WriteLine(items[1]);

Thank you.

Dear Aspose support team,

I should really appreciate your quick releases. Thank you very much for your support once again.

Regards,

Suchindhraa