In order to show a good-looking Excel file or emphasize one part of Excel, different font styles for cells, which include characters, are needed. Generally speaking, the frequently used styles contain font type, size and color.

Also, developers need to set Excel Font Style in C# during the process to operate Excel, the Excel file is completely formatted after the manipulation is finished.

Set Excel Font via Spire.XLS

Actually, the action to set C# Excel Font style is a process to assign the Excel Font properties values, which may be used depending on different requirements. For example, we may assign a value for Font.Color property to get desired color of specified contents in the worksheet.

The following code shows some basic settings on Excel Font style:

[C#]

using System.Drawing;
using Spire.Xls;

namespace FontStyle
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a new workbook.
            Workbook workbook = new Workbook();
            Worksheet sheet = workbook.Worksheets[0];
            //Write text with the font of Arial.
            sheet.Range["B1"].Text = "Arial";
            sheet.Range["B1"].Style.Font.FontName = "Arial";
            //Write text with the font of Large size.
            sheet.Range["B2"].Text = "Large size";
            sheet.Range["B2"].Style.Font.Size = 20;
            //Write text with the font of Bold.
            sheet.Range["B3"].Text = "Bold";
            sheet.Range["B3"].Style.Font.IsBold = true;
            //Write text with the font of Italic.
            sheet.Range["B4"].Text = "Italic";
            sheet.Range["B4"].Style.Font.IsItalic = true;
            //Write text with the font of Superscript.
            sheet.Range["B5"].Text = "Superscript";
            sheet.Range["B5"].Style.Font.IsSuperscript = true;
            //Write text with the font of Colored.
            sheet.Range["B6"].Text = "Colored";
            sheet.Range["B6"].Style.Font.Color = Color.FromArgb(255, 125, 125);
            //Write text with the font of Underline.
            sheet.Range["B7"].Text = "Underline";
            sheet.Range["B7"].Style.Font.Underline = FontUnderlineType.Single;
            //Save the file.
            workbook.SaveToFile("Sample.xls");
            //Launch the file.
            System.Diagnostics.Process.Start("Sample.xls");
        }
    }
}
         

The following code shows some basic settings on VB.NET Excel Font style:

[Visual Basic]

Imports Microsoft.VisualBasic
Imports System.Drawing
Imports Spire.Xls
Module Module1
    Sub Main()
        'Create a new workbook.
        Dim workbook As Workbook = New Workbook()
        Dim sheet As Worksheet = workbook.Worksheets(0)
        'Write text with the font of Arial.
        sheet.Range("B1").Text = "Arial"
        sheet.Range("B1").Style.Font.FontName = "Arial"
        'Write text with the font of Large size.
        sheet.Range("B2").Text = "Large size"
        sheet.Range("B2").Style.Font.Size = 20
        'Write text with the font of Bold.
        sheet.Range("B3").Text = "Bold"
        sheet.Range("B3").Style.Font.IsBold = True
        'Write text with the font of Italic.
        sheet.Range("B4").Text = "Italic"
        sheet.Range("B4").Style.Font.IsItalic = True
        'Write text with the font of Superscript.
        sheet.Range("B5").Text = "Superscript"
        sheet.Range("B5").Style.Font.IsSuperscript = True
        'Write text with the font of Colored.
        sheet.Range("B6").Text = "Colored"
        sheet.Range("B6").Style.Font.Color = Color.FromArgb(255, 125, 125)
        'Write text with the font of Underline.
        sheet.Range("B7").Text = "Underline"
        sheet.Range("B7").Style.Font.Underline = FontUnderlineType.Single
        'Save the file.
        workbook.SaveToFile("Sample.xls")
        'Launch the file.
        System.Diagnostics.Process.Start("Sample.xls")
    End Sub
End Module

After running, the following figure will be shown: