我想知道是否可以使用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