Skip to main content

XlBorder.OutlineBorders(XlColor) Method

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

Namespace: DevExpress.Export.Xl

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

NuGet Package: DevExpress.Printing.Core

Declaration

public static XlBorder OutlineBorders(
    XlColor color
)

Parameters

Name Type Description
color XlColor

An XlColor object that defines the line color 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. Note that this method specifies only the color of outside borders without setting their line style, so the border line style will be automatically set to XlBorderLineStyle.Thin.

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/excel-export-api-examples

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

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the OutlineBorders(XlColor) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also