IXlCell.ApplyFormatting(XlCellFormatting) Method
Applies the specified formatting settings to the cell.
Namespace: DevExpress.Export.Xl
Assembly: DevExpress.Printing.v24.2.Core.dll
Declaration
Parameters
Name | Type | Description |
---|---|---|
formatting | XlCellFormatting | An XlCellFormatting object that specifies format characteristics to be applied to the cell. |
Remarks
The XlCellFormatting object provides a set of properties and methods to change cell format settings.
- To format a cell using the predefined format settings corresponding to one of the Microsoft® Excel® styles, use static properties of the XlCellFormatting class (XlCellFormatting.Bad, XlCellFormatting.Good, XlCellFormatting.Neutral, etc.).
- To apply a predefined formatting that is based on the current document theme, use the XlCellFormatting.Themed method.
- To specify the custom formatting options for a cell, use properties inherited from the XlFormatting class: XlFormatting.Fill, XlFormatting.Font, XlFormatting.Alignment, XlFormatting.Border and XlFormatting.NumberFormat. Moreover, the XlCellFormatting object implements implicit conversion from the XlFill, XlFont, XlCellAlignment, XlBorder and XlNumberFormat objects, so that you can directly pass an object specifying the required format characteristics to the ApplyFormatting method without using unnecessary cast operators.
For more information on how to format cells in a worksheet, see the How to: Format a Cell document and the Formatting section of examples.
Example
// Create a new document and begin to write it to the specified stream.
using (IXlDocument document = exporter.CreateDocument(stream)) {
// Specify formatting settings to be applied to document content.
XlCellFormatting formatting = new XlCellFormatting();
// Specify cell background color.
formatting.Fill = XlFill.SolidFill(XlColor.FromArgb(0xCE, 0x8B, 0xDA));
// Specify font settings (font name, color, size and style).
formatting.Font = new XlFont();
formatting.Font.Name = "MV Boli";
formatting.Font.SchemeStyle = XlFontSchemeStyles.None;
formatting.Font.Size = 16;
formatting.Font.Color = Color.Wheat;
formatting.Font.Bold = true;
// Specify the alignment of cell content.
formatting.Alignment = XlCellAlignment.FromHV(XlHorizontalAlignment.Center, XlVerticalAlignment.Center);
// Specify outside border settings.
formatting.Border = XlBorder.OutlineBorders(XlColor.FromArgb(0x47, 0x7B, 0xD1), XlBorderLineStyle.Thick);
// Create a new worksheet.
using (IXlSheet sheet = document.CreateSheet()) {
// Create the first column and set its width.
using (IXlColumn column = sheet.CreateColumn())
column.WidthInPixels = 180;
// Create the first row in the worksheet.
using (IXlRow row = sheet.CreateRow()){
// Create a cell and specify its format settings.
using (IXlCell cell = row.CreateCell())
{
cell.Value = "Custom Format";
cell.ApplyFormatting(formatting);
}
}
}
}
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the ApplyFormatting(XlCellFormatting) 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.