合并函数
Contents
[
Hide
]
合并函数
Aspose.Cells for Python via .NET可用于将合并函数应用于数据透视表的数据字段(或值字段)。在Microsoft Excel中,您可以右键单击值字段,然后选择值字段设置…选项,然后选择选项卡根据汇总的值。从那里,您可以选择您喜欢的任何合并函数,如求和、计数、平均、最大、最小、乘积、不同计数等。
Aspose.Cells for Python via .NET提供ConsolidationFunction枚举以支持以下合并函数。
- ConsolidationFunction.AVERAGE
- ConsolidationFunction.COUNT
- ConsolidationFunction.COUNT_NUMS
- ConsolidationFunction.DISTINCT_COUNT
- ConsolidationFunction.MAX
- ConsolidationFunction.MIN
- ConsolidationFunction.PRODUCT
- ConsolidationFunction.STD_DEV
- ConsolidationFunction.STD_DEVP
- ConsolidationFunction.SUM
- ConsolidationFunction.VAR
- ConsolidationFunction.VARP
如何使用Aspose.Cells for Python Excel库将ConsolidationFunction应用于数据字段的数据透视表
以下代码将AVERAGE合并函数应用于第一个数据字段(或值字段),并将DISTINCT_COUNT合并函数应用于第二个数据字段(或值字段)。
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
from aspose.cells import ConsolidationFunction, Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create workbook from source excel file | |
workbook = Workbook(dataDir + "Book.xlsx") | |
# Access the first worksheet of the workbook | |
worksheet = workbook.worksheets[0] | |
# Access the first pivot table of the worksheet | |
pivotTable = worksheet.pivot_tables[0] | |
# Apply Average consolidation function to first data field | |
pivotTable.data_fields[0].function = ConsolidationFunction.AVERAGE | |
# Apply DistinctCount consolidation function to second data field | |
pivotTable.data_fields[1].function = ConsolidationFunction.DISTINCT_COUNT | |
# Calculate the data to make changes affect | |
pivotTable.calculate_data() | |
# Saving the Excel file | |
workbook.save(dataDir + "output.xlsx") |
Microsoft Excel 2013仅支持DISTINCT_COUNT合并函数。