Konsolidierungsfunktion

Konsolidierungsfunktion

Aspose.Cells for Node.js via C++ kann verwendet werden, um die ConsolidationFunction auf Datenfelder (oder Wertfelder) der Pivot-Tabelle anzuwenden. In Microsoft Excel können Sie mit der rechten Maustaste auf das Wertfeld klicken und dann die Option Wertfeldeinstellungen… auswählen und anschließend auf die Registerkarte Werte zusammenfassen nach wechseln. Dort können Sie eine beliebige ConsolidationFunction wie Summe, Anzahl, Durchschnitt, Max, Min, Produkt, Eindeutige Anzahl usw. auswählen.

Aspose.Cells for Node.js via C++ bietet ConsolidationFunction-Aufzählung zur Unterstützung der folgenden Konsolidierungsfunktionen.

  • ConsolidationFunction.Average
  • ConsolidationFunction.Count
  • ConsolidationFunction.CountNums
  • ConsolidationFunction.DistinctCount
  • ConsolidationFunction.Max
  • ConsolidationFunction.Min
  • ConsolidationFunction.Product
  • ConsolidationFunction.StdDev
  • ConsolidationFunction.StdDevp
  • ConsolidationFunction.Sum
  • ConsolidationFunction.Var
  • ConsolidationFunction.Varp

Wie man die ConsolidationFunction auf Datenfelder der Pivot-Tabelle mit Aspose.Cells for Node.js via C++ anwendet

Der folgende Code wendet die Durchschnitt-Konsolidierungsfunktion auf das erste Datenfeld (oder Wertefeld) und die DistinctCount-Konsolidierungsfunktion auf das zweite Datenfeld (oder Wertefeld) an.

const AsposeCells = require("aspose.cells.node");
//For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
//The path to the documents directory.
var dataDir = RunExamples.GetDataDir(".")
//Create workbook from source excel file
var workbook = new AsposeCells.Workbook(dataDir + "Book.xlsx");
//Access the first worksheet of the workbook
var worksheet = workbook.getWorksheets().get(0);
//Access the first pivot table of the worksheet
var pivotTable = worksheet.getPivotTables().get(0);
//Apply Average consolidation function to first data field
pivotTable.getDataFields().get(0).setFunction(AsposeCells.ConsolidationFunction.Average);
//Apply DistinctCount consolidation function to second data field
pivotTable.getDataFields().get(1).setFunction(AsposeCells.ConsolidationFunction.DistinctCount);
//Calculate the data to make changes affect
pivotTable.calculateData();
//Saving the Excel file
workbook.save(dataDir + "output.xlsx");