You need to enable the AutoSort for the required PivotField and then specify the index on which you wish to sort the Grand Total. We have devised a generic solution for better elaboration of above concepts. Please check the following code snippet that creates a PivotTable from scratch and applies the descending sort on the Grand Total.
C#
var workbook = new Workbook();
var sheet = workbook.Worksheets[0];
sheet = workbook.Worksheets.Add(“pivot”);
var pivotTables = sheet.PivotTables; //Adding a PivotTable to the worksheet int index = pivotTables.Add("=Sheet1!A1:C10", “A1”, “PivotTable2”); //Accessing the instance of the newly added PivotTable
var pivotTable = pivotTables[index]; //Showing grand totals for rows & columns
pivotTable.RowGrand = true;
pivotTable.ColumnGrand = true;
int rowFieldIndex = pivotTable.AddFieldToArea(PivotFieldType.Row, 0); int colFieldIndex = pivotTable.AddFieldToArea(PivotFieldType.Column, 1);
PivotField cpf = pivotTable.ColumnFields[colFieldIndex]; int dataFieldIndex = pivotTable.AddFieldToArea(PivotFieldType.Data, 2);
In case you face any difficulty, please provide us the sample spreadsheet after processing the smart markers and refreshing the PivotTable with new data. We will further look into the matter to provide the exact code snippet according to PivotFields in the spreadsheet.
I have tried above mentioned code but its not working .please find the smart maker formula excel and generated excel(Based on formula) for your reference.
Sorry for the confusion earlier. The current implementation of Aspose.Cells APIs do not support the sorting of row or column fields according to the data field. As your requirement is to sort the row field according to the data field (sum of jobs) so this cannot be achieved with current implementation. I have now logged a feature request in our database to provide the request feature with future releases of the Aspose.Cells for .NET API. The ticket Id for your future reference is CELLSNET-43148. Please spare us little time to properly analyze the request on our end then we can share the estimated release schedule for this feature.
I am afraid, we haven’t yet received any news regarding the feature request logged earlier as CELLSNET-43148 in our database. We have now recorded a note for the concerned development team member to share the estimated release schedule for this feature. As soon as we receive any news, we will post here for your kind reference.
This is to update you regarding the ticket logged earlier as CELLSNET-43148 in order to provide the support for the sorting of Grand Total according to the DataFields. Unfortunately we cannot provide this feature in short period of time due to its complexity and dependencies. We will keep the aforesaid ticket open in our database so that your could be notified once the required feature is available for your testing. Moreover, as soon as we schedule this feature for publication, we will inform you here with estimated time of arrival.