Apply ThemeColor Border to a Range

Range.SetInsideBorders, Range.SetOutlineBorder, and Range.SetOutlineBorders do not allow me to set a ThemeColor (or “Automatic” color) for borders.

I tried to use Range.ApplyStyle instead, but there is no way to set only Outline/Inside borders.

Is there any way to apply ThemeColor (or “Automatic” color borders to a range?

@bingxie,

See the following sample code on how to apply borders (having theme color) to a range of cells for your reference:
e.g.
Sample code:

           Workbook wb = new Workbook();
           Worksheet ws = wb.Worksheets[0];
           Range range1 = ws.Cells.CreateRange("B2", "G6");
           Style stl = wb.CreateStyle();
           stl.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
           stl.Borders[BorderType.TopBorder].ThemeColor = new ThemeColor(ThemeColorType.Accent1, 100);
           stl.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
           stl.Borders[BorderType.LeftBorder].ThemeColor = new ThemeColor(ThemeColorType.Accent4, 100);
           stl.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
           stl.Borders[BorderType.BottomBorder].ThemeColor = new ThemeColor(ThemeColorType.Accent1, 100);
           stl.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;
           stl.Borders[BorderType.RightBorder].ThemeColor = new ThemeColor(ThemeColorType.Accent2, 100);
           StyleFlag flg = new StyleFlag();
           flg.Borders = true;

           range1.ApplyStyle(stl, flg);



           wb.Save("e:\\test2\\out1style_test1.xlsx");

Hope, this helps a bit.

@Amjad_Sahi

Thanks for your response. I already tried this approach before posting, but it’s not possible to set only outer borders (without inner ones) through styles.

@bingxie,

We understand your needs as you want to apply outline borders (only with ThemeColor to a range. We will evaluate and may share a sample code segment for it. Alternatively, we might add some relevant overloads (if feasible) for the purpose. A ticket is logged with an id “CELLSNET-51910” for your issue into our database. We will look into it soon and may update you on it.

@bingxie,

This is to inform you that your issue has been resolved. The fix will be included in our upcoming release (Aspose.Cells v22.9) scheduled in the second week of September 2022. You will also be notified when the next version is released.

Thank you for the update.

@bingxie,

You are welcome.

The issues you have found earlier (filed as CELLSNET-51910) have been fixed in this update. This message was posted using Bugs notification tool by johnson.shi