合并函数
Contents
[
Hide
]
合并函数
Aspose.Cells for Node.js via C++可以用于对数据透视表的数值字段(或值字段)应用汇总函数。在Microsoft Excel中,你可以右键点击数值字段,然后选择值字段设置…,再切换到汇总值方式标签,然后选择你喜欢的任何汇总函数,如求和、计数、平均值、最大值、最小值、乘积、不同计数等。
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++将汇总函数应用于数据透视表的数值字段。
以下代码将平均值整合函数应用于第一个数据字段(或数值字段),将不重复计数整合函数应用于第二个数据字段(或数值字段)。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
Microsoft Excel 2013仅支持DISTINCT_COUNT合并函数。