alexa
menu

MAUI

  • User Guide
  • Demos
  • Support
  • Forums
  • Download
Search Results for

    Show / Hide Table of Contents

    Interface IFont

    Contains the font attributes (font name, font size, color and so on) for an object.

    Inherited Members
    IOptimizedUpdate.BeginUpdate()
    IOptimizedUpdate.EndUpdate()
    IParentApplication.Application
    IParentApplication.Parent
    Namespace: Syncfusion.XlsIO
    Assembly: Syncfusion.XlsIO.NET.dll
    Syntax
    public interface IFont : IParentApplication, IOptimizedUpdate

    Properties

    Bold

    True if the font is bold. Read / write Boolean.

    Declaration
    bool Bold { get; set; }
    Property Value
    Type
    bool
    Examples

    The following code illustrates how to set Bold property.

    using (ExcelEngine excelEngine = new ExcelEngine())
    {
        //Create worksheet
        IApplication application = excelEngine.Excel;
        application.DefaultVersion = ExcelVersion.Excel2013;
        IWorkbook workbook = application.Workbooks.Create(1);
        IWorksheet worksheet = workbook.Worksheets[0];
    
        //Set text
        worksheet["C2"].Text = "Sample";
    
        //Add style
        IStyle style = workbook.Styles.Add("CustomStyle");
    
        //Set style
        worksheet["C2"].CellStyle = style;
    
        //Set font
        IFont font = style.Font;
    
        //Set bold
        font.Bold = true;
    
        //Save and dispose
        workbook.SaveAs("CellFormats.xlsx");
        workbook.Close();
    }

    Color

    Returns or sets the primary color of the object. Read / write ExcelKnownColors.

    Declaration
    ExcelKnownColors Color { get; set; }
    Property Value
    Type
    ExcelKnownColors
    Examples

    The following code illustrates how a color from ExcelKnownColors enumeration can be set to font.

    using (ExcelEngine excelEngine = new ExcelEngine())
    {
        //Create worksheet
        IApplication application = excelEngine.Excel;
        application.DefaultVersion = ExcelVersion.Excel2013;
        IWorkbook workbook = application.Workbooks.Create(1);
        IWorksheet worksheet = workbook.Worksheets[0];
    
        //Set text
        worksheet["C2"].Text = "Sample";
    
        //Add style
        IStyle style = workbook.Styles.Add("CustomStyle");
    
        //Set style
        worksheet["C2"].CellStyle = style;
    
        //Set font
        IFont font = style.Font;
    
        //Set color
        font.Color = ExcelKnownColors.Red;
    
        //Save and dispose
        workbook.SaveAs("CellFormats.xlsx");
        workbook.Close();
    }

    FontName

    Returns or sets the font name. Read / write string.

    Declaration
    string FontName { get; set; }
    Property Value
    Type
    string
    Examples

    The following code illustrates how to set FontName property.

    using (ExcelEngine excelEngine = new ExcelEngine())
    {
        //Create worksheet
        IApplication application = excelEngine.Excel;
        application.DefaultVersion = ExcelVersion.Excel2013;
        IWorkbook workbook = application.Workbooks.Create(1);
        IWorksheet worksheet = workbook.Worksheets[0];
    
        //Set text
        worksheet["C2"].Text = "Sample";
    
        //Add style
        IStyle style = workbook.Styles.Add("CustomStyle");
    
        //Set style
        worksheet["C2"].CellStyle = style;
    
        //Set font
        IFont font = style.Font;
    
        //Set font name
        font.FontName = "Arial";
    
        //Save and dispose
        workbook.SaveAs("CellFormats.xlsx");
        workbook.Close();
    }

    IsAutoColor

    Indicates whether color is automatically selected. Read-only.

    Declaration
    bool IsAutoColor { get; }
    Property Value
    Type
    bool
    Examples

    The following code illustrates how to access IsAutoColor property.

            using (ExcelEngine excelEngine = new ExcelEngine())
            {
                //Create worksheet
                IApplication application = excelEngine.Excel;
                application.DefaultVersion = ExcelVersion.Excel2013;
                IWorkbook workbook = application.Workbooks.Create(1);
                IWorksheet worksheet = workbook.Worksheets[0];
    
                //Set text
                worksheet["C2"].Text = "Sample";
    
                //Add style
                IStyle style = workbook.Styles.Add("CustomStyle");
    
                //Set style
                worksheet["C2"].CellStyle = style;
    
                //Set font
                IFont font = style.Font;
    
                //Set color
                font.Color = ExcelKnownColors.Red;
    
                //Check IsAutoColor
                Console.Write(font.IsAutoColor);
    
                //Save and dispose
                workbook.SaveAs("CellFormats.xlsx");
                workbook.Close();
                Console.ReadKey();
            }
    //Output will be
    //False

    Italic

    True if the font style is italic. Read / write Boolean.

    Declaration
    bool Italic { get; set; }
    Property Value
    Type
    bool
    Examples

    The following code illustrates how to set Italic property.

    using (ExcelEngine excelEngine = new ExcelEngine())
    {
        //Create worksheet
        IApplication application = excelEngine.Excel;
        application.DefaultVersion = ExcelVersion.Excel2013;
        IWorkbook workbook = application.Workbooks.Create(1);
        IWorksheet worksheet = workbook.Worksheets[0];
    
        //Set text
        worksheet["C2"].Text = "Sample";
    
        //Add style
        IStyle style = workbook.Styles.Add("CustomStyle");
    
        //Set style
        worksheet["C2"].CellStyle = style;
    
        //Set font
        IFont font = style.Font;
    
        //Set italic
        font.Italic = true;
    
        //Save and dispose
        workbook.SaveAs("CellFormats.xlsx");
        workbook.Close();
    }

    MacOSOutlineFont

    True if the font is an outline font. Read / write Boolean.

    Declaration
    bool MacOSOutlineFont { get; set; }
    Property Value
    Type
    bool
    Examples

    The following code illustrates how to set MacOSOutlineFont property.

    using (ExcelEngine excelEngine = new ExcelEngine())
    {
        //Create worksheet
        IApplication application = excelEngine.Excel;
        application.DefaultVersion = ExcelVersion.Excel2013;
        IWorkbook workbook = application.Workbooks.Create(1);
        IWorksheet worksheet = workbook.Worksheets[0];
    
        //Set text
        worksheet["C2"].Text = "Sample";
    
        //Add style
        IStyle style = workbook.Styles.Add("CustomStyle");
    
        //Set style
        worksheet["C2"].CellStyle = style;
    
        //Set font
        IFont font = style.Font;
    
        //Set MacOS outline font
        font.MacOSOutlineFont = true;
    
        //Save and dispose
        workbook.SaveAs("CellFormats.xlsx");
        workbook.Close();
    }

    MacOSShadow

    True if the font is a shadow font or if the object has a shadow. Read / write Boolean.

    Declaration
    bool MacOSShadow { get; set; }
    Property Value
    Type
    bool
    Examples

    The following code illustrates how to set MacOSShadow property.

    using (ExcelEngine excelEngine = new ExcelEngine())
    {
        //Create worksheet
        IApplication application = excelEngine.Excel;
        application.DefaultVersion = ExcelVersion.Excel2013;
        IWorkbook workbook = application.Workbooks.Create(1);
        IWorksheet worksheet = workbook.Worksheets[0];
    
        //Set text
        worksheet["C2"].Text = "Sample";
    
        //Add style
        IStyle style = workbook.Styles.Add("CustomStyle");
    
        //Set style
        worksheet["C2"].CellStyle = style;
    
        //Set font
        IFont font = style.Font;
    
        //Set MacOS shadow
        font.MacOSShadow = true;
    
        //Save and dispose
        workbook.SaveAs("CellFormats.xlsx");
        workbook.Close();
    }

    RGBColor

    Gets / sets font color from the Color structure.

    Declaration
    Color RGBColor { get; set; }
    Property Value
    Type
    Color
    Examples

    The following code illustrates how to set a color from Color structure to the font.

    using (ExcelEngine excelEngine = new ExcelEngine())
    {
        //Create worksheet
        IApplication application = excelEngine.Excel;
        application.DefaultVersion = ExcelVersion.Excel2013;
        IWorkbook workbook = application.Workbooks.Create(1);
        IWorksheet worksheet = workbook.Worksheets[0];
    
        //Set text
        worksheet["C2"].Text = "Sample";
    
        //Add style
        IStyle style = workbook.Styles.Add("CustomStyle");
    
        //Set style
        worksheet["C2"].CellStyle = style;
    
        //Set font
        IFont font = style.Font;
    
        //Set color
        font.RGBColor = System.Drawing.Color.Red;
    
        //Save and dispose
        workbook.SaveAs("CellFormats.xlsx");
        workbook.Close();
    }

    Size

    Returns or sets the size of the font. Read / write Variant.

    Declaration
    double Size { get; set; }
    Property Value
    Type
    double
    Examples

    The following code illustrates how font size can be set.

    using (ExcelEngine excelEngine = new ExcelEngine())
    {
        //Create worksheet
        IApplication application = excelEngine.Excel;
        application.DefaultVersion = ExcelVersion.Excel2013;
        IWorkbook workbook = application.Workbooks.Create(1);
        IWorksheet worksheet = workbook.Worksheets[0];
    
        //Set text
        worksheet["C2"].Text = "Sample";
    
        //Add style
        IStyle style = workbook.Styles.Add("CustomStyle");
    
        //Set style
        worksheet["C2"].CellStyle = style;
    
        //Set font
        IFont font = style.Font;
    
        //Set size
        font.Size = 15;
    
        //Save and dispose
        workbook.SaveAs("CellFormats.xlsx");
        workbook.Close();
    }

    Strikethrough

    True if the font is struck through with a horizontal line. Read / write Boolean

    Declaration
    bool Strikethrough { get; set; }
    Property Value
    Type
    bool
    Examples

    The following code illustrates how to set Strikethrough property.

    using (ExcelEngine excelEngine = new ExcelEngine())
    {
        //Create worksheet
        IApplication application = excelEngine.Excel;
        application.DefaultVersion = ExcelVersion.Excel2013;
        IWorkbook workbook = application.Workbooks.Create(1);
        IWorksheet worksheet = workbook.Worksheets[0];
    
        //Set text
        worksheet["C2"].Text = "Sample";
    
        //Add style
        IStyle style = workbook.Styles.Add("CustomStyle");
    
        //Set style
        worksheet["C2"].CellStyle = style;
    
        //Set font
        IFont font = style.Font;
    
        //Set strick through
        font.Strikethrough = true;
    
        //Save and dispose
        workbook.SaveAs("CellFormats.xlsx");
        workbook.Close();
    }

    Subscript

    True if the font is formatted as subscript. False by default. Read / write Boolean.

    Declaration
    bool Subscript { get; set; }
    Property Value
    Type
    bool
    Examples

    The following code illustrates how to set Subscript property.

    using (ExcelEngine excelEngine = new ExcelEngine())
    {
        //Create worksheet
        IApplication application = excelEngine.Excel;
        application.DefaultVersion = ExcelVersion.Excel2013;
        IWorkbook workbook = application.Workbooks.Create(1);
        IWorksheet worksheet = workbook.Worksheets[0];
    
        //Set text
        worksheet["C2"].Text = "Sample";
    
        //Add style
        IStyle style = workbook.Styles.Add("CustomStyle");
    
        //Set style
        worksheet["C2"].CellStyle = style;
    
        //Set font
        IFont font = style.Font;
    
        //Set subscript
        font.Subscript = true;
    
        //Save and dispose
        workbook.SaveAs("CellFormats.xlsx");
        workbook.Close();
    }

    Superscript

    True if the font is formatted as superscript. False by default. Read/write Boolean

    Declaration
    bool Superscript { get; set; }
    Property Value
    Type
    bool
    Examples

    The following code illustrates how to set Superscript property.

    using (ExcelEngine excelEngine = new ExcelEngine())
    {
        //Create worksheet
        IApplication application = excelEngine.Excel;
        application.DefaultVersion = ExcelVersion.Excel2013;
        IWorkbook workbook = application.Workbooks.Create(1);
        IWorksheet worksheet = workbook.Worksheets[0];
    
        //Set text
        worksheet["C2"].Text = "Sample";
    
        //Add style
        IStyle style = workbook.Styles.Add("CustomStyle");
    
        //Set style
        worksheet["C2"].CellStyle = style;
    
        //Set font
        IFont font = style.Font;
    
        //Set superscript
        font.Superscript = true;
    
        //Save and dispose
        workbook.SaveAs("CellFormats.xlsx");
        workbook.Close();
    }

    Underline

    Returns or sets the type of underline applied to the font. Read / write ExcelUnderline.

    Declaration
    ExcelUnderline Underline { get; set; }
    Property Value
    Type
    ExcelUnderline
    Examples

    By default, None is set to Underline for fonts. Here for example, we set Single to Underline property.

    using (ExcelEngine excelEngine = new ExcelEngine())
    {
        //Create worksheet
        IApplication application = excelEngine.Excel;
        application.DefaultVersion = ExcelVersion.Excel2013;
        IWorkbook workbook = application.Workbooks.Create(1);
        IWorksheet worksheet = workbook.Worksheets[0];
    
        //Set text
        worksheet["C2"].Text = "Sample";
    
        //Add style
        IStyle style = workbook.Styles.Add("CustomStyle");
    
        //Set style
        worksheet["C2"].CellStyle = style;
    
        //Set font
        IFont font = style.Font;
    
        //Set underline
        font.Underline = ExcelUnderline.Single;
    
        //Save and dispose
        workbook.SaveAs("CellFormats.xlsx");
        workbook.Close();
    }

    VerticalAlignment

    Gets / sets font vertical alignment.

    Declaration
    ExcelFontVertialAlignment VerticalAlignment { get; set; }
    Property Value
    Type
    ExcelFontVertialAlignment
    Examples

    By default, Baseline is set to VerticalAlignment for fonts. Here for example, we set Superscript to VerticalAlignment property.

    using (ExcelEngine excelEngine = new ExcelEngine())
    {
        //Create worksheet
        IApplication application = excelEngine.Excel;
        application.DefaultVersion = ExcelVersion.Excel2013;
        IWorkbook workbook = application.Workbooks.Create(1);
        IWorksheet worksheet = workbook.Worksheets[0];
    
        //Set text
        worksheet["C2"].Text = "Sample";
    
        //Add style
        IStyle style = workbook.Styles.Add("CustomStyle");
    
        //Set style
        worksheet["C2"].CellStyle = style;
    
        //Set font
        IFont font = style.Font;
    
        //Set alignment
        font.VerticalAlignment = ExcelFontVertialAlignment.Superscript;
    
        //Save and dispose
        workbook.SaveAs("CellFormats.xlsx");
        workbook.Close();
    }

    Methods

    GenerateNativeFont()

    Generates .Net font object corresponding to the current font.

    Declaration
    Font GenerateNativeFont()
    Returns
    Type Description
    Font

    Generated .Net font.

    Examples

    The following code illustrates how .Net font object can be generated using GenerateNativeFont() method.

            using (ExcelEngine excelEngine = new ExcelEngine())
            {
                //Create worksheet
                IApplication application = excelEngine.Excel;
                application.DefaultVersion = ExcelVersion.Excel2013;
                IWorkbook workbook = application.Workbooks.Create(1);
                IWorksheet worksheet = workbook.Worksheets[0];
    
                //Set text
                worksheet["C2"].Text = "Sample";
    
                //Add style
                IStyle style = workbook.Styles.Add("CustomStyle");
    
                //Set style
                worksheet["C2"].CellStyle = style;
    
                //Set font
                IFont font = style.Font;
    
                //Set color
                font.Color = ExcelKnownColors.Red;
    
                //Generate font
                System.Drawing.Font nativeFont = font.GenerateNativeFont();
    
                //Get native font name
                Console.Write(nativeFont.Name);
    
                //Save and dispose
                workbook.SaveAs("CellFormats.xlsx");
                workbook.Close();
                Console.ReadKey();
            }
    //Output will be
    //Calibri
    In this article
    Back to top Generated by DocFX
    Copyright © 2001 - 2026 Syncfusion Inc. All Rights Reserved