Edit: These examples should all work. My problem was actually unrelated to epplus and this code as well as the marked answer works for styling merged cells.
I'd like to be able to style a merged cell, however, my attempts to style it have no effect. Here is how I am merging the cells:
WorkSheet.Cells["A1:K1"].Merge = true;
Here is how I have tried to set the background and font color on this merged cell:
WorkSheet.Cells["A1:K1"].Style.Fill.PatternType = ExcelFillStyle.Solid;
WorkSheet.Cells["A1:K1"].Style.Fill.BackgroundColor.SetColor(Color.Black);
WorkSheet.Cells["A1:K1"].Style.Font.Color.SetColor(Color.Red);
Another way I have tried:
WorkSheet.Cells["A1"].Style.Fill.PatternType = ExcelFillStyle.Solid;
WorkSheet.Cells["A1"].Style.Fill.BackgroundColor.SetColor(Color.Black);
WorkSheet.Cells["A1"].Style.Font.Color.SetColor(Color.Red);
Yet another way I have tried:
WorkSheet.Cells[1, 1].Style.Fill.PatternType = ExcelFillStyle.Solid;
WorkSheet.Cells[1, 1].Style.Fill.BackgroundColor.SetColor(Color.Black);
WorkSheet.Cells[1, 1].Style.Font.Color.SetColor(Color.Red);
What am I missing here? I am able to style other cells that haven't been merged with no difficulty, but my merged cells won't change.
I can't reproduce the problem.. Here's an example of styling merged cells. See if you can find what you did wrong. All you have to do is run it.
Please let me know if you have any doubt.