Hi,
Thanks for the template file.
We have evaluated your scenario/ case further. It looks the feature “Sort data in Data field with respect to / by Row pivot field in the PivotTable” is not supported at the moment as I tried the following sample code (I also tried with other options and combinations of the APIs) but it does not work as expected. It works fine if we sort the pivot field (Row field) itself.
e.g
Sample code:
Workbook wb = new Workbook(@“e:\test2\SortTest.xlsx”);
Worksheet wsData = wb.Worksheets[0];
Worksheet wsPivot = wb.Worksheets.Add(“pvt”);
PivotTableCollection pivotTables = wsPivot.PivotTables;
int index = pivotTables.Add("=‘Values’!A1:B3000", “A3”, “test_PivotTable”);
PivotTable pvtTable = pivotTables[index];
pvtTable.IsAutoFormat = true;
pvtTable.AutoFormatType = PivotTableAutoFormatType.Report4;
// add Hubsite row field
pvtTable.AddFieldToArea(PivotFieldType.Row, 0);
// add data field
int nDataField = pvtTable.AddFieldToArea(PivotFieldType.Data, “Count”);
pvtTable.DataFields[nDataField].Number = 3; // #,##0
pvtTable.RowFields[0].IsAutoSort = true;
pvtTable.RowFields[0].IsAscendSort = true;
//Sort by grand total (Sum of Count)
pvtTable.RowFields[0].AutoSortField = 1;
//Setting autoShow options.
//Setting the field auto show.
pvtTable.DataFields[0].IsAutoShow = true;
//Setting the field auto show ascend.
pvtTable.DataFields[0].IsAscendShow = true;
//Setting the auto show using field(data field).
pvtTable.DataFields[0].AutoShowField = 0;
// save & close file
wb.Save(@“e:\test2\outSortTestOutput1.xlsx”, SaveFormat.Xlsx);
I have logged a ticket with an id “CELLSNET-43257” for your issue/ requirements. We will look into it soon.
Once we have any update on it, we will let you know here.
And for your other needs i.e., change the header text in the Row header to “Hubsite”, well, when the Row label area only contains one PivotField, it would show “Row Label”. If you implement such a table in Ms Excel manually, you will get the same results too. You should first have the Row label area that contains two or more Pivot fields.
Thank you.