用 C++ 格式化数据透视表单元格
Contents
[
Hide
]
有时,您可能希望格式化数据透视表单元格。例如,您可能希望对数据透视表单元格应用背景颜色。Aspose.Cells提供了两种方法PivotTable::FormatAll()和PivotTable::Format(),您可以用于此目的。
PivotTable::FormatAll() 将样式应用于整个数据透视表,而 PivotTable::Format() 将样式应用于数据透视表的单个单元格。
以下示例代码加载包含两个数据透视表的示例Excel文件,实现对整个数据透视表的格式化和对数据透视表中单个单元格的格式化操作。
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main() {
Aspose::Cells::Startup();
Workbook workbook(u"pivot_format.xlsx");
Worksheet worksheet = workbook.GetWorksheets().Get(u"Sheet1");
PivotTable pivotTable = worksheet.GetPivotTables().Get(1);
Style style = workbook.CreateStyle();
style.SetPattern(BackgroundType::Solid);
style.SetBackgroundColor(Color::LightBlue());
pivotTable.FormatAll(style);
style = workbook.CreateStyle();
style.SetPattern(BackgroundType::Solid);
style.SetBackgroundColor(Color::Yellow());
PivotTable pivotTable2 = worksheet.GetPivotTables().Get(0);
pivotTable2.Format(16, 5, style);
workbook.Save(u"out.xlsx");
Aspose::Cells::Cleanup();
return 0;
}