Konsolidierungsfunktion
Konsolidierungsfunktion
Mit Aspose.Cells kann die Konsolidierungsfunktion auf Datenfelder (oder Wertefelder) der Pivot-Tabelle angewendet werden. In Microsoft Excel können Sie mit der rechten Maustaste auf das Wertefeld klicken und dann die Option Wertfeldeinstellungen… auswählen, und dann den Tab Werte zusammenfassen nach auswählen. Von dort aus können Sie eine Konsolidierungsfunktion Ihrer Wahl wie Summe, Anzahl, Durchschnitt, Maximum, Minimum, Produkt, Eindeutige Anzahl usw. auswählen.
Aspose.Cells bietet die Aufzählung ConsolidationFunction, um die folgenden Konsolidierungsfunktionen zu unterstützen.
- ConsolidationFunction.Average
- ConsolidationFunction.Count
- ConsolidationFunction.CountNums
- ConsolidationFunction.DistinctCount
- ConsolidationFunction.Max
- ConsolidationFunction.Min
- ConsolidationFunction.Product
- ConsolidationFunction.StdDev
- ConsolidationFunction.StdDevp
- ConsolidationFunction.Sum
- ConsolidationFunction.Var
- ConsolidationFunction.Varp
Anwendung von ConsolidationFunction auf Datenfelder des Pivot-Tabellen
Der folgende Code wendet die Durchschnitt-Konsolidierungsfunktion auf das erste Datenfeld (oder Wertefeld) und die DistinctCount-Konsolidierungsfunktion auf das zweite Datenfeld (oder Wertefeld) an.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook from source excel file | |
Workbook workbook = new Workbook(dataDir + "Book.xlsx"); | |
// Access the first worksheet of the workbook | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access the first pivot table of the worksheet | |
PivotTable pivotTable = worksheet.PivotTables[0]; | |
// Apply Average consolidation function to first data field | |
pivotTable.DataFields[0].Function = ConsolidationFunction.Average; | |
// Apply DistinctCount consolidation function to second data field | |
pivotTable.DataFields[1].Function = ConsolidationFunction.DistinctCount; | |
// Calculate the data to make changes affect | |
pivotTable.CalculateData(); | |
// Saving the Excel file | |
workbook.Save(dataDir + "output.xlsx"); | |