格式化数据透视表单元格
Contents
[
Hide
]
有时你想格式化数据透视表的单元格。例如,为数据透视表单元格应用背景色。Aspose.Cells for Node.js via C++ 提供了两个方法 PivotTable.formatAll(style) 和 PivotTable.format(row, column, style),你可以利用它们来实现。
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"); |