根据数据透视表的PivotField显示名称获取单元格对象

通过透视表的透视字段的DisplayName获取单元格对象

以下代码访问工作表的第一个透视表,然后通过透视表的第二个数据字段的显示名称获取单元格。然后将单元格的填充颜色和字体颜色分别更改为浅蓝色和黑色。下面的屏幕截图显示了代码执行之前和之后透视表的外观。

透视表 - 在之前
todo:image_alt_text
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create workbook object from source excel file
Workbook workbook = new Workbook(dataDir + "source.xlsx");
// Access first worksheet
Worksheet worksheet = workbook.Worksheets[0];
// Access first pivot table inside the worksheet
PivotTable pivotTable = worksheet.PivotTables[0];
// Access cell by display name of 2nd data field of the pivot table
Cell cell = pivotTable.GetCellByDisplayName(pivotTable.DataFields[0].DisplayName);
// Access cell style and set its fill color and font color
Style style = cell.GetStyle();
style.ForegroundColor = Color.LightBlue;
style.Font.Color = Color.Black;
// Set the style of the cell
pivotTable.Format(cell.Row, cell.Column, style);
// Save workbook
workbook.Save(dataDir + "output_out.xlsx");
透视表 - 在之后
todo:image_alt_text