【发布时间】:2017-01-27 23:37:25
【问题描述】:
在我的工作表上的两个地方,我需要具有白色字体和黑色背景的单元格。在一个地方(标题行),它可以工作;在另一个(日期值)中,它没有,而且我看不出我正在做的不同会导致此失败。
这是有效的代码(用于标题行):
CellsFactory cfHeaderRow = new CellsFactory();
Cell headerRowCell;
Style styleHeaderRow;
for (int x = 0; x < drPrices.FieldCount-1; x++)
{
headerRowCell = pricePushSheet.Cells[6, x];
headerRowCell.PutValue(drPrices.GetName(x));
pricePushSheet.Cells.SetColumnWidth(x, 9);
styleHeaderRow = cfHeaderRow.CreateStyle();
styleHeaderRow.HorizontalAlignment = TextAlignmentType.Center;
styleHeaderRow.Font.Color = Color.White;
styleHeaderRow.ForegroundColor = Color.Black;
styleHeaderRow.Pattern = BackgroundType.Solid;
styleHeaderRow.IsTextWrapped = true;
headerRowCell.SetStyle(styleHeaderRow);
}
..这是不起作用的代码(对于下面屏幕截图中圈出的日期行):
CellsFactory cfDate = new CellsFactory();
Cell dateCell = pricePushSheet.Cells[3, 4];
Style styleDate = cfDate.CreateStyle();
dateCell.PutValue(pricePushSheet.Cells[7, 1]);
StyleFlag flag2 = new StyleFlag();
flag2.NumberFormat = true;
styleDate.Font.IsBold = true;
styleDate.HorizontalAlignment = TextAlignmentType.Center;
styleDate.Font.Color = Color.White;
styleDate.ForegroundColor = Color.Black;
styleDate.Pattern = BackgroundType.Solid;
styleDate.Custom = "mm/dd/yyyy";
dateCell.SetStyle(styleDate, flag2);
因此,在非工作代码中似乎不同(可能很重要)的是它使用了 StyleFlag(因为它需要设置日期格式):
StyleFlag flag2 = new StyleFlag();
flag2.NumberFormat = true;
styleDate.Custom = "mm/dd/yyyy";
...当然,SetStyle 将标志作为第二个参数(代码的工作位不需要标志,因为它没有做任何花哨的事情)。
如下所示,相关单元格中没有日期 (E4);它从尚未出现在工作表上的地方抓取它。但事实上字体是黑色而不是白色,背景(Aspose 称为前景)是白色而不是黑色。
那么为什么着色不起作用?我需要做什么或更改才能使其在单元格 E4 中工作?
【问题讨论】:
标签: excel aspose aspose-cells background-foreground