Style border Excel using ClosedXML in C#
Asked Answered
H

2

7

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?

Haematogenesis answered 14/11, 2019 at 1:53 Comment(2)
ClosedXML documentation about borders are available at 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.Rounds
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;Haematogenesis
H
10

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;

Haematogenesis answered 19/11, 2019 at 9:28 Comment(0)
I
1

try this:

worksheet.Range(1,1,4,4).Style
          .Border.SetOutsideBorder(XLBorderStyleValues.Thin)
          .Border.SetInsideBorder(XLBorderStyleValues.Thin);
Ioved answered 9/8, 2023 at 6:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.