Cómo añadir estilo al texto en DOCX con C#
La clase TextStyle de IronWord permite a los desarrolladores de .NET aplicar formato de texto profesional a documentos de Word programáticamente, incluyendo fuentes, colores, negrita, cursiva, subrayado y más. Ya se trate de generar informes, crear plantillas o automatizar la creación de documentos, IronWord ofrece herramientas de estilo completas que reproducen las opciones de formato de Microsoft Word.
-
1Instalar IronWord con NuGet Package Manager
-
2Copie y ejecute este fragmento de código.
// Quick example using IronWord; using IronWord.Models; // Initialize a new Word document WordDocument doc = new WordDocument(); // Create a Run with styled text Run textRun = new Run(new TextContent("Styled text")); // Apply styling properties to the Run textRun.Style = new TextStyle() { IsBold = true, Color = Color.Red, FontSize = 16, TextFont = new Font() { FontFamily = "Arial" } }; // Create paragraph and add the styled Run Paragraph paragraph = new Paragraph(); paragraph.AddChild(textRun); // Add paragraph to document and save doc.AddParagraph(paragraph); doc.SaveAs("styled.docx");Imports IronWord Imports IronWord.Models ' Initialize a new Word document Dim doc As New WordDocument() ' Create a Run with styled text Dim textRun As New Run(New TextContent("Styled text")) ' Apply styling properties to the Run textRun.Style = New TextStyle() With { .IsBold = True, .Color = Color.Red, .FontSize = 16, .TextFont = New Font() With { .FontFamily = "Arial" } } ' Create paragraph and add the styled Run Dim paragraph As New Paragraph() paragraph.AddChild(textRun) ' Add paragraph to document and save doc.AddParagraph(paragraph) doc.SaveAs("styled.docx")Imports IronWord Imports IronWord.Models ' Initialize a new Word document Dim doc As New WordDocument() ' Create a Run with styled text Dim textRun As New Run(New TextContent("Styled text")) ' Apply styling properties to the Run textRun.Style = New TextStyle() With { .IsBold = True, .Color = Color.Red, .FontSize = 16, .TextFont = New Font() With { .FontFamily = "Arial" } } ' Create paragraph and add the styled Run Dim paragraph As New Paragraph() paragraph.AddChild(textRun) ' Add paragraph to document and save doc.AddParagraph(paragraph) doc.SaveAs("styled.docx") -
3Despliegue para probar en su entorno real
Empiece a usar IronWord en su proyecto hoy con una prueba gratuita
Flujo de trabajo mínimo (5 pasos)
- Instalar la biblioteca IronWord C#
- Crear un objeto
Runque contengaTextContent - Aplicar
TextStylea laRuncon propiedades comoFontSize,IsBoldyColor - Agregue la
Runcon estilo a unParagraphusandoAddChild - Guardar el documento con los estilos aplicados
¿Cómo añadir estilo de texto a DOCX?
Aplicar estilos de texto en IronWord requiere usar el patrón de envoltura Run. Cree un objeto WordDocument, luego cree un objeto Run que contenga TextContent con su texto. Aplique un TextStyle al Run (no al TextContent) utilizando propiedades como IsBold, Color, o FontSize.
Una vez estilizado, agregue el Run a un Paragraph usando AddChild, inserte el párrafo en el documento y guarde el resultado. Este enfoque proporciona un control programático sobre el formato del texto para escenarios de generación automática de documentos que requieren un estilo coherente.
Document → (opcional DocumentSection) → Paragraph → Run → TextContent. Los párrafos pueden agregarse directamente a WordDocument mediante AddParagraph sin un DocumentSection explícito, como se muestra en los ejemplos de esta página. Los estilos se aplican a nivel de Run, no directamente en TextContent.using IronWord;
using IronWord.Models;
using IronWord.Models.Enums;
// Load docx
WordDocument doc = new WordDocument("sample.docx");
// Configure text
Run textRun = new Run(new TextContent("Add text using IronWord"));
// Configure text style settings
textRun.Style = new TextStyle()
{
FontSize = 24, // Text Size is 24
TextFont = new Font()
{
FontFamily = "Calibri" // Text Font is "Calibri"
},
Color = Color.Red, // Set text color to red
IsBold = true, // Make text bold
IsItalic = true, // Make text italic
Underline = new Underline(), // Have an underline
Strike = StrikeValue.DoubleStrike, // Double strike-through
};
Paragraph paragraph = new Paragraph();
// Add text to paragraph
paragraph.AddChild(textRun);
// Add paragraph to document
doc.AddParagraph(paragraph);
// Save document
doc.SaveAs("add-text-style.docx");using IronWord;
using IronWord.Models;
using IronWord.Models.Enums;
// Load docx
WordDocument doc = new WordDocument("sample.docx");
// Configure text
Run textRun = new Run(new TextContent("Add text using IronWord"));
// Configure text style settings
textRun.Style = new TextStyle()
{
FontSize = 24, // Text Size is 24
TextFont = new Font()
{
FontFamily = "Calibri" // Text Font is "Calibri"
},
Color = Color.Red, // Set text color to red
IsBold = true, // Make text bold
IsItalic = true, // Make text italic
Underline = new Underline(), // Have an underline
Strike = StrikeValue.DoubleStrike, // Double strike-through
};
Paragraph paragraph = new Paragraph();
// Add text to paragraph
paragraph.AddChild(textRun);
// Add paragraph to document
doc.AddParagraph(paragraph);
// Save document
doc.SaveAs("add-text-style.docx");Imports IronWord
Imports IronWord.Models
Imports IronWord.Models.Enums
' Load docx
Dim doc As New WordDocument("sample.docx")
' Configure text
Dim textRun As New Run(New TextContent("Add text using IronWord"))
' Configure text style settings
textRun.Style = New TextStyle() With {
.FontSize = 24, ' Text Size is 24
.TextFont = New Font() With {
.FontFamily = "Calibri" ' Text Font is "Calibri"
},
.Color = Color.Red, ' Set text color to red
.IsBold = True, ' Make text bold
.IsItalic = True, ' Make text italic
.Underline = New Underline(), ' Have an underline
.Strike = StrikeValue.DoubleStrike ' Double strike-through
}
Dim paragraph As New Paragraph()
' Add text to paragraph
paragraph.AddChild(textRun)
' Add paragraph to document
doc.AddParagraph(paragraph)
' Save document
doc.SaveAs("add-text-style.docx")Imports IronWord
Imports IronWord.Models
Imports IronWord.Models.Enums
' Load docx
Dim doc As New WordDocument("sample.docx")
' Configure text
Dim textRun As New Run(New TextContent("Add text using IronWord"))
' Configure text style settings
textRun.Style = New TextStyle() With {
.FontSize = 24, ' Text Size is 24
.TextFont = New Font() With {
.FontFamily = "Calibri" ' Text Font is "Calibri"
},
.Color = Color.Red, ' Set text color to red
.IsBold = True, ' Make text bold
.IsItalic = True, ' Make text italic
.Underline = New Underline(), ' Have an underline
.Strike = StrikeValue.DoubleStrike ' Double strike-through
}
Dim paragraph As New Paragraph()
' Add text to paragraph
paragraph.AddChild(textRun)
' Add paragraph to document
doc.AddParagraph(paragraph)
' Save document
doc.SaveAs("add-text-style.docx")¿Qué resultados se obtendrán?

La clase TextStyle proporciona opciones esenciales de formato que incluyen propiedades de fuente, color del texto, negrita, cursiva y subrayado. Tenga en cuenta que FontSize se configura a nivel de TextStyle (no dentro de Font), mientras que FontFamily se establece dentro de la propiedad TextFont. El objeto Run envuelve el TextContent y mantiene el estilo, siguiendo el patrón de jerarquía de documentos de IronWord. El ejemplo demuestra cómo múltiples propiedades de estilo se combinan para crear texto ricamente formateado cuando se aplican a un Run.
¿Qué estilos específicos puedo añadir?
¿Cómo puedo cambiar el color del texto?
La propiedad Color en TextStyle establece el color del texto utilizando colores predefinidos de IronWord.Models.Color o valores hexadecimales personalizados. Esto enfatiza el contenido específico o coincide con los colores de la marca. IronWord admite una amplia gama de colores, como rojo, azul, verde, oliva, azul marino y granate.
using IronWord;
using IronWord.Models;
// Create document
WordDocument doc = new WordDocument();
// Add colored text
Run textRun = new Run(new TextContent("This text is olive-colored!"));
textRun.Style = new TextStyle()
{
Color = IronWord.Models.Color.Olive // defining text to be colored olive
};
Paragraph paragraph = new Paragraph();
paragraph.AddChild(textRun);
doc.AddParagraph(paragraph);
// Save document
doc.SaveAs("colored-text.docx");using IronWord;
using IronWord.Models;
// Create document
WordDocument doc = new WordDocument();
// Add colored text
Run textRun = new Run(new TextContent("This text is olive-colored!"));
textRun.Style = new TextStyle()
{
Color = IronWord.Models.Color.Olive // defining text to be colored olive
};
Paragraph paragraph = new Paragraph();
paragraph.AddChild(textRun);
doc.AddParagraph(paragraph);
// Save document
doc.SaveAs("colored-text.docx");Imports IronWord
Imports IronWord.Models
' Create document
Dim doc As New WordDocument()
' Add colored text
Dim textRun As New Run(New TextContent("This text is olive-colored!"))
textRun.Style = New TextStyle() With {
.Color = IronWord.Models.Color.Olive ' defining text to be colored olive
}
Dim paragraph As New Paragraph()
paragraph.AddChild(textRun)
doc.AddParagraph(paragraph)
' Save document
doc.SaveAs("colored-text.docx")Imports IronWord
Imports IronWord.Models
' Create document
Dim doc As New WordDocument()
' Add colored text
Dim textRun As New Run(New TextContent("This text is olive-colored!"))
textRun.Style = New TextStyle() With {
.Color = IronWord.Models.Color.Olive ' defining text to be colored olive
}
Dim paragraph As New Paragraph()
paragraph.AddChild(textRun)
doc.AddParagraph(paragraph)
' Save document
doc.SaveAs("colored-text.docx")¿Qué aspecto tiene el texto coloreado?

¿Cómo configuro la familia y el tamaño de la fuente?
Personalice la apariencia del texto con la propiedad TextFont. Establezca FontFamily en cualquier nombre de fuente instalado (por ejemplo, "Arial", "Times New Roman") y FontSize en puntos. Así se establece una jerarquía visual y se garantiza la legibilidad en distintos dispositivos y plataformas.
using IronWord;
using IronWord.Models;
// Create document
WordDocument doc = new WordDocument();
// Add text with custom font family and size
Run textRun = new Run(new TextContent("This text uses Arial at 24pt!"));
textRun.Style = new TextStyle()
{
FontSize = 24, // Set font size in points
TextFont = new IronWord.Models.Font()
{
FontFamily = "Arial" // Set font family
}
};
Paragraph paragraph = new Paragraph();
paragraph.AddChild(textRun);
doc.AddParagraph(paragraph);
// Save document
doc.SaveAs("font-styled-text.docx");using IronWord;
using IronWord.Models;
// Create document
WordDocument doc = new WordDocument();
// Add text with custom font family and size
Run textRun = new Run(new TextContent("This text uses Arial at 24pt!"));
textRun.Style = new TextStyle()
{
FontSize = 24, // Set font size in points
TextFont = new IronWord.Models.Font()
{
FontFamily = "Arial" // Set font family
}
};
Paragraph paragraph = new Paragraph();
paragraph.AddChild(textRun);
doc.AddParagraph(paragraph);
// Save document
doc.SaveAs("font-styled-text.docx");Imports IronWord
Imports IronWord.Models
' Create document
Dim doc As New WordDocument()
' Add text with custom font family and size
Dim textRun As New Run(New TextContent("This text uses Arial at 24pt!"))
textRun.Style = New TextStyle() With {
.FontSize = 24, ' Set font size in points
.TextFont = New IronWord.Models.Font() With {
.FontFamily = "Arial" ' Set font family
}
}
Dim paragraph As New Paragraph()
paragraph.AddChild(textRun)
doc.AddParagraph(paragraph)
' Save document
doc.SaveAs("font-styled-text.docx")Imports IronWord
Imports IronWord.Models
' Create document
Dim doc As New WordDocument()
' Add text with custom font family and size
Dim textRun As New Run(New TextContent("This text uses Arial at 24pt!"))
textRun.Style = New TextStyle() With {
.FontSize = 24, ' Set font size in points
.TextFont = New IronWord.Models.Font() With {
.FontFamily = "Arial" ' Set font family
}
}
Dim paragraph As New Paragraph()
paragraph.AddChild(textRun)
doc.AddParagraph(paragraph)
' Save document
doc.SaveAs("font-styled-text.docx")¿Qué aspecto tiene el estilo de fuente personalizado?

¿Cómo poner el texto en negrita?
Configure la propiedad IsBold a true para hacer el texto Bold. El texto Bold se utiliza comúnmente para encabezados, énfasis o resaltar información importante. Combinado con otras propiedades de estilo, el texto Bold crea jerarquía visual y mejora la legibilidad.
using IronWord;
using IronWord.Models;
// Create document
WordDocument doc = new WordDocument();
// Add bold text
Run textRun = new Run(new TextContent("this is bold!"));
textRun.Style = new TextStyle()
{
IsBold = true // Make text bold
};
Paragraph paragraph = new Paragraph();
paragraph.AddChild(textRun);
doc.AddParagraph(paragraph);
// Save document
doc.SaveAs("bold-text.docx");using IronWord;
using IronWord.Models;
// Create document
WordDocument doc = new WordDocument();
// Add bold text
Run textRun = new Run(new TextContent("this is bold!"));
textRun.Style = new TextStyle()
{
IsBold = true // Make text bold
};
Paragraph paragraph = new Paragraph();
paragraph.AddChild(textRun);
doc.AddParagraph(paragraph);
// Save document
doc.SaveAs("bold-text.docx");Imports IronWord
Imports IronWord.Models
' Create document
Dim doc As New WordDocument()
' Add bold text
Dim textRun As New Run(New TextContent("this is bold!"))
textRun.Style = New TextStyle() With {
.IsBold = True ' Make text bold
}
Dim paragraph As New Paragraph()
paragraph.AddChild(textRun)
doc.AddParagraph(paragraph)
' Save document
doc.SaveAs("bold-text.docx")Imports IronWord
Imports IronWord.Models
' Create document
Dim doc As New WordDocument()
' Add bold text
Dim textRun As New Run(New TextContent("this is bold!"))
textRun.Style = New TextStyle() With {
.IsBold = True ' Make text bold
}
Dim paragraph As New Paragraph()
paragraph.AddChild(textRun)
doc.AddParagraph(paragraph)
' Save document
doc.SaveAs("bold-text.docx")¿Qué aspecto tiene el texto en negrita?

¿Cómo poner texto en cursiva?
Configure la propiedad IsItalic a true para el estilo Italic. El texto Italic se utiliza típicamente para énfasis, títulos, palabras extranjeras o términos técnicos. Este formato sutil diferencia elementos de texto sin el peso visual del formato Bold.
using IronWord;
using IronWord.Models;
// Create document
WordDocument doc = new WordDocument();
// Add italic text
Run textRun = new Run(new TextContent("this is italic."));
textRun.Style = new TextStyle()
{
IsItalic = true // Make text italic
};
Paragraph paragraph = new Paragraph();
paragraph.AddChild(textRun);
doc.AddParagraph(paragraph);
// Save document
doc.SaveAs("italic-text.docx");using IronWord;
using IronWord.Models;
// Create document
WordDocument doc = new WordDocument();
// Add italic text
Run textRun = new Run(new TextContent("this is italic."));
textRun.Style = new TextStyle()
{
IsItalic = true // Make text italic
};
Paragraph paragraph = new Paragraph();
paragraph.AddChild(textRun);
doc.AddParagraph(paragraph);
// Save document
doc.SaveAs("italic-text.docx");Imports IronWord
Imports IronWord.Models
' Create document
Dim doc As New WordDocument()
' Add italic text
Dim textRun As New Run(New TextContent("this is italic."))
textRun.Style = New TextStyle() With {
.IsItalic = True ' Make text italic
}
Dim paragraph As New Paragraph()
paragraph.AddChild(textRun)
doc.AddParagraph(paragraph)
' Save document
doc.SaveAs("italic-text.docx")Imports IronWord
Imports IronWord.Models
' Create document
Dim doc As New WordDocument()
' Add italic text
Dim textRun As New Run(New TextContent("this is italic."))
textRun.Style = New TextStyle() With {
.IsItalic = True ' Make text italic
}
Dim paragraph As New Paragraph()
paragraph.AddChild(textRun)
doc.AddParagraph(paragraph)
' Save document
doc.SaveAs("italic-text.docx")¿Qué aspecto tiene el texto en cursiva?

¿Cuáles son las propiedades de estilo disponibles?
IronWord ofrece amplias propiedades de estilo que reflejan las opciones de formato de Microsoft Word. Estas propiedades se combinan para crear un formato de texto complejo que cumpla las normas de los documentos profesionales.
| Método de peinado | Descripción | Ejemplo |
|---|---|---|
TextFont | Personaliza la apariencia del texto con un objeto Font , configurando la familia de fuentes. Nota: FontSize se configura en el nivel TextStyle , no dentro Font . | textRun.Style = new TextStyle() { FontSize = 24, TextFont = new Font() { FontFamily = "Calibri" } }; |
Color | Establece el color del texto utilizando colores predefinidos de IronWord.Models.Color o valores hexadecimales personalizados. | textRun.Style.Color = IronWord.Models.Color.Red; |
IsBold | Hace el texto Bold cuando se establece en true, comúnmente usado para títulos o énfasis. | textRun.Style.IsBold = true; |
IsItalic | Aplica formato Italic al texto cuando se establece en true, típicamente usado para énfasis o títulos. | textRun.Style.IsItalic = true; |
Underline | Añade un Underline al texto utilizando un objeto Underline con varios estilos de subrayado. | textRun.Style.Underline = new Underline(); |
Strike | Aplica tachado al texto utilizando el enum StrikeValue (Strike o DoubleStrike). | textRun.Style.Strike = StrikeValue.Strike; |
Caps | Aplica efectos de capitalización al texto, convirtiendo todos los caracteres a mayúsculas. | textRun.Style.Caps = true; |
CharacterScale | Ajusta el ancho proporcional de los caracteres como un porcentaje de su tamaño normal. | textRun.Style.CharacterScale = 150; |
Emboss | Aplica un efecto de relieve al texto, creando una apariencia elevada. | textRun.Style.Emboss = true; |
Emphasis | Añade marcas de énfasis al texto con estilo utilizando valores EmphasisMarkValues enum. | textRun.Style.Emphasis = EmphasisMarkValues.Dot; |
LineSpacing | Controla el espaciado entre líneas de texto para mejorar la legibilidad usando un objeto LineSpacing, donde Value es un multiplicador de altura de línea. | textRun.Style.LineSpacing = new LineSpacing() { Value = 1.5 }; |
Outline | Representa el texto con un efecto de contorno, mostrando solo los bordes de los caracteres. | textRun.Style.Outline = true; |
Shading | Aplica color de fondo o sombreado al texto mediante un objeto Shading. | textRun.Style.Shading = new Shading() { Color = Color.Yellow }; |
SmallCaps | Convierte letras minúsculas en mayúsculas pequeñas manteniendo la distinción entre mayúsculas y minúsculas. | textRun.Style.SmallCaps = true; |
VerticalPosition | Ajusta la ubicación vertical del texto en relación con su línea base, medida en puntos. | textRun.Style.VerticalPosition = 5.0; |
VerticalTextAlignment | Posiciona el texto verticalmente dentro de su contenedor utilizando VerticalPositionValues enum. | textRun.Style.VerticalTextAlignment = VerticalPositionValues.Superscript; |
Combinación de varios estilos
El poder de estilización del texto de IronWord proviene de la combinación de múltiples propiedades para lograr un formato complejo. A continuación se muestra un ejemplo de texto con estilo profesional mediante la combinación de varias propiedades de estilo:
using IronWord;
using IronWord.Models;
// Create a new document
WordDocument doc = new WordDocument();
// Create richly formatted header text using Run
Run headerRun = new Run(new TextContent("Professional Document Header"));
headerRun.Style = new TextStyle()
{
FontSize = 28,
TextFont = new Font()
{
FontFamily = "Georgia"
},
Color = Color.DarkBlue,
IsBold = true,
SmallCaps = true,
Underline = new Underline(),
CharacterScale = 110, // Slightly expand character width
Shading = new Shading()
{
Color = Color.LightGray // Light background
}
};
// Add header to document using AddChild for styled Run
Paragraph headerParagraph = new Paragraph();
headerParagraph.AddChild(headerRun);
doc.AddParagraph(headerParagraph);
// Create body text with different styling
Run bodyRun = new Run(new TextContent("This is professionally formatted body text with custom styling."));
bodyRun.Style = new TextStyle()
{
FontSize = 11,
TextFont = new Font()
{
FontFamily = "Calibri"
},
Color = Color.Black
};
Paragraph bodyParagraph = new Paragraph();
bodyParagraph.AddChild(bodyRun);
doc.AddParagraph(bodyParagraph);
// Save the document
doc.SaveAs("professional-document.docx");using IronWord;
using IronWord.Models;
// Create a new document
WordDocument doc = new WordDocument();
// Create richly formatted header text using Run
Run headerRun = new Run(new TextContent("Professional Document Header"));
headerRun.Style = new TextStyle()
{
FontSize = 28,
TextFont = new Font()
{
FontFamily = "Georgia"
},
Color = Color.DarkBlue,
IsBold = true,
SmallCaps = true,
Underline = new Underline(),
CharacterScale = 110, // Slightly expand character width
Shading = new Shading()
{
Color = Color.LightGray // Light background
}
};
// Add header to document using AddChild for styled Run
Paragraph headerParagraph = new Paragraph();
headerParagraph.AddChild(headerRun);
doc.AddParagraph(headerParagraph);
// Create body text with different styling
Run bodyRun = new Run(new TextContent("This is professionally formatted body text with custom styling."));
bodyRun.Style = new TextStyle()
{
FontSize = 11,
TextFont = new Font()
{
FontFamily = "Calibri"
},
Color = Color.Black
};
Paragraph bodyParagraph = new Paragraph();
bodyParagraph.AddChild(bodyRun);
doc.AddParagraph(bodyParagraph);
// Save the document
doc.SaveAs("professional-document.docx");Imports IronWord
Imports IronWord.Models
' Create a new document
Dim doc As New WordDocument()
' Create richly formatted header text using Run
Dim headerRun As New Run(New TextContent("Professional Document Header"))
headerRun.Style = New TextStyle() With {
.FontSize = 28,
.TextFont = New Font() With {
.FontFamily = "Georgia"
},
.Color = Color.DarkBlue,
.IsBold = True,
.SmallCaps = True,
.Underline = New Underline(),
.CharacterScale = 110, ' Slightly expand character width
.Shading = New Shading() With {
.Color = Color.LightGray ' Light background
}
}
' Add header to document using AddChild for styled Run
Dim headerParagraph As New Paragraph()
headerParagraph.AddChild(headerRun)
doc.AddParagraph(headerParagraph)
' Create body text with different styling
Dim bodyRun As New Run(New TextContent("This is professionally formatted body text with custom styling."))
bodyRun.Style = New TextStyle() With {
.FontSize = 11,
.TextFont = New Font() With {
.FontFamily = "Calibri"
},
.Color = Color.Black
}
Dim bodyParagraph As New Paragraph()
bodyParagraph.AddChild(bodyRun)
doc.AddParagraph(bodyParagraph)
' Save the document
doc.SaveAs("professional-document.docx")Imports IronWord
Imports IronWord.Models
' Create a new document
Dim doc As New WordDocument()
' Create richly formatted header text using Run
Dim headerRun As New Run(New TextContent("Professional Document Header"))
headerRun.Style = New TextStyle() With {
.FontSize = 28,
.TextFont = New Font() With {
.FontFamily = "Georgia"
},
.Color = Color.DarkBlue,
.IsBold = True,
.SmallCaps = True,
.Underline = New Underline(),
.CharacterScale = 110, ' Slightly expand character width
.Shading = New Shading() With {
.Color = Color.LightGray ' Light background
}
}
' Add header to document using AddChild for styled Run
Dim headerParagraph As New Paragraph()
headerParagraph.AddChild(headerRun)
doc.AddParagraph(headerParagraph)
' Create body text with different styling
Dim bodyRun As New Run(New TextContent("This is professionally formatted body text with custom styling."))
bodyRun.Style = New TextStyle() With {
.FontSize = 11,
.TextFont = New Font() With {
.FontFamily = "Calibri"
},
.Color = Color.Black
}
Dim bodyParagraph As New Paragraph()
bodyParagraph.AddChild(bodyRun)
doc.AddParagraph(bodyParagraph)
' Save the document
doc.SaveAs("professional-document.docx")Este enfoque de estilo integral crea documentos que mantienen una imagen de marca coherente y un aspecto profesional durante todo el proceso de generación de documentos de su aplicación.
Preguntas frecuentes
¿Cómo puedo formatear texto en un archivo DOCX usando C#?
Puede formatear texto en un archivo DOCX utilizando la biblioteca IronWord creando un objeto Run que contenga TextContent y aplicando un TextStyle al Run. Las propiedades de TextStyle como FontSize, Color e IsBold le permiten personalizar la apariencia del texto programáticamente.
¿Para qué se utiliza la clase TextStyle en IronWord?
La clase TextStyle en IronWord se utiliza para aplicar varias opciones de formato de texto, como fuentes, colores, negrita, cursiva y subrayado, al texto dentro de documentos de Word.
¿Cómo cambio el color de fuente del texto usando IronWord?
Para cambiar el color de fuente del texto usando IronWord, configure la propiedad Color en la clase TextStyle a un color predefinido de IronWord.Models.Color o utilice valores hexadecimales personalizados para necesidades de color específicas.
¿Puedo establecer tanto la familia de fuentes como el tamaño en IronWord?
Sí, IronWord le permite establecer tanto la familia de fuentes como el tamaño para el texto. Puede utilizar la propiedad TextFont para especificar el FontFamily y la propiedad FontSize en TextStyle para establecer el tamaño en puntos.
¿Cuál es el propósito del objeto Run en IronWord?
El objeto Run en IronWord sirve como un contenedor para TextContent, lo que permite la aplicación de estilos de texto como fuentes, colores y decoraciones a un nivel granular dentro de los párrafos.
¿Cómo hago texto en negrita en un documento de IronWord?
Para hacer texto en negrita en un documento de IronWord, configure la propiedad IsBold de la clase TextStyle a true y aplíquela al objeto Run que contiene su texto.
¿Qué propiedad se usa para poner texto en cursiva en IronWord?
La propiedad IsItalic se utiliza dentro de la clase TextStyle para aplicar formato en cursiva al texto en documentos de IronWord.
¿Cómo aplico un subrayado al texto usando IronWord?
Para subrayar texto en un documento de IronWord, cree un nuevo objeto Underline y asígnelo a la propiedad Underline en la clase TextStyle para el objeto Run que contiene su texto.
¿Puedo aplicar formato de texto complejo utilizando múltiples propiedades en IronWord?
Sí, IronWord permite un formato de texto complejo combinando múltiples propiedades de TextStyle, como FontSize, Color, IsBold y Underline, para crear texto con formato rico en los documentos de Word.
¿Cuál es el beneficio de usar IronWord para formatear texto en documentos DOCX?
IronWord ofrece control programático sobre el formato de texto en documentos DOCX, lo que permite a los desarrolladores automatizar la creación de documentos mientras aseguran un formato consistente y profesional similar al de Microsoft Word.
Ahmad es un desarrollador full-stack con una sólida base en C#, Python y tecnologías web. Tiene un profundo interés en construir soluciones de software escalables y disfruta explorando cómo el diseño y la funcionalidad se encuentran en aplicaciones del mundo real.