【问题标题】:change cell color in ClosedXML while exporting sql data to excel在将 sql 数据导出到 excel 时更改 ClosedXML 中的单元格颜色
【发布时间】:2019-12-18 06:11:56
【问题描述】:

我需要根据某些条件更改特定单元格的颜色。我已经将整个表从 MySQL 导出到 Excel,导出到 Excel 后我想更改 Excel 文件中的单元格颜色。 我在 C#.NET 中使用 ClosedXML 库导出到 Excel。


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

            }


        }

【问题讨论】:

标签: c# closedxml


【解决方案1】:

试试这个,

ws.Row(6).Style.Fill.BackgroundColor = XLColor.Blue
ws.Column("E").Style.Fill.BackgroundColor = XLColor.Blue;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-09
    • 2012-01-23
    • 1970-01-01
    • 2017-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多