XlColor Class
Represents a color used in the spreadsheet document.
Namespace: DevExpress.Export.Xl
Assembly: DevExpress.Printing.v24.1.Core.dll
NuGet Package: DevExpress.Printing.Core
Declaration
Related API Members
The following members return XlColor objects:
Remarks
The XlColor object can be used in the following cases:
- To perform direct cell formatting: change the color of the cell background (XlFill.SolidFill and XlFill.PatternFill) and cell font (XlFont.Color), or set the border line color (XlBorder.TopColor, XlBorder.BottomColor, XlBorder.LeftColor, XlBorder.RightColor, etc.).
- To apply conditional formatting to worksheet cells (IXlSheet.ConditionalFormattings).
- To specify the color of sparkline elements (IXlSheet.SparklineGroups).
Excel Export API supports implicit conversion between the XlColor class and the Color structure, so that you can utilize predefined system-defined colors obtained by using the corresponding static properties of the Color structure to set the color of spreadsheet elements. To create a custom color from the RGB component values, use the static XlColor.FromArgb method of the XlColor class or the Color structure. To define a new color based on one of the theme colors, utilize the static XlColor.FromTheme method.
The example below demonstrates how to specify a solid and pattern fill of the cell background.
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)));
}
}
}