【问题标题】:How to hide grid lines for one column using epplus如何使用epplus隐藏一列的网格线
【发布时间】:2019-07-21 05:01:00
【问题描述】:
WorkSheet.View.ShowGridLines = false;

这将在完整的 excel 中隐藏网格线。

【问题讨论】:

标签: c# .net epplus


【解决方案1】:

AFAIK,网格线仅适用于整个工作表,无论是在视图、打印或两者中。我认为您在谈论Border 设置。你会做这样的事情:

[TestMethod]
public void Column_Border()
{
    var datatable = new DataTable("tblData");
    datatable.Columns.AddRange(new DataColumn[] {
        new DataColumn("Col0", typeof(object)),
        new DataColumn("Col1", typeof(int)),
        new DataColumn("Col2", typeof(int)),
        new DataColumn("Col3", typeof(object))
    });
    for (int i = 0; i < 10; i++)
    {
        var row = datatable.NewRow();
        row[0] = Path.GetRandomFileName();
        row[1] = i;
        row[2] = i * 10;
        row[3] = Path.GetRandomFileName();
        datatable.Rows.Add(row);
    }
    var fi = new FileInfo("c:\\temp\\Column_Border.xlsx");
    if (fi.Exists)
        fi.Delete();

    using (ExcelPackage pck = new ExcelPackage(fi))
    {
        var WorkSheet = pck.Workbook.Worksheets.Add("source");
        WorkSheet.Cells["A1"].LoadFromDataTable(datatable, true);
        WorkSheet.View.ShowGridLines = false;

        var allCells = WorkSheet.Cells;
        allCells.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
        allCells.Style.Border.Top.Style = ExcelBorderStyle.Thin;
        allCells.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
        allCells.Style.Border.Left.Style = ExcelBorderStyle.Thin;
        allCells.Style.Border.Right.Style = ExcelBorderStyle.Thin;

        allCells.Style.Border.Top.Color.SetColor(Color.Green);
        allCells.Style.Border.Bottom.Color.SetColor(Color.Green);
        allCells.Style.Border.Left.Color.SetColor(Color.Green);
        allCells.Style.Border.Right.Color.SetColor(Color.Green);

        var colRange2 = WorkSheet.Column(2);
        colRange2.Style.Border.Top.Style = ExcelBorderStyle.None;
        colRange2.Style.Border.Bottom.Style = ExcelBorderStyle.None;
        colRange2.Style.Border.Left.Style = ExcelBorderStyle.None;
        colRange2.Style.Border.Right.Style = ExcelBorderStyle.None;

        pck.Save();
    }
}

给你这个:

【讨论】:

    猜你喜欢
    • 2015-11-13
    • 1970-01-01
    • 2014-04-29
    • 1970-01-01
    • 2019-12-24
    • 2012-02-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多