Mam ten kod, aby spróbować styl wiersz nagłówka..Dlaczego program EPPlus mówi mi, że "Nie mogę ustawić koloru, gdy nie ustawiono parametru patterntype", gdy ustawiłem PatternType?
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);
To nie w ostatnim wierszu powyżej z "System.ArgumentException był nieobsługiwany .Message = Nie można ustawić kolor, gdy patterntype nie jest ustawiony Źródło = EPPlus ... "
Co może być prawdziwym problemem? I am robi to, co twierdzi, że nie jestem, prawda?
Więcej kontekstu:
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);
Zauważ, że miałem „styl reszta” kod przed dodaniem „wiersz nagłówka w stylu” i nie napotkasz tego problemu. Kod jest dokładnie taki sam jak ustawienie PatternType, a następnie BackgroundColor (z wyjątkiem użytego koloru i zakresu komórek, do których stosuje się kod).
Brakowało tej linii: worksheet.Cells ["A32: D32"]. Style.Fill.PatternType = ExcelFillStyle.Solid; – Kadaj