riya tiwary Ответов: 1

Изменение цвета ячейки в closedxml при экспорте данных SQL в excel


I need to change the color of a particular cell based on some conditions. I am already exporting whole table from MySQL to Excel, after exporting to Excel I want to change cell color in Excel file. I am using ClosedXML library in C#.NET for exporting to Excel.


Ошибка-
Severity	Code	Description	Project	File	Line	Suppression State
Error	CS1061	'XLColor' does not contain a definition for 'SetColor' and no accessible extension method 'SetColor' accepting a first argument of type 'XLColor' could be found (are you missing a using directive or an assembly reference?)	MailScheduler	


Severity	Code	Description	Project	File	Line	Suppression State
Error	CS0117	'Color' does not contain a definition for 'LightGreen'	MailScheduler	


Что я уже пробовал:

private void ExportDataSetToExcel(DataSet ds)
       {
           string[] paths = { Path.GetFullPath(@"..\..\"), "ExcelFiles" };
           string fullPath = Path.Combine(paths);
           string file = fullPath + "\\DataFile.xlsx";

           using (XLWorkbook wb = new XLWorkbook())
           {

               wb.Worksheets.Add(ds.Tables[0]);
               wb.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
               wb.Style.Font.Bold = true;
               wb.Style.Fill.BackgroundColor.SetColor(Color.LightGreen);
               wb.SaveAs(file);

           }


       }

1 Ответов

Рейтинг:
2

Maciej Los

Основанный на Документация ClosedXml[^] вы должны использовать один из них. ClosedXML Предопределенные Цвета[^], вместо стандартного цвета.

ws.Cell(++ro, 1).Style.Fill.BackgroundColor = XLColor.Red;


Удачи вам!