【发布时间】:2017-01-17 02:20:41
【问题描述】:
我需要一个单元格的背景颜色为浅蓝色;我有在另一张表中工作的代码,但完全相同的代码(变量名称和列索引 val 除外):
Style styleShipVariance = null;
CellsFactory cfShipVariance = new CellsFactory();
Cell ShipVarianceCell = customerWorksheet.Cells[0, SHIPVARIANCE_COL];
ShipVarianceCell.PutValue("Ship Variance");
styleShipVariance = cfShipVariance.CreateStyle();
styleShipVariance.HorizontalAlignment = TextAlignmentType.Left;
styleShipVariance.Font.Name = fontForSheets;
styleShipVariance.Font.IsBold = true;
styleShipVariance.Font.Size = 11;
styleShipVariance.ForegroundColor = Color.LightBlue;
styleShipVariance.Pattern = BackgroundType.Solid;
ShipVarianceCell.SetStyle(styleShipVariance);
...在另一张纸上不起作用。值(“Ship Variance”)显示在该单元格中,但未应用颜色。
为什么这不起作用?缺少什么?
注意:我也试过添加这个:
var flag = new StyleFlag
{
CellShading = true,
FontName = true,
FontSize = true,
FontColor = true,
FontBold = true,
NumberFormat = true
};
...并将上面的最后一行更改为:
ShipVarianceCell.SetStyle(styleShipVariance, flag);
...但它没有任何区别。
更新
我保存为 xlsx:
var filename = String.Format(@"{0}\{1} - Fill Rate - {2}.xlsx", sharedFolder, _unit, fromAsYYYYMMDD);
if (File.Exists(filename))
{
File.Delete(filename);
}
workBook.Save(filename, SaveFormat.Xlsx);
更新 2
我刚刚注意到 val 也没有加粗或左对齐。正在分配文本值本身,但没有任何格式是...
更新 3
为什么有必要,我不知道,但是通过在数据行添加到工作表之后添加着色代码,它现在可以工作了。
【问题讨论】:
标签: aspose aspose-cells