我想知道是否可以使用epplus以编程方式设置单元格颜色?如何以编程方式设置单元格颜色epplus?
我从sql存储过程加载我的数据,它运行良好,但我的用户希望 包含单词'年假'的单元格具有淡黄色而不是默认白色的背景颜色。有没有办法做到这一点?也许通过迭代数据表可能?下面是其中
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();
}
那么,什么不与你在这里工作?抱歉没有看到明确的问题。 – workabyte 2015-02-23 17:29:22
基本上我有一列可以包含“年假”,“可用”,“生病”,“退休”等数据,并根据此文本我想以编程方式更改包含单元格的颜色。例如,如果表示“年假”,则为淡黄色,只要包含“可用”等等,则表示绿色单元格。目前它没有改变颜色 – wubblyjuggly 2015-02-23 17:32:11
所以你有什么^不工作?它在做什么?完全理解期望的结果,但是阻止你到达那里的是什么? – workabyte 2015-02-23 17:33:24