統合機能
統合機能
Aspose.Cells for Node.js via C++は、ピボットテーブルのデータ(または値)フィールドに集約関数を適用するために使用できます。Microsoft Excelでは、値フィールドを右クリックし、「値フィールドの設定…」を選択し、「値の集計方法」タブから選択します。そこから、Sum、Count、Average、Max、Min、Product、Distinct Countなどの集約関数を選択できます。
Aspose.Cells for Node.js via C++は、以下の集約関数をサポートする ConsolidationFunction 列挙を提供します。
- ConsolidationFunction.Average
- ConsolidationFunction.Count
- ConsolidationFunction.CountNums
- ConsolidationFunction.DistinctCount
- ConsolidationFunction.Max
- ConsolidationFunction.Min
- ConsolidationFunction.Product
- ConsolidationFunction.StdDev
- ConsolidationFunction.StdDevp
- ConsolidationFunction.Sum
- ConsolidationFunction.Var
- ConsolidationFunction.Varp
Aspose.Cells for Node.js via C++を使用してピボットテーブルのデータフィールドに集約関数を適用する方法。
次のコードは、最初のデータフィールド(または値フィールド)に 平均 の統合機能を適用し、2番目のデータフィールド(または値フィールド)に 重複排除 の統合機能を適用します。
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"); |