Formatta celle di tabella pivot con C++
Contents
[
Hide
]
A volte vuoi formattare le celle della tabella pivot. Ad esempio, vuoi applicare un colore di sfondo alle celle della tabella pivot. Aspose.Cells fornisce due metodi PivotTable::FormatAll() e PivotTable::Format(), che puoi utilizzare a questo scopo.
PivotTable::FormatAll() applica lo stile all’intera tabella pivot mentre PivotTable::Format() applica lo stile a una singola cella della tabella pivot.
Il codice di esempio seguente carica il file Excel di esempio che contiene due tabelle pivot, e realizza l’operazione di formattare l’intera tabella pivot e di formattare singole celle nella tabella pivot.
#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;
}