I have this code to try to create a title bar:
worksheet.Cells["A32:D32"].Style.Font.Name = "Georgia"; worksheet.Cells["A32:D32"].Style.Font.Bold = true; worksheet.Cells["A32:D32"].Style.Font.Size = 16; worksheet.Cells["A32:D32"].Style.Fill.PatternType = ExcelFillStyle.Solid; worksheet.Cells["A32:D33"].Style.Fill.BackgroundColor.SetColor(Color.CornflowerBlue);
It does not work in the last line above with "System.ArgumentException was unhandled..Message = Unable to set color if patterntype is not set. Source = EPPlus.,."
What could be the real problem? I do what I do, I'm wrong, right?
For more context:
worksheet.Cells["A32"].LoadFromCollection(bookDataList, true); // style header row worksheet.Cells["A32:D32"].Style.Font.Name = "Georgia"; worksheet.Cells["A32:D32"].Style.Font.Bold = true; worksheet.Cells["A32:D32"].Style.Font.Size = 16; worksheet.Cells["A32:D32"].Style.Fill.PatternType = ExcelFillStyle.Solid; worksheet.Cells["A32:D33"].Style.Fill.BackgroundColor.SetColor(Color.CornflowerBlue); // style the rest worksheet.Cells["A33:D59"].Style.Font.Name = "Candara"; worksheet.Cells["A33:D59"].Style.Fill.PatternType = ExcelFillStyle.Solid; worksheet.Cells["A33:D59"].Style.Fill.BackgroundColor.SetColor(Color.Cornsilk);
Please note that before adding the style header line, I used the βstyle for the restβ code and did not encounter this problem. The code is exactly the same as for setting PatternType and then BackgroundColor (except for the color used and the range of cells to which the code applies).
c # excel epplus epplus-4
B. Clay Shannon
source share