gpt4 book ai didi

c# - 为什么 EPPlus 告诉我 "Can' t set color when patterntype is not set"当我设置了 PatternType 时?

转载 作者:可可西里 更新时间:2023-11-01 07:44:02 31 4
gpt4 key购买 nike

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

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);

它在上面的最后一行失败,显示“System.ArgumentException was unhandled...Message=Can't set color when patterntype is not set. 来源=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);

请注意,我在添加“样式标题行”之前使用了“其余样式”代码,但没有遇到此问题。该代码与设置 PatternType 和 BackgroundColor 完全相同(除了使用的颜色和应用代码的单元格范围)。

最佳答案

仔细看这两行:

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

第二行有 D33 而不是 D32 所以如果 D33 还没有设置它会抛出那个错误。

关于c# - 为什么 EPPlus 告诉我 "Can' t set color when patterntype is not set"当我设置了 PatternType 时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38665741/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com