We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Query on Aspose set all borders of range of cells

Hi,

We are using Aspose.cells version 4.8.2.3

We need to set borders of excel sheet (having data) to "ALL BORDER" border style provided by MS Excel.

Other than looping and setting each border of cell (setting right,left,top and bottom) Do we have any other alternative solution?

Thanks,

Sourav

Hi,

Yes, you may do it with ease, see the sample code below for your reference:
Workbook workbook = new Workbook();
Cells cells = workbook.Worksheets[0].Cells;


//apply style to a range of cells.
Range range = cells.CreateRange(“B2”, “M52”);
Style stl = workbook.Styles[workbook.Styles.Add()];
stl.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
stl.Borders[BorderType.TopBorder].Color = Color.Blue;
stl.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
stl.Borders[BorderType.LeftBorder].Color = Color.Blue;
stl.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
stl.Borders[BorderType.BottomBorder].Color = Color.Blue;
stl.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;
stl.Borders[BorderType.RightBorder].Color = Color.Blue;
StyleFlag flg = new StyleFlag();
flg.Borders = true;

range.ApplyStyle(stl, flg);

workbook.Save(“e:\test\rangeborders.xls”);


Thank you.