Konsolidierungsfunktion
Konsolidierungsfunktion
Mit Aspose.Cells für Python via .NET kann die Konsolidierungsfunktion auf Datenfelder (oder Wertefelder) der Pivottabelle angewendet werden. In Microsoft Excel können Sie mit der rechten Maustaste auf das Wertefeld klicken und dann die Option Wertfeldeinstellungen… auswählen und anschließend den Tab Werte zusammenfassen nach wählen. Von dort aus können Sie jede gewünschte Konsolidierungsfunktion auswählen, wie Summe, Anzahl, Durchschnitt, Max, Min, Produkt, Distinct Count, usw.
Aspose.Cells für Python via .NET bietet die ConsolidationFunction Aufzählung zur Unterstützung der folgenden Konsolidierungsfunktionen.
- ConsolidationFunction.AVERAGE
- ConsolidationFunction.COUNT
- ConsolidationFunction.COUNT_NUMS
- ConsolidationFunction.DISTINCT_COUNT
- ConsolidationFunction.MAX
- ConsolidationFunction.MIN
- ConsolidationFunction.PRODUCT
- ConsolidationFunction.STD_DEV
- ConsolidationFunction.STD_DEVP
- ConsolidationFunction.SUM
- ConsolidationFunction.VAR
- ConsolidationFunction.VARP
Wie man die ConsolidationFunction auf Datenfelder des Pivot-Tables mit der Aspose.Cells für die Excel-Bibliothek für Python anwendet
Der folgende Code wendet die AVERAGE-Konsolidierungsfunktion auf das erste Datenfeld (oder Wertefeld) und die DISTINCT_COUNT-Konsolidierungsfunktion auf das zweite Datenfeld (oder Wertefeld) an.
from aspose.cells import ConsolidationFunction, Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create workbook from source excel file | |
workbook = Workbook(dataDir + "Book.xlsx") | |
# Access the first worksheet of the workbook | |
worksheet = workbook.worksheets[0] | |
# Access the first pivot table of the worksheet | |
pivotTable = worksheet.pivot_tables[0] | |
# Apply Average consolidation function to first data field | |
pivotTable.data_fields[0].function = ConsolidationFunction.AVERAGE | |
# Apply DistinctCount consolidation function to second data field | |
pivotTable.data_fields[1].function = ConsolidationFunction.DISTINCT_COUNT | |
# Calculate the data to make changes affect | |
pivotTable.calculate_data() | |
# Saving the Excel file | |
workbook.save(dataDir + "output.xlsx") |