How to Set Cell Font and Size
Customizing font properties, including font name, size, color, underline, bold, italic, script, and strikeout, offers numerous benefits in document formatting. These options empower you to improve readability, emphasize critical information, and create visually appealing documents. With IronXL, you can effortlessly edit font properties without interop in C# .NET, simplifying the process and enabling you to create professional and polished materials effortlessly.
How to Set Cell Font and Size
Get started with IronXL
Start using IronXL in your project today with a free trial.
Set Cell Font and Size Example
To personalize the font of a selected cell, column, row, or range, simply set the Font
properties of the Style
. Utilize the Name
property to set the desired font family, the Height
property to adjust the font size, and the Bold
property to emphasize the font weight. Additionally, you can employ the Underline
property to add underlining for further visual emphasis.
Please note
Name
property sets the font name exactly as provided. For instance, if you want to use the "Times New Roman" font, make sure to input it exactly with the same spaces and capital letters.:path=/static-assets/excel/content-code-examples/how-to/cell-font-size-set-font.cs
// Import the necessary namespaces from the IronXL library
using IronXL;
using IronXL.Styles;
// Create a new workbook
WorkBook workBook = WorkBook.Create(ExcelFileFormat.XLSX);
// Get the default worksheet from the workbook
WorkSheet workSheet = workBook.DefaultWorkSheet;
// Assign a string value to cell B2
workSheet["B2"].Value = "Font and Size";
// Set the font properties for the cell B2
workSheet["B2"].Style.Font.Name = "Times New Roman"; // Set font family to Times New Roman
workSheet["B2"].Style.Font.Size = 15; // Set font size to 15
workSheet["B2"].Style.Font.Bold = true; // Make the font bold
workSheet["B2"].Style.Font.Underline = FontUnderlineType.Single; // Underline the text with a single line
// Save the workbook to the specified file path
workBook.SaveAs("fontAndSize.xlsx");
' Import the necessary namespaces from the IronXL library
Imports IronXL
Imports IronXL.Styles
' Create a new workbook
Private workBook As WorkBook = WorkBook.Create(ExcelFileFormat.XLSX)
' Get the default worksheet from the workbook
Private workSheet As WorkSheet = workBook.DefaultWorkSheet
' Assign a string value to cell B2
Private workSheet("B2").Value = "Font and Size"
' Set the font properties for the cell B2
Private workSheet("B2").Style.Font.Name = "Times New Roman" ' Set font family to Times New Roman
Private workSheet("B2").Style.Font.Size = 15 ' Set font size to 15
Private workSheet("B2").Style.Font.Bold = True ' Make the font bold
Private workSheet("B2").Style.Font.Underline = FontUnderlineType.Single ' Underline the text with a single line
' Save the workbook to the specified file path
workBook.SaveAs("fontAndSize.xlsx")

Set Cell Font and Size Advanced Example
In addition to the options discussed in the previous section, you can further customize the font appearance in Excel. This includes setting the font to Italic
, applying Strikeout
, using FontScript
for super and subscripts, and choosing a specific font color
. Below is an example demonstrating how to utilize these additional options to create personalized font styles for your cells.
// Example of advanced font styling in IronXL
using IronXL;
using System.Drawing;
public class AdvancedFontExample
{
public static void SetAdvancedFontStyles()
{
// Load your Excel file
WorkBook workbook = WorkBook.Load("example.xlsx");
WorkSheet sheet = workbook.DefaultWorkSheet;
:path=/static-assets/excel/content-code-examples/how-to/cell-font-size-set-font-advanced.cs
// Example of advanced font styling in IronXL
using IronXL;
using System.Drawing;
public class AdvancedFontExample
{
public static void SetAdvancedFontStyles()
{
// Load your Excel file
WorkBook workbook = WorkBook.Load("example.xlsx");
WorkSheet sheet = workbook.DefaultWorkSheet;
using IronXL;
using IronXL.Styles;
// Create a new workbook
WorkBook workBook = WorkBook.Create();
// Get a reference to the default worksheet
WorkSheet workSheet = workBook.DefaultWorkSheet;
// Set the value of cell B2 to "Advanced"
workSheet["B2"].StringValue = "Advanced";
// Set the font family of cell B2 to "Lucida Handwriting"
workSheet["B2"].Style.Font.Name = "Lucida Handwriting";
// Set the font script for cell B2 to none
workSheet["B2"].Style.Font.FontScript = FontScript.None;
// Apply a double underline to the text in cell B2
workSheet["B2"].Style.Font.Underline = FontUnderlineType.Double;
// Set the text in cell B2 to bold
workSheet["B2"].Style.Font.Bold = true;
// Set the text in cell B2 to be non-italic
workSheet["B2"].Style.Font.Italic = false;
// Ensure the text in cell B2 is not struck out
workSheet["B2"].Style.Font.Strikeout = false;
// Set the color of the text in cell B2 to cyan
workSheet["B2"].Style.Font.Color = "#00FFFF";
// Save the workbook to a file named "fontAndSizeAdvanced.xlsx"
workBook.SaveAs("fontAndSizeAdvanced.xlsx");
' Example of advanced font styling in IronXL
Imports IronXL
Imports System.Drawing
Public Class AdvancedFontExample
Public Shared Sub SetAdvancedFontStyles()
' Load your Excel file
Dim workbook As WorkBook = WorkBook.Load("example.xlsx")
Dim sheet As WorkSheet = workbook.DefaultWorkSheet
Dim IronXL As using
Using IronXL.Styles
' Create a new workbook
'INSTANT VB NOTE: The variable workBook was renamed since Visual Basic will not allow local variables with the same name as parameters or other local variables:
Dim workBook_Conflict As WorkBook = WorkBook.Create()
' Get a reference to the default worksheet
Dim workSheet As WorkSheet = workBook_Conflict.DefaultWorkSheet
' Set the value of cell B2 to "Advanced"
workSheet("B2").StringValue = "Advanced"
' Set the font family of cell B2 to "Lucida Handwriting"
workSheet("B2").Style.Font.Name = "Lucida Handwriting"
' Set the font script for cell B2 to none
workSheet("B2").Style.Font.FontScript = FontScript.None
' Apply a double underline to the text in cell B2
workSheet("B2").Style.Font.Underline = FontUnderlineType.Double
' Set the text in cell B2 to bold
workSheet("B2").Style.Font.Bold = True
' Set the text in cell B2 to be non-italic
workSheet("B2").Style.Font.Italic = False
' Ensure the text in cell B2 is not struck out
workSheet("B2").Style.Font.Strikeout = False
' Set the color of the text in cell B2 to cyan
workSheet("B2").Style.Font.Color = "#00FFFF"
' Save the workbook to a file named "fontAndSizeAdvanced.xlsx"
workBook_Conflict.SaveAs("fontAndSizeAdvanced.xlsx")
End Using

Underline
In Excel, there are different types of underlines available for text formatting. One such option is the Accounting underline, which has additional spacing between the characters and the lines compared to the normal underline. For text entries, the underline extends beyond the value both in front and back. However, for numeric data formats, the underline remains confined to the value. In cases where a cell contains both numbers and other characters, the Accounting underline will behave similarly to text.

Font Script
Font script in IronXL offers three options: none
, super
, and sub
.
none
: The default option, setting the font on the baseline for regular text appearance.super
: Positions text characters above the baseline for exponents or footnotes.sub
: Positions text characters below the baseline for chemical formulas and math notations.

Font Color
You can set the font color using either the Color
property or the SetColor
method. The SetColor
method accepts input in the form of IronSoftware.Drawing.Color
or a Hex color code.
:path=/static-assets/excel/content-code-examples/how-to/cell-font-size-set-font-color.cs
using IronXL;
using IronSoftware.Drawing;
// Create a new workbook using IronXL
WorkBook workBook = WorkBook.Create();
// Get the default worksheet of the newly created workbook
WorkSheet workSheet = workBook.DefaultWorkSheet;
// Changing the font color of cell B2 using different methods
// Method 1: Directly setting the color property using a Hex color code
// This method changes the font color of cell B2 to Cyan
workSheet["B2"].Style.Font.Color = "#00FFFF";
// Method 2: Using the SetColor method with a Hex color code
// This method also changes the font color of cell B2 to Cyan
workSheet["B2"].Style.Font.SetColor("#00FFFF");
// Method 3: Using the SetColor method with a predefined color from IronSoftware.Drawing
// This method changes the font color of cell B2 to Red
workSheet["B2"].Style.Font.SetColor(Color.Red);
Imports IronXL
Imports IronSoftware.Drawing
' Create a new workbook using IronXL
Private workBook As WorkBook = WorkBook.Create()
' Get the default worksheet of the newly created workbook
Private workSheet As WorkSheet = workBook.DefaultWorkSheet
' Changing the font color of cell B2 using different methods
' Method 1: Directly setting the color property using a Hex color code
' This method changes the font color of cell B2 to Cyan
Private workSheet("B2").Style.Font.Color = "#00FFFF"
' Method 2: Using the SetColor method with a Hex color code
' This method also changes the font color of cell B2 to Cyan
workSheet("B2").Style.Font.SetColor("#00FFFF")
' Method 3: Using the SetColor method with a predefined color from IronSoftware.Drawing
' This method changes the font color of cell B2 to Red
workSheet("B2").Style.Font.SetColor(Color.Red)
Frequently Asked Questions
How can I set the font size in an Excel cell using IronXL?
You can set the font size by using the Height property of the Font object in IronXL. Load your Excel file, select a cell, and set the cell.Style.Font.Height to the desired size.
What font properties can be customized with IronXL?
With IronXL, you can customize font name, size, color, boldness, italic, underline, strikeout, and script (super or subscript).
How do I make text bold in an Excel cell using IronXL?
To make text bold, set the Bold property of the Font object to true. For example, cell.Style.Font.Bold = true.
Can I apply italic and strikeout styles to text in Excel using IronXL?
Yes, you can apply italic by setting cell.Style.Font.Italic = true and strikeout by setting cell.Style.Font.Strikeout = true.
How do I underline text in an Excel cell using IronXL?
Use the Underline property of the Font object to apply underlining. For example, cell.Style.Font.Underline = ExcelFont.UnderlineType.Single.
What are the font script options available in IronXL?
IronXL offers three font script options: none (default), super (for superscript), and sub (for subscript).
How do I change the font color in an Excel cell using IronXL?
You can change the font color using the Color property or SetColor method. For instance, use cell.Style.Font.Color = Color.Red or cell.Style.Font.SetColor("#FF0000").
What is the Accounting underline in Excel?
The Accounting underline is a type of underline with additional spacing, extending beyond text entries and confined to numeric values.
How do I load and save an Excel file in IronXL?
To load an Excel file, use WorkBook.Load("example.xlsx"). To save changes, use workbook.SaveAs("example_modified.xlsx").
Can I set a specific font family in an Excel cell using IronXL?
Yes, you can set a specific font family by assigning the desired font name to cell.Style.Font.Name, such as "Arial" or "Times New Roman".