相关疑难解决方法(0)

如何以编程方式设置单元格颜色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();
}
Run Code Online (Sandbox Code Playgroud)

c# asp.net epplus

24
推荐指数
2
解决办法
5万
查看次数

通过表达式EPPlus格式化条件

我正在使用带条件格式的EPPlus创建excel.我使用C#代码进行条件格式化,但它无法正常工作.

请检查我的下面的代码,让我知道我错在哪里:

ExcelPackage pck = new ExcelPackage();
var ws = pck.Workbook.Worksheets.Add("Sample1");
var _formatRangeAddress = new ExcelAddress("H16:K31,H33:K44,H46:K57,H59:K69,H71:K73");
string _statement = "=AND(COUNTA(H16:H16)<2,COUNTA(H16:K16)>0)";
var _cond4 = ws.ConditionalFormatting.AddExpression(_formatRangeAddress);
_cond4.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
_cond4.Style.Fill.BackgroundColor.Color = Color.Green;
_cond4.Formula = _statement;
pck.SaveAs(Response.OutputStream);
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", "attachment;  filename=Sample1.xlsx");
Run Code Online (Sandbox Code Playgroud)

c# asp.net visual-studio-2010 epplus

7
推荐指数
2
解决办法
2182
查看次数

如何使用epplus在值大于特定常量值的单元格上添加条件格式

我已经以编程方式制作了一张excel表.现在我想在特定的单元格范围上添加条件格式.

格式化类型是所有单元格 values greater than 0 (>0)

怎么去做呢?在excel中,我可以使用内置公式来实现Cell Values Greater Than.但是如何使用C#和epplus将它嵌入excel?

c# excel epplus

2
推荐指数
1
解决办法
3485
查看次数

标签 统计

c# ×3

epplus ×3

asp.net ×2

excel ×1

visual-studio-2010 ×1