ピボットテーブルのレイアウトを変更する
Microsoft Excelでは、PivotTable Tools > Design > Report Layoutメニューコマンドを使用してピボットテーブルのレイアウトを変更できます。レイアウトはこれらの3つの形式で変更できます
- コンパクト形式で表示
- アウトライン形式で表示
- 表形式で表示
Aspose.Cellsは、これらの3つの形式でピボットテーブルのレイアウトを変更するPivotTable.showInCompactForm()、PivotTable.showInOutlineForm()、およびPivotTable.showInTabularForm()のメソッドも提供しています。
例
次のサンプルコードでは、まずPivot Tableをコンパクト形式で表示し、次にPivot Tableをアウトライン形式で表示し、最後にPivot Tableを表形式で表示します。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ChangingLayoutofPivotTable.class); | |
// Create workbook object from source excel file | |
Workbook workbook = new Workbook(dataDir + "source.xlsx"); | |
// Access first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Access first pivot table | |
PivotTable 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("CompactForm.xlsx"); | |
// 2 - Show the pivot table in outline form | |
pivotTable.showInOutlineForm(); | |
// Refresh the pivot table | |
pivotTable.refreshData(); | |
pivotTable.calculateData(); | |
// Save the output | |
workbook.save("OutlineForm.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.xlsx"); |