Pivot Tabellenzellen mit C++ formatieren
Manchmal möchten Sie Pivottabellenzellen formatieren. Zum Beispiel möchten Sie Hintergrundfarbe auf Pivottabellenzellen anwenden. Aspose.Cells bietet zwei Methoden PivotTable::FormatAll() und PivotTable::Format(), die Sie zu diesem Zweck verwenden können.
PivotTable::FormatAll() wendet den Stil auf die gesamte Pivot-Tabelle an, während PivotTable::Format() den Stil auf eine einzelne Zelle der Pivot-Tabelle anwendet.
Der folgende Beispielcode lädt die Beispiel Excel-Datei, die zwei Pivot-Tabellen enthält, und führt die Operation der Formatierung der gesamten Pivot-Tabelle und der einzelnen Zellen in der Pivot-Tabelle aus.
#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;
}