Cómo establecer el tamaño de la fuente de la celda en Excel usando C# | IronXL

How to Set Cell Font and Size

This article was translated from English: Does it need improvement?
Translated
View the article in English

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.

Quickstart: Change a Cell's Font Size in One Line

Use IronXL to instantly adjust the font size of a cell with minimal setup. This concise code shows how developers can pick a target cell and set its font height in a single, easy-to-read line using IronXL.

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


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.

Por favor notaThe 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
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
Set Font And Size

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.

: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
Set Font And Size advanced

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.

Available Underline Options

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.
Available Font Script Options

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;

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

Preguntas Frecuentes

¿Cómo puedo cambiar el tamaño de la fuente en una hoja de cálculo de Excel usando C#?

En IronXL, puedes cambiar el tamaño de la fuente accediendo a la propiedad Height del objeto Font. Por ejemplo, establece cell.Style.Font.Height al tamaño deseado.

¿Cuáles son las opciones disponibles para personalizar fuentes en IronXL?

IronXL permite la personalización de propiedades de fuente como el nombre, tamaño, color, negrita, cursiva, subrayado, tachado y el script (superíndice o subíndice).

¿Cómo hago el texto en negrita en una celda de Excel usando C#?

Para hacer texto en negrita, establece la propiedad Bold del objeto Font en true. Por ejemplo, usa cell.Style.Font.Bold = true en IronXL.

¿Es posible aplicar estilos de cursiva y tachado al texto en Excel con C#?

Sí, puedes aplicar cursiva estableciendo cell.Style.Font.Italic = true y tachado estableciendo cell.Style.Font.Strikeout = true en IronXL.

¿Cómo puedo subrayar texto en una celda de Excel usando IronXL?

Usa la propiedad Underline del objeto Font para aplicar subrayado. Por ejemplo, utiliza cell.Style.Font.Underline = ExcelFont.UnderlineType.Single.

¿Qué opciones de script de fuente están disponibles en IronXL?

IronXL proporciona tres opciones de script de fuente: none (por defecto), super (para superíndice), y sub (para subíndice).

¿Cómo cambio el color de la fuente en una celda de Excel usando C#?

Puedes cambiar el color de la fuente en IronXL usando la propiedad Color o el método SetColor. Por ejemplo, usa cell.Style.Font.Color = Color.Red o cell.Style.Font.SetColor("#FF0000").

¿Qué es el subrayado de contabilidad en Excel?

El subrayado de contabilidad es un tipo de subrayado que incluye espaciado adicional y se utiliza típicamente con valores numéricos, extendiéndose más allá de las entradas de texto.

¿Cómo cargo y guardo un archivo de Excel usando IronXL?

Para cargar un archivo de Excel en IronXL, usa WorkBook.Load("example.xlsx"). Para guardar los cambios, usa workbook.SaveAs("example_modified.xlsx").

¿Puedo establecer una familia de fuentes específica en una celda de Excel usando C#?

Sí, puedes establecer una familia de fuentes específica asignando el nombre de fuente deseado a cell.Style.Font.Name, como 'Arial' o 'Times New Roman' en IronXL.

Chaknith Bin
Ingeniero de Software
Chaknith trabaja en IronXL e IronBarcode. Tiene un profundo conocimiento en C# y .NET, ayudando a mejorar el software y apoyar a los clientes. Sus conocimientos derivados de las interacciones con los usuarios contribuyen a mejores productos, documentación y experiencia en general.
¿Listo para empezar?
Nuget Descargas 1,686,155 | Versión: 2025.11 recién lanzado