更改数据透视表的布局

如何在MS-Excel中更改数据透视表的布局

Microsoft Excel允许您使用数据透视表工具 > 设计 > 报表布局菜单命令更改数据透视表的布局。您可以以以下三种形式更改布局

  • 以紧凑形式显示
  • 以大纲形式显示
  • 以表格形式显示

如何使用Aspose.Cells for Node.js via C++更改数据透视表的布局。

Aspose.Cells for Node.js via C++库还提供PivotTable.showInCompactForm()PivotTable.showInOutlineForm()PivotTable.showInTabularForm()方法,以这三种形式更改数据透视表的布局。

示例代码

以下示例代码首先以紧凑形式显示数据透视表,然后以大纲形式显示数据透视表,最后以表格形式显示数据透视表。

const AsposeCells = require("aspose.cells.node");
//For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
//The path to the documents directory.
var dataDir = RunExamples.GetDataDir(".")
//Create workbook object from source excel file
var workbook = new AsposeCells.Workbook(dataDir + "pivotTable_sample.xlsx");
//Access first worksheet
var worksheet = workbook.getWorksheets().get(0);
//Access first pivot table
var pivotTable = worksheet.getPivotTables().get(0);
//1 - Show the pivot table in compact form
pivotTable.showInCompactForm();
//Refresh the pivot table
pivotTable.refreshData();
pivotTable.calculateData();
//Save the output
workbook.save(dataDir + "CompactForm_out.xlsx");
//2 - Show the pivot table in outline form
pivotTable.showInOutlineForm();
//Refresh the pivot table
pivotTable.refreshData();
pivotTable.calculateData();
//Save the output
workbook.save(dataDir + "OutlineForm_out.xlsx");
//3 - Show the pivot table in tabular form
pivotTable.showInTabularForm();
//Refresh the pivot table
pivotTable.refreshData();
pivotTable.calculateData();
//Save the output
workbook.save(dataDir + "TabularForm_out.xlsx");