2
votes

I'm trying to add a color to the background of my cells like so:

style.BackgroundColor = Color.LightBlue;
style.Pattern = BackgroundType.Solid;

In more context:

Cell shortNameHeaderCell = locationWorksheet.Cells[BYDCBYLOC_HEADING_ROW, SHORTNAME_BYDCBYLOC_COL];
shortNameHeaderCell.PutValue("Short Name");
style = cf.CreateStyle();
style.HorizontalAlignment = TextAlignmentType.Left;
style.VerticalAlignment = TextAlignmentType.Center;
style.Font.Name = fontForSheets;
style.Font.IsBold = true;
style.Font.Size = 12;
style.BackgroundColor = Color.LightBlue;
style.Pattern = BackgroundType.Solid;
shortNameHeaderCell.SetStyle(style);

Cell companyNameHeaderCell = locationWorksheet.Cells[BYDCBYLOC_HEADING_ROW, COMPANYNAME_BYDCBYLOC_COL];
companyNameHeaderCell.PutValue("Company Name");
companyNameHeaderCell.SetStyle(style);

Cell reasonDescHeaderCell = locationWorksheet.Cells[BYDCBYLOC_HEADING_ROW, REASONDESC_BYDCBYLOC_COL];
reasonDescHeaderCell.PutValue("Reason Description");
reasonDescHeaderCell.SetStyle(style);

Cell transTypeHeaderCell = locationWorksheet.Cells[BYDCBYLOC_HEADING_ROW, TRANSTYPE_BYDCBYLOC_COL];
transTypeHeaderCell.PutValue("Transaction Type");
style = cf.CreateStyle();
style.HorizontalAlignment = TextAlignmentType.Center;
style.Font.Name = fontForSheets;
style.Font.IsBold = true;
style.Font.Size = 12;
style.IsTextWrapped = true;
style.BackgroundColor = Color.LightBlue;
style.Pattern = BackgroundType.Solid;
transTypeHeaderCell.SetStyle(style);

Cell sumOfQtyOrdHeaderCell = locationWorksheet.Cells[BYDCBYLOC_HEADING_ROW, QTYORD_BYDCBYLOC_COL];
sumOfQtyOrdHeaderCell.PutValue("Sum of Qty Ord");
sumOfQtyOrdHeaderCell.SetStyle(style);

Cell sumOfQtyShippedHeaderCell = locationWorksheet.Cells[BYDCBYLOC_HEADING_ROW, QTYSHIPPED_BYDCBYLOC_COL];
sumOfQtyShippedHeaderCell.PutValue("Sum of Qty Shipped");
sumOfQtyShippedHeaderCell.SetStyle(style);

Yet, the light blue color is not applied:

enter image description here

Something is happening, though, because it looks like the midsections of the vertical lines bounding the cells have been erased. I don't know why, or what if any connection that has with the unbearable invisibleness of the light blue color. Before adding that code (first snippet), those smudges/erasings were not [in]visible.

1

1 Answers

1
votes

Please note, if pattern is solid, Style.ForegroundColor should be used to paint the cell (or range). Moreover, if pattern is not solid or none, Style.BackgroundColor should be used for the same scenario.

Note: I am working as Developer Evangelist at Aspose.