【问题标题】:How to color entire column in excel using c# in epplus?如何在 epplus 中使用 c# 为 excel 中的整个列着色?
【发布时间】:2016-12-13 20:33:03
【问题描述】:

我编写了一个代码,它为与单元格中的文本匹配的单个单元格着色,但我想为标题行中具有匹配文本的整个列着色

using System.Drawing;
using OfficeOpenXml;
using OfficeOpenXml.Style;
using System.IO;
namespace Project32
{
public class Class1
{
    public static void Main()
    {

        FileInfo newFile = new FileInfo(@"C:\Users\mvmurthy\Downloads\Template.xlsx");
        ExcelPackage pck = new ExcelPackage(newFile);
        var ws = pck.Workbook.Worksheets["ImportTemplate"];
        var start = ws.Dimension.Start;
        var end = ws.Dimension.End;
        for (int col = start.Column; col <= end.Column; col++)
        { // ... Cell by cell...
            if (ws.Cells[1, col].Text == "Tracking Numbers")
            {
                ws.Cells[1, col].Style.Fill.PatternType = ExcelFillStyle.Solid;
                ws.Cells[1, col].Style.Fill.BackgroundColor.SetColor(Color.Red);
            }
        }

        pck.Save();
    }
}

}

【问题讨论】:

标签: c# excel header string-matching epplus


【解决方案1】:

你可以这样做:

excelWorksheet.Column(i).Style.Fill.PatternType = ExcelFillStyle.Solid;
excelWorksheet.Column(i).Style.Fill.BackgroundColor.SetColor(ColorTranslator.FromHtml("#FF00CC"));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-04
    • 1970-01-01
    • 2013-04-24
    相关资源
    最近更新 更多