Skip to main content

XlFill.PatternFill(XlPatternType) Method

Creates the XlFill object that specifies the automatic pattern fill for a cell background.

Namespace: DevExpress.Export.Xl

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

NuGet Package: DevExpress.Printing.Core

Declaration

public static XlFill PatternFill(
    XlPatternType patternType
)

Parameters

Name Type Description
patternType XlPatternType

An XlPatternType enumeration member that is a preset type of the cell pattern fill.

Returns

Type Description
XlFill

An XlFill object that specifies the cell background fill.

Remarks

Use the PatternFill method to fill a cell with a repeated pattern defined by the XlPatternType enumeration value. Note that this method specifies only the type of the cell pattern without setting its color, so the cell background color will be empty and the pattern color will be set to automatic. However, you can use the XlFill.BackColor and XlFill.ForeColor properties to specify the background color and foreground color of the fill pattern.

To fill a cell background with a solid color, use the XlFill.SolidFill method. In this case, the XlFill.PatternType property value will be changed to XlPatternType.Solid.

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

For more information on how to specify the cell background color, refer to the How to: Change Cell Background Color article.

Example

Note

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

// Create a new worksheet.
using(IXlSheet sheet = document.CreateSheet()) {

    using(IXlRow row = sheet.CreateRow()) {
        using(IXlCell cell = row.CreateCell()) {
            // Fill the cell background using the predefined color.
            cell.ApplyFormatting(XlFill.SolidFill(Color.Beige));
        }
        using(IXlCell cell = row.CreateCell()) {
            // Fill the cell background using the custom RGB color.
            cell.ApplyFormatting(XlFill.SolidFill(Color.FromArgb(0xff, 0x99, 0x66)));
        }
        using(IXlCell cell = row.CreateCell()) {
            // Fill the cell background using the theme color.
            cell.ApplyFormatting(XlFill.SolidFill(XlColor.FromTheme(XlThemeColor.Accent3, 0.4)));
        }
    }

    using(IXlRow row = sheet.CreateRow()) {
        using(IXlCell cell = row.CreateCell()) {
            // Specify the cell background pattern using predefined colors.
            cell.ApplyFormatting(XlFill.PatternFill(XlPatternType.DarkDown, Color.Red, Color.White));
        }
        using(IXlCell cell = row.CreateCell()) {
            // Specify the cell background pattern using custom RGB colors.
            cell.ApplyFormatting(XlFill.PatternFill(XlPatternType.DarkTrellis, Color.FromArgb(0xff, 0xff, 0x66), Color.FromArgb(0x66, 0x99, 0xff)));
        }
        using(IXlCell cell = row.CreateCell()) {
            // Specify the cell background pattern using theme colors.
            cell.ApplyFormatting(XlFill.PatternFill(XlPatternType.LightHorizontal, XlColor.FromTheme(XlThemeColor.Accent1, 0.2), XlColor.FromTheme(XlThemeColor.Light2, 0.0)));
        }
    }
}
See Also