Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
The following code accesses the first pivot table of the worksheet and then retrieves the cell by the display name of the second data field of the pivot table. It then changes the fill color and font color of the cell to light blue and black, respectively. Below are screenshots showing how the pivot table looks before and after the execution of the code.
| Pivot Table - Before |
|---|
![]() |
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
U16String outDir(u"..\\Data\\02_OutputDirectory\\");
Workbook workbook(srcDir + u"source.xlsx");
Worksheet worksheet = workbook.GetWorksheets().Get(0);
PivotTable pivotTable = worksheet.GetPivotTables().Get(0);
Cell cell = pivotTable.GetCellByDisplayName(pivotTable.GetDataFields().Get(0).GetDisplayName());
Style style = cell.GetStyle();
style.SetForegroundColor(Color::LightBlue());
style.GetFont().SetColor(Color::Black());
pivotTable.Format(cell.GetRow(), cell.GetColumn(), style);
workbook.Save(outDir + u"output_out.xlsx");
std::cout << "Pivot table formatted successfully!" << std::endl;
Aspose::Cells::Cleanup();
}
| Pivot Table - After |
|---|
![]() |
|
|
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.