整合功能
Contents
[
Hide
]
整合功能
Aspose.Cells 可用于将 ConsolidationFunction 应用于数据透视表的数据字段(或值字段)。在Microsoft Excel中,您可以右键单击值字段,然后选择值字段设置…选项,然后选择选项卡值汇总依据.从那里,您可以选择您选择的任何 ConsolidationFunction,例如 Sum、Count、Average、Max、Min、Product、Distinct Count 等。
Aspose.Cells提供整合功能支持以下合并功能的枚举。
- 合并函数.平均
- ConsolidationFunction.Count
- ConsolidationFunction.CountNums 函数
- ConsolidationFunction.DistinctCount
- 合并函数.Max
- 合并函数.Min
- 合并函数.产品
- 合并函数.StdDev
- 合并函数.StdDevp
- 合并函数.Sum
- 合并函数.Var
- 合并函数.Varp
将 ConsolidationFunction 应用于数据透视表的数据字段
以下代码适用平均的合并功能到第一个数据字段(或值字段)和非重复计数合并功能到第二个数据字段(或值字段)。
This file contains 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
// 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"); | |
Microsoft 仅 Excel 2013 支持 DistinctCount 合并函数。