[英]How to Change Excel Cell Color Dynamically using C#
使用下面的鏈接,我可以遍歷行並獲得准確的單元格,但無法設置其顏色。 請看下面的代碼。
使用EPPLUS導出excel時,如何根據值動態設置列數據的前景色?
var costStructureReport = new
{
CurrentQuotation = rptCostStructure.GetCostStructureReport()
};
var reportEngine = new ReportEngine();
string fileName = reportEngine.ProcessReport(ReportNames.ProjectDownload_Template, reportname + ".xlsx", costStructureReport);
var ep = new ExcelPackage(new FileInfo(fileName));
var sheet1 = ep.Workbook.Worksheets["SPR_ProjectDownload"];
var row = sheet1.Dimension.End.Row;
for(int i=0;i< costStructureReport.CurrentQuotation.Count;i++)
{
if (costStructureReport.CurrentQuotation[i].MaterialCost_ByUser)
{
sheet1.Cells[i+2, 2].Style.Font.Color.SetColor(System.Drawing.Color.Red);
sheet1.Cells[i + 2, 12].Style.Font.Color.SetColor(System.Drawing.Color.Red);
sheet1.Cells[i + 2, 12].Style.Font.Bold = true;
}
}
您可以使用更改文本顏色
[RangeObject].Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);
和字體顏色使用
[RangeObject].Interior.Color =System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.