首页 文章

如何在EPPlus中设置整列的样式?

提问于
浏览
7

是否可以在EPPlus中为整列设置样式?我希望我可以使用 Column 方法,但是当我这样做时,我会得到奇怪的结果:

//Sets all cells in all columns to Red
worksheet.Column(1).Style.Font.Color.SetColor(Color.Red);

//Sets some cells in column B to red.
worksheet.Column(2).Style.Font.Color.SetColor(Color.Red);

在这两种情况下,我在添加一些 Headers 行之后设置颜色,但在添加大量行之前,我没有在其他地方设置颜色 . 我也得到了类似的意外结果设置水平对齐 . 目前我不得不在单元格级别设置样式 .

我使用不正确还是这个错误?使用EPPlus 3.1.2.0和Excel 2010(14.0.6129.5000) .

2 回答

  • 6

    尝试使用范围;我也遇到了使用数字的问题 .

    //Get the final row for the column in the worksheet
    int finalrows = worksheet.dimension.End.Row;
    
    //Convert into a string for the range.
    string ColumnString = "A1:A" + finalrows.ToString();
    
    //Convert the range to the color Red
    worksheet.Cells[ColumnString].Style.Font.Color.SetColor(Color.Red);
    

    希望这有效,但我没试过 .

  • 6
    int indexOfColumn = ...;
     worksheet.Column(indexOfColumn).Style.Font.Color.SetColor(Color.Red);
    

相关问题