I need a cell to have a light blue background color; I have code that works in another sheet, but the same exact code (except for the names of the vars and column index 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);
...does not work on the other sheet. The value ("Ship Variance") is displayed in that cell, but the color is not being applied.
Why would this not work? What is missing?
Note: I also tried adding this:
var flag = new StyleFlag
{
CellShading = true,
FontName = true,
FontSize = true,
FontColor = true,
FontBold = true,
NumberFormat = true
};
...and changing the last line above to:
ShipVarianceCell.SetStyle(styleShipVariance, flag);
...but it made no difference.
I am saving as 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);
I just noticed that the vals are also not being bolded or left-aligned. The text values themselves are being assigned, but none of the formatting is...
Why it was necessary, I don't know, but by adding the colorizing code AFTER the data rows were added to the sheet, it works now.
Well, normally it should work fine. But if you are saving to an XLS file (instead of XLSX file), the light blue background color might not be applied so, you got to add to MS Excel color palette first via the line of code: e.g Sample code:
......... workbook.ChangePalette(Color.LightBlue, 55);
Anyways, we need your template Excel file, so we could evaluate your issue precisely and test to apply the color to the cell on our side and guide you appropriately. I think you may follow up your thread in the Aspose.Cells forums.
I am working as Support developer/ Evangelist at Aspose.