Hämta cellobjektet genom visningsnamn för PivotField i PivotTable med C++

Hämta cellobjektet genom visningsnamn för PivotField i PivotTable

Följande kod får den första pivot-tabellen i kalkbladet och hämtar sedan cellen genom visningsnamnet för det andra datafältets pivot-tabell. Den ändrar sedan fyllnadsfärgen och teckensnittsfärgen till ljusblå respektive svart. Nedan visas skärmbilder på hur pivot-tabellen ser ut före och efter kodens körning.

Pivot-tabel - Före
todo:image_alt_text
#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-tabel - Efter
todo:image_alt_text