Back to Devexpress

XlFill Class

corelibraries-devexpress-dot-export-dot-xl-c69ba315.md

latest6.2 KB
Original Source

XlFill Class

Contains the cell background attributes.

Namespace : DevExpress.Export.Xl

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

NuGet Package : DevExpress.Printing.Core

Declaration

csharp
public class XlFill :
    ISupportsCopyFrom<XlFill>
vb
Public Class XlFill
    Implements ISupportsCopyFrom(Of XlFill)

The following members return XlFill objects:

Remarks

The XlFill object provides a set of static methods that you can use to customize the cell background. The XlFill.SolidFill method specifies the cell background color, while the XlFill.PatternFill specifies the type of cell background pattern (the XlPatternType enumeration lists the available pattern types, and XlFill.ForeColor and XlFill.BackColor specify the foreground and background colors of pattern fill).

For an example on how to fill the cell background, 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

csharp
// 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)));
        }
    }
}
vb
' Create a new worksheet.
Using sheet As IXlSheet = document.CreateSheet()

    Using row As IXlRow = sheet.CreateRow()
        Using cell As IXlCell = row.CreateCell()
            ' Fill the cell background using the predefined color.
            cell.ApplyFormatting(XlFill.SolidFill(Color.Beige))
        End Using
        Using cell As IXlCell = row.CreateCell()
            ' Fill the cell background using the custom RGB color.
            cell.ApplyFormatting(XlFill.SolidFill(Color.FromArgb(&Hff, &H99, &H66)))
        End Using
        Using cell As IXlCell = row.CreateCell()
            ' Fill the cell background using the theme color.
            cell.ApplyFormatting(XlFill.SolidFill(XlColor.FromTheme(XlThemeColor.Accent3, 0.4)))
        End Using
    End Using

    Using row As IXlRow = sheet.CreateRow()
        Using cell As IXlCell = row.CreateCell()
            ' Specify the cell background pattern using predefined colors.
            cell.ApplyFormatting(XlFill.PatternFill(XlPatternType.DarkDown, Color.Red, Color.White))
        End Using
        Using cell As IXlCell = row.CreateCell()
            ' Specify the cell background pattern using custom RGB colors.
            cell.ApplyFormatting(XlFill.PatternFill(XlPatternType.DarkTrellis, Color.FromArgb(&Hff, &Hff, &H66), Color.FromArgb(&H66, &H99, &Hff)))
        End Using
        Using cell As IXlCell = 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)))
        End Using
    End Using
End Using

Inheritance

Object XlFill

See Also

XlFill Members

Use the Excel Export API to Change Cell Background Color

DevExpress.Export.Xl Namespace