4

I have a table data in Excel

enter image description here

I want to apply style broder as image enter image description here

How to code script in C# using ClosedXML?

Ly Thanh Ngo
  • 394
  • 1
  • 2
  • 15
  • 2
    ClosedXML documentation about borders are available at https://github.com/ClosedXML/ClosedXML/wiki/Styles-Border . I want to urge you to read through all the ClosedXML documentation. It will answer a lot of questions that you will encounter as you learn ClosedXML. – Francois Botha Nov 18 '19 at 12:57
  • ws.Range("A1:D4").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right; ws.Range("A1:D4").Style.Border.TopBorder = XLBorderStyleValues.Thin; ws.Range("A1:D4").Style.Border.InsideBorder = XLBorderStyleValues.Dotted; ws.Range("A1:D4").Style.Border.OutsideBorder = XLBorderStyleValues.Thin; ws.Range("A1:D4").Style.Border.LeftBorder = XLBorderStyleValues.Thin; ws.Range("A1:D4").Style.Border.RightBorder = XLBorderStyleValues.Thin; ws.Range("A1:D4").Style.Border.TopBorder = XLBorderStyleValues.Thin; – Ly Thanh Ngo Nov 19 '19 at 00:53

2 Answers2

8

Thank @Francois Botha! I try it and it work. :)

ws.Range("A1:D4").Style.Border.TopBorder = XLBorderStyleValues.Thin; ws.Range("A1:D4").Style.Border.InsideBorder = XLBorderStyleValues.Dotted; ws.Range("A1:D4").Style.Border.OutsideBorder = XLBorderStyleValues.Thin; ws.Range("A1:D4").Style.Border.LeftBorder = XLBorderStyleValues.Thin; ws.Range("A1:D4").Style.Border.RightBorder = XLBorderStyleValues.Thin; ws.Range("A1:D4").Style.Border.TopBorder = XLBorderStyleValues.Thin;

Ly Thanh Ngo
  • 394
  • 1
  • 2
  • 15
0

try this:

worksheet.Range(1,1,4,4).Style
          .Border.SetOutsideBorder(XLBorderStyleValues.Thin)
          .Border.SetInsideBorder(XLBorderStyleValues.Thin);
khaled saleh
  • 470
  • 7
  • 18