This project has moved. For the latest updates, please go here.

Set border on a range

Apr 28, 2010 at 10:39 AM


Great job on the EPPlus library Jan.


I've been trying to set border on an ExcelRange, but I'm probably doing something wrong.

Should this work? If not, how could this be done?

using (ExcelRange range = ws.Cells[rowIndex, 1, rowCount, 57])
    range.Style.Border.Top.Style = ExcelBorderStyle.Thin;

Any help appreciated.


Apr 28, 2010 at 11:06 AM

After a little more testing this works fine:

ws.Cells["A1:A10"].Style.Border.Top.Style = ExcelBorderStyle.Thin;


Apr 28, 2010 at 11:10 AM

Have a look at sample 6.

Something like this...

            //Set a border around
            ws.Cells["A1:A43"].Style.Border.Left.Style = ExcelBorderStyle.Thin;
            ws.Cells["A1:O1"].Style.Border.Top.Style = ExcelBorderStyle.Thin;
            ws.Cells["O1:O43"].Style.Border.Right.Style = ExcelBorderStyle.Thin;
            ws.Cells["A43:O43"].Style.Border.Bottom.Style = ExcelBorderStyle.Thin;


Apr 28, 2010 at 11:16 AM

Thanks Jan. Found sample 6 :)