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

Free Support Forum - aspose.com

Sorting on data fields of the Pivot table c#

I want to apply sorting on data fields of the pivot table. Here is a snippet of my code,

pt.AddFieldToArea(Aspose.Cells.Pivot.PivotFieldType.Data, columnItem.ReportObjectName.ToString());
Aspose.Cells.Pivot.PivotField pdf = pt.DataFields[dataIndex++];
pdf.IsAutoSort =false;
if (objRequest.ReportObjectDetails.LstSortReportObject.Find(so => so.ReportObject.ReportObjectId == columnItem.ReportObjectId).SortType == Data.Entities.Enums.SortType.Desc)

                        pdf.IsAscendSort = false;

                        pdf.IsAscendSort = true;

Here sorting is not reflecting on the datafields. Is this a limitation of AsposeCells?


Thanks for your query.

Please provide us a console application(runnable) along with the template and output file as well. Identify and describe the issue in detail using some snapshots etc. Also provide us an expected output file which is created by Excel. It will help us to compare the output created by Aspose.Cells with the expected output file and provide our feedback.


Please find attached
1)Windows Forms Application

2)Excel files
excel.zip (31.3 KB)


Aspose.pdf (295.9 KB)


We were able to observe the issue but at different place with the latest version Aspose.Cells for .NET 18.9.x. We need to look into it more therefore we have logged the issue in our database for investigation and for a fix. Once, we will have some news for you, we will update you in this topic.
Note that we have mentioned your original issue as well in the logged ticket.

This issue has been logged as

CELLSNET-46379 - Exception NullReferenceException raised while calling Worksheet.PivotTables.Add


We have investigated your issue and found it is not an issue with the APIs. While creating PivotTable, if the worksheet name contains special chars, you need to surround the worksheet name with single quotes. So you should change the following code:
string datasource = sheetname + "!A3:" + columnName + row_last.ToString();
string datasource = "'" + sheetname + "'" + "!A3:" + columnName + row_last.ToString();

Please try it and let us know your result.