PivotField.IsAutoSort
PivotField.IsAutoSort property
Indicates whether the specified PivotTable field is automatically sorted.
public bool IsAutoSort { get; set; }
Examples
using System;
using Aspose.Cells;
using Aspose.Cells.Pivot;
namespace AsposeCellsExamples
{
public class PivotFieldPropertyIsAutoSortDemo
{
public static void Run()
{
// Create a workbook
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
Cells cells = worksheet.Cells;
// Add sample data
cells["A1"].Value = "Fruit";
cells["B1"].Value = "Quantity";
cells["A2"].Value = "Apple";
cells["B2"].Value = 10;
cells["A3"].Value = "Orange";
cells["B3"].Value = 5;
cells["A4"].Value = "Banana";
cells["B4"].Value = 20;
cells["A5"].Value = "Blueberry";
cells["B5"].Value = 15;
// Create pivot table
PivotTableCollection pivotTables = worksheet.PivotTables;
int index = pivotTables.Add("A1:B5", "E3", "PivotTable1");
PivotTable pivotTable = pivotTables[index];
// Add row field and set auto sort
pivotTable.AddFieldToArea(PivotFieldType.Row, "Fruit");
PivotField rowField = pivotTable.RowFields[0];
rowField.IsAutoSort = true;
rowField.AutoSortField = 1; // Sort by Quantity (column B)
pivotTable.RefreshData();
pivotTable.CalculateData();
// Save the workbook
workbook.Save("PivotFieldIsAutoSortDemo.xlsx");
}
}
}
See Also
- class PivotField
- namespace Aspose.Cells.Pivot
- assembly Aspose.Cells