ピボットテーブルセルの書式設定
Contents
[
Hide
]
時には、ピボットテーブルのセルの書式設定を行いたい場合があります。例えば、ピボットテーブルのセルに背景色を適用したい場合です。Aspose.Cells for Node.js via C++ は、この目的に PivotTable.formatAll(style) と PivotTable.format(row, column, style) の2つのメソッドを提供します。
PivotTable.formatAll(style) は、ピボットテーブル全体にスタイルを適用し、PivotTable.format(row, column, style) はピボットテーブルの個々のセルにスタイルを適用します。
This file contains hidden or 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
const AsposeCells = require("aspose.cells.node"); | |
//Create workbook object from source file containing pivot table | |
var workbook = new AsposeCells.Workbook("pivot_format.xlsx"); | |
//Access the worksheet by its name | |
var worksheet = workbook.getWorksheets().get("Sheet1"); | |
//Access the pivot table | |
var pivotTable = worksheet.getPivotTables().get(1); | |
//Create a style object with background color light blue | |
var style = workbook.createStyle(); | |
style.setPattern(AsposeCells.BackgroundType.Solid); | |
style.setBackgroundColor(AsposeCells.Color.LightBlue); | |
//Format entire pivot table with light blue color | |
pivotTable.formatAll(style); | |
//Create another style object with yellow color | |
var style = workbook.createStyle(); | |
style.setPattern(AsposeCells.BackgroundType.Solid); | |
style.setBackgroundColor(AsposeCells.Color.Yellow); | |
//Access the pivot table | |
var pivotTable2 = worksheet.getPivotTables().get(0); | |
//Format the cell of pivot table | |
pivotTable2.format(16, 5, style); | |
//Save the workbook object | |
workbook.save("out.xlsx"); |