Skip to main content
A newer version of this page is available. .

XlBorder Class

Provides access to the line characteristics of a cell border.

Namespace: DevExpress.Export.Xl

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

NuGet Packages: DevExpress.Printing.Core, DevExpress.WindowsDesktop.Printing.Core

Declaration

public class XlBorder :
    XlBordersBase,
    ISupportsCopyFrom<XlBorder>

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

// 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]));
                    }
                }
            }
        }
    }
}

Inheritance

See Also