通过数据透视表的 PivotField 的显示名称获取单元格对象(C++)

用 C++ 通过数据透视表的 PivotField 的显示名称获取单元格对象

以下代码访问工作表的第一个数据透视表,并根据数据透视表的第二个数据字段的显示名称检索单元格。然后,将单元格的填充颜色设为浅蓝色,字体颜色设为黑色。以下为执行前后数据透视表的效果截图。

透视表 - 在之前
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();
}
透视表 - 在之后
todo:image_alt_text