統合機能
統合機能
Aspose.Cells for Python via .NETを使用してデータフィールド(または値フィールド)に集計関数を適用できます。Microsoft Excelでは、値フィールドを右クリックし、値フィールドの設定…オプションを選択してから集計値のサマリズでByタブを選択します。そこから、Sum、Count、Average、Max、Min、Product、Distinct Countなどの任意の集計関数を選択できます。
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ライブラリを使用してピボットテーブルのデータフィールドに集計関数を適用する方法
以下のコードは、最初のデータフィールドにAVERAGE集計関数を適用し、2番目のデータフィールドにDISTINCT_COUNT集計関数を適用します。
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") |