我需要根据某些条件更改特定单元格的颜色。我已经将整个表格从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);
}
}发布于 2019-12-18 20:29:56
尝尝这个,
ws.Row(6).Style.Fill.BackgroundColor = XLColor.Blue
ws.Column("E").Style.Fill.BackgroundColor = XLColor.Blue;https://stackoverflow.com/questions/59386370
复制相似问题