How to Set Cell Font & Size in C# with IronXL
IronXL enables you to set cell font properties including name, size, color, bold, italic, underline, strikeout, and script positioning in C# .NET without Microsoft Office interop, using simple properties like workSheet["A1"].Style.Font.Height = 18 for instant font customization.
Customizing font properties offers numerous benefits in document formatting. These options improve readability, emphasize critical information, and create visually appealing documents. With IronXL, you can edit font properties without interop in C# .NET, simplifying the process and enabling you to create professional materials effortlessly.
Quickstart: Change a Cell's Font Size in One LineUse IronXL to instantly adjust cell font size with minimal setup. This code shows how to target a cell and set its font height in a single line.
-
1Install IronXL with NuGet Package Manager
-
2Copy and run this code snippet.
workSheet["C3"].Style.Font.Height = 18;C# -
3Deploy to test on your live environment
Start using IronXL in your project today with a free trial
Minimal Workflow (5 steps)
- Download the C# library to set font and size
- Open an existing Excel spreadsheet or create a new one
- Use Font properties to customize font appearance, such as name, size, and boldness
- Set the
Fontto italic, strikeout, or useFontScript - Explore all available options for underlining
How Do I Set Cell Font and Size?
To personalize the font of a selected cell, column, row, or range, set the Font properties of the Style. Use the Name property to set the font family, the Height property to adjust font size, and the Bold property to emphasize font weight. Use the Underline property to add underlining for visual emphasis.
Name property sets the font name exactly as provided. For instance, to use "Times New Roman", input it exactly with the same spaces and capital letters.When working with Excel spreadsheets in C#, font customization is essential for creating professional documents. IronXL provides comprehensive font styling capabilities that match Excel's native functionality, allowing you to create polished Excel files with precise formatting control.
using IronXL;
using IronXL.Styles;
WorkBook workBook = WorkBook.Create();
WorkSheet workSheet = workBook.DefaultWorkSheet;
workSheet["B2"].StringValue = "Font and Size";
// Set font family
workSheet["B2"].Style.Font.Name = "Times New Roman";
// Set font size
workSheet["B2"].Style.Font.Height = 15;
// Set font to bold
workSheet["B2"].Style.Font.Bold = true;
// Set underline
workSheet["B2"].Style.Font.Underline = FontUnderlineType.Single;
workBook.SaveAs("fontAndSize.xlsx");Imports IronXL
Imports IronXL.Styles
Private workBook As WorkBook = WorkBook.Create()
Private workSheet As WorkSheet = workBook.DefaultWorkSheet
Private workSheet("B2").StringValue = "Font and Size"
' Set font family
Private workSheet("B2").Style.Font.Name = "Times New Roman"
' Set font size
Private workSheet("B2").Style.Font.Height = 15
' Set font to bold
Private workSheet("B2").Style.Font.Bold = True
' Set underline
Private workSheet("B2").Style.Font.Underline = FontUnderlineType.Single
workBook.SaveAs("fontAndSize.xlsx")
What Advanced Font Options Are Available?
Beyond basic font options, you can further customize font appearance in Excel. This includes setting the font to Italic, applying Strikeout, using FontScript for superscripts and subscripts, and choosing specific font colors. The example below demonstrates how to use these additional options to create personalized font styles for your cells.
These advanced formatting options are particularly useful when working with complex Excel reports that require professional presentation. You can combine multiple font properties to create distinctive headers, highlight important data, or format scientific notations appropriately.
using IronXL;
using IronXL.Styles;
WorkBook workBook = WorkBook.Create();
WorkSheet workSheet = workBook.DefaultWorkSheet;
workSheet["B2"].StringValue = "Advanced";
// Set font family
workSheet["B2"].Style.Font.Name = "Lucida Handwriting";
// Set font script
workSheet["B2"].Style.Font.FontScript = FontScript.None;
// Set underline
workSheet["B2"].Style.Font.Underline = FontUnderlineType.Double;
// Set bold property
workSheet["B2"].Style.Font.Bold = true;
// Set italic property
workSheet["B2"].Style.Font.Italic = false;
// Set strikeout property
workSheet["B2"].Style.Font.Strikeout = false;
// Set font color
workSheet["B2"].Style.Font.Color = "#00FFFF";
workBook.SaveAs("fontAndSizeAdvanced.xlsx");Imports IronXL
Imports IronXL.Styles
Private workBook As WorkBook = WorkBook.Create()
Private workSheet As WorkSheet = workBook.DefaultWorkSheet
Private workSheet("B2").StringValue = "Advanced"
' Set font family
Private workSheet("B2").Style.Font.Name = "Lucida Handwriting"
' Set font script
Private workSheet("B2").Style.Font.FontScript = FontScript.None
' Set underline
Private workSheet("B2").Style.Font.Underline = FontUnderlineType.Double
' Set bold property
Private workSheet("B2").Style.Font.Bold = True
' Set italic property
Private workSheet("B2").Style.Font.Italic = False
' Set strikeout property
Private workSheet("B2").Style.Font.Strikeout = False
' Set font color
Private workSheet("B2").Style.Font.Color = "#00FFFF"
workBook.SaveAs("fontAndSizeAdvanced.xlsx")
Which Underline Types Should I Use?
Excel offers different underline types for text formatting. The Accounting underline features additional spacing between characters and lines compared to the normal underline. For text entries, the underline extends beyond the value both front and back. For numeric data formats, the underline stays within the value. When a cell contains both numbers and other characters, the Accounting underline behaves like text formatting.
When creating financial reports, the accounting underline style is valuable for emphasizing totals and subtotals in a professional manner that follows standard accounting practices.

When Should I Use Font Script?
Font script in IronXL offers three options: none, super, and sub.
none: The default option, setting 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.
These script options are essential when working with scientific data or mathematical formulas in Excel spreadsheets. For example, use superscript for power notation (x²) or subscript for chemical formulas (H₂O).

How Do I Set Font Color?
You can set font color using either the Color property or the SetColor method. The SetColor method accepts input as Color or a Hex color code. This flexibility allows you to match brand colors precisely or apply conditional formatting based on data values.
using IronXL;
using IronSoftware.Drawing;
WorkBook workBook = WorkBook.Create();
WorkSheet workSheet = workBook.DefaultWorkSheet;
// Set Color property
workSheet["B2"].Style.Font.Color = "#00FFFF";
// Use Hex color code
workSheet["B2"].Style.Font.SetColor("#00FFFF");
// Use IronSoftware.Drawing
workSheet["B2"].Style.Font.SetColor(Color.Red);Imports IronXL
Imports IronSoftware.Drawing
Private workBook As WorkBook = WorkBook.Create()
Private workSheet As WorkSheet = workBook.DefaultWorkSheet
' Set Color property
Private workSheet("B2").Style.Font.Color = "#00FFFF"
' Use Hex color code
workSheet("B2").Style.Font.SetColor("#00FFFF")
' Use IronSoftware.Drawing
workSheet("B2").Style.Font.SetColor(Color.Red)Practical Example: Creating a Styled Header Row
Here's a comprehensive example that combines multiple font properties to create a professional-looking header row for a data table. This demonstrates how to apply consistent formatting across multiple cells while managing worksheets effectively:
using IronXL;
using IronXL.Styles;
using IronSoftware.Drawing;
// Create workbook and worksheet
WorkBook workBook = WorkBook.Create();
WorkSheet workSheet = workBook.DefaultWorkSheet;
// Define header titles
string[] headers = { "Product ID", "Product Name", "Price", "Stock", "Category" };
// Apply consistent header formatting
for (int i = 0; i < headers.Length; i++)
{
var cell = workSheet[1, i + 1];
cell.StringValue = headers[i];
// Apply header styling
cell.Style.Font.Name = "Arial";
cell.Style.Font.Height = 12;
cell.Style.Font.Bold = true;
cell.Style.Font.Color = "#FFFFFF";
// Add background color for headers
cell.Style.SetBackgroundColor(Color.DarkBlue);
}
// Add sample data with different font styles
workSheet["A2"].Value = "PROD001";
workSheet["B2"].Value = "Premium Widget";
workSheet["C2"].Value = 29.99;
workSheet["C2"].Style.Font.Color = "#008000"; // Green for positive values
workSheet["D2"].Value = 15;
workSheet["E2"].Value = "Electronics";
// Save the styled workbook
workBook.SaveAs("styledProducts.xlsx");Imports IronXL
Imports IronXL.Styles
Imports IronSoftware.Drawing
' Create workbook and worksheet
Dim workBook As WorkBook = WorkBook.Create()
Dim workSheet As WorkSheet = workBook.DefaultWorkSheet
' Define header titles
Dim headers As String() = {"Product ID", "Product Name", "Price", "Stock", "Category"}
' Apply consistent header formatting
For i As Integer = 0 To headers.Length - 1
Dim cell = workSheet(1, i + 1)
cell.StringValue = headers(i)
' Apply header styling
cell.Style.Font.Name = "Arial"
cell.Style.Font.Height = 12
cell.Style.Font.Bold = True
cell.Style.Font.Color = "#FFFFFF"
' Add background color for headers
cell.Style.SetBackgroundColor(Color.DarkBlue)
Next
' Add sample data with different font styles
workSheet("A2").Value = "PROD001"
workSheet("B2").Value = "Premium Widget"
workSheet("C2").Value = 29.99
workSheet("C2").Style.Font.Color = "#008000" ' Green for positive values
workSheet("D2").Value = 15
workSheet("E2").Value = "Electronics"
' Save the styled workbook
workBook.SaveAs("styledProducts.xlsx")This example showcases how IronXL's font styling capabilities integrate seamlessly with other formatting features like background colors and patterns, enabling you to create visually appealing and professional Excel documents programmatically.
Frequently Asked Questions
How can I set the font size in an Excel cell using IronXL?
To set the font size in an Excel cell using IronXL, you can use the `Height` property of the `Font` object associated with the cell's style. For example: `workSheet["A1"].Style.Font.Height = 18;` sets the font height to 18.
What font properties can be customized with IronXL?
IronXL allows you to customize various font properties such as name, size, color, bold, italic, underline, strikeout, and script positioning without Microsoft Office interop.
Is it possible to apply underline styles to text in Excel with IronXL?
Yes, IronXL supports different underline styles for text formatting, including single and double underlines, as well as accounting underlines for financial reports.
Can I set the font color in IronXL? If so, how?
You can set the font color in IronXL using either the `Color` property or the `SetColor` method. Both allow specifying colors with Hex codes or predefined color names, such as `workSheet["B2"].Style.Font.SetColor("#00FFFF");`.
How do I create bold text in an Excel cell using IronXL?
To make text bold in an Excel cell using IronXL, set the `Bold` property of the `Font` object to `true`. For example: `workSheet["B2"].Style.Font.Bold = true;`.
What is the function of FontScript in IronXL?
FontScript in IronXL is used to set the text position to normal, superscript, or subscript with options `none`, `super`, and `sub`, which are essential for scientific notation and formatting chemical formulas.
How can I change the font type in Excel files using IronXL?
You can change the font type in Excel files by setting the `Name` property of the `Font` object. For example: `workSheet["B2"].Style.Font.Name = "Times New Roman";` to set the font to Times New Roman.
Is it possible to perform font customization in Excel without Microsoft Office using C#?
Yes, IronXL allows you to perform comprehensive font customization in Excel from C# applications without needing Microsoft Office interop, providing methods to adjust font style, size, weight, and more.
What are the benefits of customizing fonts in Excel using IronXL?
Customizing fonts in Excel using IronXL benefits document formatting by improving readability, emphasizing critical information, and creating visually appealing and professional documents programmatically.
How can I make use of advanced font options like Italic or Strikeout in IronXL?
Advanced font options such as Italic or Strikeout can be implemented by setting properties like `Italic` and `Strikeout` in IronXL. For instance, `workSheet["B2"].Style.Font.Italic = true;` sets the font to italic.

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.