Skip to main content
A newer version of this page is available. .

XlFormatting.Font Property

Gets or sets font settings to be applied to the cell content.

Namespace: DevExpress.Export.Xl

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

Declaration

public XlFont Font { get; set; }

Property Value

Type Description
XlFont

An XlFont object that specifies cell font attributes.

Remarks

To specify the font characteristics of the cell content, use the Font property of the XlCellFormatting object, which controls the format settings of worksheet cells. The XlFont object provides a set of properties that you can use to set different font attributes (XlFontBase.Name, XlFontBase.Size, XlFontBase.Bold, XlFontBase.Italic, XlFont.Color, etc.).

To apply font characteristics to a cell, assign the specified XlCellFormatting instance to the IXlCell.Formatting property or pass it to the IXlCell.ApplyFormatting method as a parameter, as shown in the example below. Note that the XlCellFormatting object supports implicit conversion from the XlFont object, so that you can directly apply font settings to a cell without using unnecessary cast operators. For more information on how to set different characteristics of a cell font, refer to the How to: Configure Cell Font Settings topic.

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);
            }
        }
    }
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the Font property.

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.

See Also