C# excel, 从模板中找到单元格的颜色

C# excel, find the color of the cell from template

我需要以编程方式在 Excel 中找到颜色单元格。如果我手动更改颜色,一切都很好(使用 interior.color)。万一你把它翻过来,模板就会产生问题。

x.interior.color returns 任何颜色都是白色。

好的,我需要使用一些模板 Excel -> 设计: 然后我需要在更改后读取单元格的颜色

颜色是橙色但是:

Excel.Range oPivotTableCell.Interior.Color = 16777215.0(这是白色的)

在哪里可以找到特定单元格的真实颜色或模板颜色?

答案是:

excel.Range.DisplayFormat.Interior.Color

获取 excel.range 的好方法是 select 个单元格并获取范围

excel.Range 测试 = (excel.Range)Globals.ThisAddIn.Application.Selection; test.DisplayFormat.Interior.Color