Travail sur les formats d affichage des données de DataField dans le tableau croisé dynamique
Comment définir l’option de format d’affichage “Classer du plus petit au plus grand” et “Classer du plus grand au plus petit”
Aspose.Cells for Python via .NET offre la possibilité de définir l’option de format d’affichage pour les champs de tableau croisé. Pour cela, l’API fournit la propriété PivotField.data_display_format. Pour classer du plus grand au plus petit, vous pouvez définir la propriété PivotField.data_display_format sur PivotFieldDataDisplayFormat.RANK_LARGEST_TO_SMALLEST. Le code suivant montre comment définir les options de format d’affichage.
Les fichiers source et de sortie de l’échantillon peuvent être téléchargés d’ici pour tester le code d’échantillon:
from aspose.cells import Workbook | |
from aspose.cells.pivot import PivotFieldDataDisplayFormat | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# directories | |
sourceDir = RunExamples.Get_SourceDirectory() | |
outputDir = RunExamples.Get_OutputDirectory() | |
# Load a template file | |
workbook = Workbook(sourceDir + "PivotTableSample.xlsx") | |
# Get the first worksheet | |
worksheet = workbook.worksheets[0] | |
pivotIndex = 0 | |
# Accessing the PivotTable | |
pivotTable = worksheet.pivot_tables[pivotIndex] | |
# Accessing the data fields. | |
pivotFields = pivotTable.data_fields | |
# Accessing the first data field in the data fields. | |
pivotField = pivotFields[0] | |
# Setting data display format | |
pivotField.data_display_format = PivotFieldDataDisplayFormat.RANK_LARGEST_TO_SMALLEST | |
pivotTable.calculate_data() | |
# Saving the Excel file | |
workbook.save(outputDir + "PivotTableDataDisplayFormatRanking_out.xlsx") |