XlCellFormatting.Themed(XlThemeColor, Double) Method
Creates the XlCellFormatting object that specifies themed formatting for a cell.
Namespace: DevExpress.Export.Xl
Assembly: DevExpress.Printing.v24.2.Core.dll
Declaration
Parameters
Name | Type | Description |
---|---|---|
themeColor | XlThemeColor | An XlThemeColor enumeration member that is one of the six Accent colors used to fill the cell background. If the themeColor is other than any of the theme accent colors, the System.ArgumentException occurs. |
tint | Double | A Double value from -1 to 1 used to darken (negative values) or lighten (positive values) the original theme color. If a value is outside the allowable range of values, the System.ArgumentOutOfRangeException will be thrown. |
Returns
Type | Description |
---|---|
XlCellFormatting | An XlCellFormatting class instance that contains theme formatting settings. |
Remarks
Use the Themed method to apply the predefined formatting to a cell that is based on the document theme. A document theme is a set of fonts, colors, and graphic effects you can apply to a workbook. The XlDocumentTheme enumeration lists the available document themes (currently, only Office themes are supported). The IXlDocument.Theme property allows you to set the theme of a workbook. By default, the Office 2013 theme is used.
If you use the Themed method to specify the theme-based formatting for a cell, the cell font will be automatically set to the body font of the current document theme (that is Calibri, 11 for Office themes). The font color depends on the cell background color: if the background color is dark or saturated (the tint value is less than 0.5), the font color will be set to the XlThemeColor.Light1 theme color; and if the background color is light and pale (the tint value is greater than or equal to 0.5), the XlThemeColor.Dark1 font color will be used.
To apply theme formatting settings to a cell, pass the XlCellFormatting object returned by the Themed method to the IXlCell.ApplyFormatting method as a parameter, or assign it to the IXlCell.Formatting property. For more information on how to format worksheet cells, refer to the How to: Format a Cell and How to: Apply Themed Formatting to a Cell topics.
Example
Note
A complete sample project is available at https://github.com/DevExpress-Examples/excel-export-api-examples
// Create a worksheet.
using(IXlSheet sheet = document.CreateSheet()) {
// Create six successive columns and set their widths.
for(int i = 0; i < 6; i++) {
using(IXlColumn column = sheet.CreateColumn()) {
column.WidthInPixels = 100;
}
}
// Specify an array that stores six accent colors of the document theme.
XlThemeColor[] themeColors = new XlThemeColor[] { XlThemeColor.Accent1, XlThemeColor.Accent2, XlThemeColor.Accent3, XlThemeColor.Accent4, XlThemeColor.Accent5, XlThemeColor.Accent6 };
// Specify the "20% - AccentN" themed cell formatting.
// Create a worksheet row.
using(IXlRow row = sheet.CreateRow()) {
for(int i = 0; i < 6; i++) {
// Create a new cell in the row.
using(IXlCell cell = row.CreateCell()) {
// Set the cell value.
cell.Value = string.Format("Accent{0} 20%", i + 1);
// Apply the themed formatting to the cell using one of the predefined accent colors lightened by 80%.
cell.Formatting = XlCellFormatting.Themed(themeColors[i], 0.8);
}
}
}
// Specify the "40% - AccentN" themed cell formatting.
// Create a worksheet row.
using(IXlRow row = sheet.CreateRow()) {
for(int i = 0; i < 6; i++) {
// Create a new cell in the row.
using(IXlCell cell = row.CreateCell()) {
// Set the cell value.
cell.Value = string.Format("Accent{0} 40%", i + 1);
// Apply the themed formatting to the cell using one of the predefined accent colors lightened by 60%.
cell.Formatting = XlCellFormatting.Themed(themeColors[i], 0.6);
}
}
}
// Specify the "60% - AccentN" themed cell formatting.
// Create a worksheet row.
using(IXlRow row = sheet.CreateRow()) {
for(int i = 0; i < 6; i++) {
// Create a new cell in the row.
using(IXlCell cell = row.CreateCell()) {
// Set the cell value.
cell.Value = string.Format("Accent{0} 60%", i + 1);
// Apply the themed formatting to the cell using one of the predefined accent colors lightened by 40%.
cell.Formatting = XlCellFormatting.Themed(themeColors[i], 0.4);
}
}
}
// Specify the "AccentN" themed cell formatting.
// Create a worksheet row.
using(IXlRow row = sheet.CreateRow()) {
for(int i = 0; i < 6; i++) {
// Create a new cell in the row.
using(IXlCell cell = row.CreateCell()) {
// Set the cell value.
cell.Value = string.Format("Accent{0}", i + 1);
// Apply the themed formatting to the cell using one of the predefined accent colors.
cell.Formatting = XlCellFormatting.Themed(themeColors[i], 0.0);
}
}
}
}