为什么为单元格设置颜色不起作用(Aspose Cells)?

B. *_*non 0 excel colors background-foreground aspose aspose-cells

我有这段代码来尝试设置单元格的背景颜色(除其他外):

private static readonly Color CONTRACT_ITEM_COLOR = Color.FromArgb(255, 255, 204);
. . .
cell = pivotTableSheet.Cells[4, 0];
cell.PutValue(AnnualContractProductsLabel);
style = cell.GetStyle();
style.HorizontalAlignment = TextAlignmentType.Center;
style.VerticalAlignment = TextAlignmentType.Center;
style.Font.IsBold = true;
pivotTableSheet.Cells.SetRowHeight(4, 25);
style.BackgroundColor = CONTRACT_ITEM_COLOR;
pivotTableSheet.Cells[4, 0].SetStyle(style);
Run Code Online (Sandbox Code Playgroud)

水平和垂直对齐的设置有效,粗体和高度也有效 - 除了颜色之外的所有内容:

在此输入图像描述

还需要什么?我什至尝试将 ForegroundColor 和背景颜色设置为:

style.ForegroundColor = Color.Red;
style.BackgroundColor = Color.Blue;
Run Code Online (Sandbox Code Playgroud)

...但两者都没有任何作用 - 单元格看起来仍然与上面的屏幕截图完全相同。

小智 5

请将您的代码段更改为(请参阅突出显示的行):例如示例代码:

. . .
cell = pivotTableSheet.Cells[4, 0];
cell.PutValue(AnnualContractProductsLabel);
style = cell.GetStyle();
style.HorizontalAlignment = TextAlignmentType.Center;
style.VerticalAlignment = TextAlignmentType.Center;
style.Font.IsBold = true;
pivotTableSheet.Cells.SetRowHeight(4, 25);
**style.ForegroundColor = CONTRACT_ITEM_COLOR;
style.Pattern = BackgroundType.Solid;**
pivotTableSheet.Cells[4, 0].SetStyle(style);
Run Code Online (Sandbox Code Playgroud)

…………

它应该工作正常。

我在 Aspose 担任支持开发人员/布道者。