为什么当我设置PatternType时,EPPlus告诉我"当没有设置patterntype时无法设置颜色"?

B. *_*non 17 c# excel epplus epplus-4

我有这个代码来尝试设置标题行的样式:

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);
Run Code Online (Sandbox Code Playgroud)

它在上面的最后一行失败," System.ArgumentException未处理.Message =未设置patterntype时无法设置颜色.来源= EPPlus ... "

真正的问题是什么?我正在做的事情我不是,对吧?

更多背景信息:

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);
Run Code Online (Sandbox Code Playgroud)

请注意,在添加"样式标题行"之前,我有"样式其余"代码,并且没有遇到此问题.代码与设置PatternType然后设置BackgroundColor完全相同(使用的颜色除外,以及应用代码的单元格范围除外).

Ern*_*e S 26

仔细看看这两行:

worksheet.Cells["A32:D32"].Style.Fill.PatternType = ExcelFillStyle.Solid;
worksheet.Cells["A32:D33"].Style.Fill.BackgroundColor.SetColor(Color.CornflowerBlue);
Run Code Online (Sandbox Code Playgroud)

第二行有D33而不是D32,所以如果D33没有设置,它会抛出该错误.