我想知道是否可以使用epplus以编程方式设置单元格颜色?
我从SQL存储过程中加载数据,它运行良好,但我的用户希望包含“年度休假”这些单词的单元格具有浅黄色的背景颜色,而不是默认的白色。有没有办法做到这一点?也许通过迭代Datatable?下面是相关代码:
public void ExportTableData(DataTable dtdata)
{
//Using EPPLUS to export Spreadsheets
ExcelPackage pck = new ExcelPackage();
var ws = pck.Workbook.Worksheets.Add("Availability list");
ws.Cells["A1"].LoadFromDataTable(dtdata, true);
ws.Cells["A1:G1"].Style.Font.Bold = true;
ws.Cells["A1:G1"].Style.Font.UnderLine = true;
//change cell color depending on the text input from stored proc?
if (dtdata.Rows[4].ToString() == "Annual Leave")
{
ws.Cells["E1"].Style.Fill.PatternType = ExcelFillStyle.Solid;
ws.Cells["E1"].Style.Fill.BackgroundColor.SetColor(Color.LightYellow);
}
pck.SaveAs(Response.OutputStream);
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", "attachment; filename=Availability.xlsx");
Response.End();
}