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

XlBorder.OutlineBorders(XlColor, XlBorderLineStyle) Method

Returns the XlBorder object that specifies the outside borders of a cell.

Namespace: DevExpress.Export.Xl

Assembly: DevExpress.Printing.v19.1.Core.dll

Declaration

public static XlBorder OutlineBorders(
    XlColor color,
    XlBorderLineStyle lineStyle
)

Parameters

Name Type Description
color XlColor

An XlColor object that defines the line color of borders.

lineStyle XlBorderLineStyle

An XlBorderLineStyle enumeration member that specifies the line style of borders.

Returns

Type Description
XlBorder

An XlBorder class instance.

Remarks

Use the OutlineBorders method to specify top, bottom, left and right borders around a cell in one step. If you need to set different formats for each outside border separately, use the corresponding *LineStyle and *Color properties of the XlBorder object.

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

For more information on how to set cell borders, refer to the How to: Add Cell Borders example.

Example

Note

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

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