ピボットテーブルのレイアウトを変更する
MS-Excelでのピボットテーブルのレイアウトの変更方法
Microsoft Excelでは、PivotTable Tools > Design > Report Layoutメニューコマンドを使用してピボットテーブルのレイアウトを変更できます。これらの3つの形式でレイアウトを変更できます
- コンパクト形式で表示
- アウトライン形式で表示
- 表形式で表示
Aspose.Cells for Python Excelライブラリを使用してピボットテーブルのレイアウトを変更する方法
Aspose.Cells for Pythonエクセルライブラリには、これら3つの形式でピボットテーブルのレイアウトを変更するPivotTable.show_in_compact_form()、PivotTable.show_in_outline_form()、およびPivotTable.show_in_tabular_form()メソッドも提供されています。
サンプルコード
次のサンプルコードでは、まずPivot Tableをコンパクト形式で表示し、次にアウトライン形式でPivot Tableを表示し、最後にPivot Tableを表形式で表示します。
from aspose.cells import 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 object from source excel file | |
workbook = Workbook(dataDir + "pivotTable_sample.xlsx") | |
# Access first worksheet | |
worksheet = workbook.worksheets[0] | |
# Access first pivot table | |
pivotTable = worksheet.pivot_tables[0] | |
# 1 - Show the pivot table in compact form | |
pivotTable.show_in_compact_form() | |
# Refresh the pivot table | |
pivotTable.refresh_data() | |
pivotTable.calculate_data() | |
# Save the output | |
workbook.save(dataDir + "CompactForm_out.xlsx") | |
# 2 - Show the pivot table in outline form | |
pivotTable.show_in_outline_form() | |
# Refresh the pivot table | |
pivotTable.refresh_data() | |
pivotTable.calculate_data() | |
# Save the output | |
workbook.save(dataDir + "OutlineForm_out.xlsx") | |
# 3 - Show the pivot table in tabular form | |
pivotTable.show_in_tabular_form() | |
# Refresh the pivot table | |
pivotTable.refresh_data() | |
pivotTable.calculate_data() | |
# Save the output | |
workbook.save(dataDir + "TabularForm_out.xlsx") |