Format Pivot Table Cells with C++
Sometimes, you want to format pivot table cells. For example, you want to apply background color to pivot table cells. Aspose.Cells provides two methods PivotTable::FormatAll() and PivotTable::Format(), which you can use for this purpose.
PivotTable::FormatAll() applies the style to the entire pivot table while PivotTable::Format() applies the style to a single cell of the pivot table.
The following sample code loads the sample Excel file that contains two pivot tables, and achieves the operation of formatting the entire pivot table and formatting individual cells in the pivot table.
#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;
}