Free Support Forum -

Pb making borders of a range selection


I’m trying to set the borders of a range selection.

My code looks like this :

Aspose.Excel.Range range = sheet.Cells.CreateRange(“A1”,"A10);
range.Style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;

But, it seems that range.Style.Borders is null : I get a null pointer exception.
It works ok when I set a single cell border type.

Where am I wrong ?

Hi Laurent,

Please refer to and

If you want to set the outline border of a range, please user SetOutlineBorder method. If you want to set borders for each cell of a range, please try the following code:

int styleIndex = excel.Styles.Add();
Aspose.Excel.Style style = excel.Styles[styleIndex];
style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
range.Style = style;