Back to Devexpress

XlBorder Class

corelibraries-devexpress-dot-export-dot-xl-991382b2.md

latest8.5 KB
Original Source

XlBorder Class

Provides access to the line characteristics of a cell border.

Namespace : DevExpress.Export.Xl

Assembly : DevExpress.Printing.v25.2.Core.dll

NuGet Package : DevExpress.Printing.Core

Declaration

csharp
public class XlBorder :
    XlBordersBase,
    ISupportsCopyFrom<XlBorder>
vb
Public Class XlBorder
    Inherits XlBordersBase
    Implements ISupportsCopyFrom(Of XlBorder)

The following members return XlBorder objects:

Remarks

The XlBorder class inherits from the XlBordersBase class, which provides properties used to define border line style options (XlBordersBase.BottomLineStyle, XlBordersBase.TopLineStyle, XlBordersBase.LeftLineStyle, XlBordersBase.RightLineStyle, etc.). In addition to the inherited settings, the XlBorder class exposes properties and methods which allow you to define the color of a particular border (XlBorder.BottomColor, XlBorder.TopColor, XlBorder.LeftColor, XlBorder.RightColor, etc.), or set all outside borders of a cell at once (XlBorder.AllBorders or XlBorder.OutlineBorders).

To set a particular cell border, create an instance of the XlBorder class, and then specify the line style and color of the required border by using the corresponding properties of the XlBorder object.

To apply border settings to a cell, assign the specified XlBorder object to the IXlCell.Formatting property, or pass it to the IXlCell.ApplyFormatting method as a parameter.

To share border settings with multiple adjacent cells in a row at once, use the IXlRow.BlankCells or IXlRow.BulkCells method.

To set borders for the entire row or column, use the IXlRow.ApplyFormatting and IXlColumn.ApplyFormatting methods, or IXlRow.Formatting and IXlColumn.Formatting properties, respectively.

For an example, refer to the How to: Add Cell Borders article.

Example

Note

A complete sample project is available at https://github.com/DevExpress-Examples/excel-export-api-examples

csharp
// Specify a two-dimensional array that stores possible line styles for a border. 
XlBorderLineStyle[,] lineStyles = new XlBorderLineStyle[,] {
            { XlBorderLineStyle.Thin, XlBorderLineStyle.Medium, XlBorderLineStyle.Thick, XlBorderLineStyle.Double },
            { XlBorderLineStyle.Dotted, XlBorderLineStyle.Dashed, XlBorderLineStyle.DashDot, XlBorderLineStyle.DashDotDot },
            { XlBorderLineStyle.SlantDashDot, XlBorderLineStyle.MediumDashed, XlBorderLineStyle.MediumDashDot, XlBorderLineStyle.MediumDashDotDot }
        };

// Create an exporter instance.
IXlExporter exporter = XlExport.CreateExporter(documentFormat);
// Create a new document.
using(IXlDocument document = exporter.CreateDocument(stream)) {
    document.Options.Culture = CultureInfo.CurrentCulture;
    // Create a worksheet.
    using(IXlSheet sheet = document.CreateSheet()) {
        for(int i = 0; i < 3; i++) {
            sheet.SkipRows(1);
            // Create a worksheet row.
            using(IXlRow row = sheet.CreateRow()) {
                for(int j = 0; j < 4; j++) {
                    row.SkipCells(1);
                    // Create a new cell in the row.
                    using(IXlCell cell = row.CreateCell()) {
                        // Set outside borders for the created cell using a particular line style from the lineStyles array.
                        cell.ApplyFormatting(XlBorder.OutlineBorders(Color.SeaGreen, lineStyles[i, j]));
                    }
                }
            }
        }
    }
}
vb
' Specify a two-dimensional array that stores possible line styles for a border. 
Dim lineStyles(,) As XlBorderLineStyle = { _
    { XlBorderLineStyle.Thin, XlBorderLineStyle.Medium, XlBorderLineStyle.Thick, XlBorderLineStyle.Double }, _
    { XlBorderLineStyle.Dotted, XlBorderLineStyle.Dashed, XlBorderLineStyle.DashDot, XlBorderLineStyle.DashDotDot }, _
    { XlBorderLineStyle.SlantDashDot, XlBorderLineStyle.MediumDashed, XlBorderLineStyle.MediumDashDot, XlBorderLineStyle.MediumDashDotDot } _
}

' Create an exporter instance.
Dim exporter As IXlExporter = XlExport.CreateExporter(documentFormat)
' Create a new document.
Using document As IXlDocument = exporter.CreateDocument(stream)
    document.Options.Culture = CultureInfo.CurrentCulture
    ' Create a worksheet.
    Using sheet As IXlSheet = document.CreateSheet()
        For i As Integer = 0 To 2
            sheet.SkipRows(1)
            ' Create a worksheet row.
            Using row As IXlRow = sheet.CreateRow()
                For j As Integer = 0 To 3
                    row.SkipCells(1)
                    ' Create a new cell in the row.
                    Using cell As IXlCell = row.CreateCell()
                        ' Set outside borders for the created cell using a particular line style from the lineStyles array.
                        cell.ApplyFormatting(XlBorder.OutlineBorders(Color.SeaGreen, lineStyles(i, j)))
                    End Using
                Next j
            End Using
        Next i
    End Using
End Using

Inheritance

Object XlBordersBase XlBorder

See Also

XlBorder Members

Use the Excel Export API to Add Cell Borders

DevExpress.Export.Xl Namespace