How to Set Cell Font Size in Excel Using C# | IronXL

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 Line

Use 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.

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronXL with NuGet Package Manager

    PM > Install-Package IronXL.Excel

  2. Copy and run this code snippet.

    workSheet["C3"].Style.Font.Height = 18;
  3. Deploy to test on your live environment

    Start using IronXL in your project today with a free trial
    arrow pointer


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.

Please noteThe 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.

:path=/static-assets/excel/content-code-examples/how-to/cell-font-size-set-font.cs
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")
$vbLabelText   $csharpLabel
Excel Font section showing Times New Roman size 15 selected with Bold, Italic, Underline buttons and cell displaying formatted text

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.

:path=/static-assets/excel/content-code-examples/how-to/cell-font-size-set-font-advanced.cs
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")
$vbLabelText   $csharpLabel
Excel font formatting menu showing Lucida Handwriting font selection and Double Underline option highlighted

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.

Excel cells showing underline formatting options: none, single, double, single accounting, and double accounting

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).

Spreadsheet showing font script options: None, Super, and Sub in column B rows 2-4

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 IronSoftware.Drawing.Color or a Hex color code. This flexibility allows you to match brand colors precisely or apply conditional formatting based on data values.

:path=/static-assets/excel/content-code-examples/how-to/cell-font-size-set-font-color.cs
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)
$vbLabelText   $csharpLabel

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");
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");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

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 do I change the font size of a cell in C#?

With IronXL, you can easily change a cell's font size using the Height property. Simply use code like workSheet["A1"].Style.Font.Height = 18 to set the font size to 18 points. This approach doesn't require Microsoft Office interop, making it a streamlined solution for Excel manipulation in C# .NET applications.

Can I set different font families for Excel cells programmatically?

Yes, IronXL allows you to set any font family using the Name property of the cell's Style.Font. You can specify fonts like "Times New Roman" or "Arial" by setting workSheet["A1"].Style.Font.Name = "Times New Roman". Remember to use the exact font name with proper spacing and capitalization.

How can I make text bold or italic in Excel cells using C#?

IronXL provides simple properties to control text styling. Use the Bold property (workSheet["A1"].Style.Font.Bold = true) to make text bold, and the Italic property for italic text. You can combine these properties to create various text emphasis effects without needing Office interop.

Is it possible to add underline or strikethrough to cell text?

Yes, IronXL supports both underlining and strikethrough effects. You can use the Underline property to add underlines for visual emphasis, and the Strikeout property to create strikethrough text. These formatting options help highlight important information or indicate changes in your Excel documents.

Can I apply font formatting to multiple cells at once?

Absolutely! IronXL allows you to select and format entire ranges, rows, or columns simultaneously. You can target multiple cells using range notation and apply font properties to all selected cells at once, making it efficient to format large sections of your Excel spreadsheet.

How do I set superscript or subscript text in Excel cells?

IronXL provides the FontScript property for creating superscripts and subscripts in your Excel cells. This advanced formatting option is particularly useful for scientific notation, chemical formulas, or mathematical expressions within your spreadsheets.

Can I change font colors in Excel cells programmatically?

Yes, IronXL includes font color customization capabilities. You can set specific font colors for your cell text using the color properties available in the Style.Font object, allowing you to create visually appealing and color-coded Excel documents.

Chaknith Bin
Software Engineer
Chaknith works on IronXL and IronBarcode. He has deep expertise in C# and .NET, helping improve the software and support customers. His insights from user interactions contribute to better products, documentation, and overall experience.
Ready to Get Started?
Nuget Downloads 1,765,830 | Version: 2025.12 just released