Att arbeta med dataformat för datarad i pivottabell

Alternativ för “Rangordna minsta till största” och “Rangordna största till minsta” i displayformat

Aspose.Cells tillhandahåller möjligheten att ange datapresentationformatet för pivotfält. För detta tillhandahåller API:et PivotField.DataDisplayFormat egenskapen. För att rangera störst till minst kan du ange PivotField.DataDisplayFormat egenskapen till PivotFieldDataDisplayFormat.RANK_LARGEST_TO_SMALLEST. Följande kodsnutt visar hur du anger datapresentationformatalternativen.

Provfil och utdatafiler kan laddas ner här för att testa provkoden:

Käll-Excel-fil

Utdata-Excel-fil

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// directories
String sourceDir = Utils.Get_SourceDirectory();
String outputDir = Utils.Get_OutputDirectory();
// Load a template file
Workbook workbook = new Workbook(sourceDir + "PivotTableSample.xlsx");
// Get the first worksheet
Worksheet sheet = workbook.getWorksheets().get(0);
int pivotIndex = 0;
// Get the pivot tables in the sheet
PivotTable pivotTable = sheet.getPivotTables().get(pivotIndex);
// Accessing the data fields.
PivotFieldCollection pivotFields = pivotTable.getDataFields();
// Accessing the first data field in the data fields.
PivotField pivotField = pivotFields.get(0);
// Setting data display format
pivotField.setDataDisplayFormat(PivotFieldDataDisplayFormat.RANK_LARGEST_TO_SMALLEST);
pivotTable.calculateData();
// Saving the Excel file
workbook.save(outputDir + "PivotTableDataDisplayFormatRanking_out.xlsx");