更改数据透视表的布局
Contents
[
Hide
]
如何在MS-Excel中更改数据透视表的布局
Microsoft Excel允许您使用数据透视表工具 > 设计 > 报表布局菜单命令更改数据透视表的布局。您可以以以下三种形式更改布局
- 以紧凑形式显示
- 以大纲形式显示
- 以表格形式显示
如何使用Aspose.Cells for Python Excel库更改数据透视表的布局
Aspose.Cells for Python Excel库也提供PivotTable.show_in_compact_form(),PivotTable.show_in_outline_form()和PivotTable.show_in_tabular_form()方法,以这三种形式更改数据透视表的布局。
示例代码
以下示例代码首先以紧凑形式显示数据透视表,然后以大纲形式显示数据透视表,最后以表格形式显示数据透视表。
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 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") |