Skip to main content

XlFont.CustomFont(String, Double) Method

Creates the XlFont object that specifies a custom font with the given face name and size.

Namespace: DevExpress.Export.Xl

Assembly: DevExpress.Printing.v24.1.Core.dll

NuGet Package: DevExpress.Printing.Core

Declaration

public static XlFont CustomFont(
    string fontName,
    double size
)

Parameters

Name Type Description
fontName String

A String value that specifies the font name.

size Double

A Double value that specifies the font size in points.

Returns

Type Description
XlFont

An XlFont class instance that is the custom font with specified characteristics.

Remarks

Use the static CustomFont methods to create the XlFont class instance with the specified font attributes (font name, size and/or color). To apply this font to cell content, assign the XlFont object to the IXlCell.Formatting property or pass it to the IXlCell.ApplyFormatting method as a parameter, as shown in the example below.

using (IXlSheet sheet = document.CreateSheet()) {
    // Create the first row in the worksheet.
    using (IXlRow row = sheet.CreateRow()){
        // Create the first cell in the row.
        using (IXlCell cell = row.CreateCell())
        {
            // Set the cell value.
            cell.Value = "Custom font";
            // Specify the custom font attributes.
            XlFont font = XlFont.CustomFont("Century Gothic", 14, Color.DeepSkyBlue);
            font.Bold = true;
            // Apply the custom font to the cell content.
            cell.ApplyFormatting(font);
        }
    }
}

You can also use the XlFontBase.Name and XlFontBase.Size properties of the XlFont object to define a cell font with a particular face name and size. For more information on how to specify font settings for an individual cell, refer to the How to: Configure Cell Font Settings article.

See Also