XlFill.PatternFill(XlPatternType, XlColor, XlColor) Method
Creates the XlFill object that specifies the pattern fill for a cell background.
Namespace: DevExpress.Export.Xl
Assembly: DevExpress.Printing.v23.2.Core.dll
NuGet Package: DevExpress.Printing.Core
Declaration
public static XlFill PatternFill(
XlPatternType patternType,
XlColor backColor,
XlColor patternColor
)
Parameters
Name | Type | Description |
---|---|---|
patternType | XlPatternType | An XlPatternType enumeration member that is a preset type of the cell pattern fill. |
backColor | XlColor | An XlColor object that specifies the background color of the pattern fill. |
patternColor | XlColor | An XlColor object that specifies the foreground color of the 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. You can also use the XlFill.PatternType, XlFill.BackColor and XlFill.ForeColor properties of the XlFill object to control the cell pattern characteristics.
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)));
}
}
}
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the PatternFill(XlPatternType, XlColor, 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.