How to Add Style to Text in DOCX

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

Customizing text styling in Word documents is essential for creating professional and visually appealing content. IronWord offers industry-grade text styling options similar to what's available in your favorite DOCX editor, allowing you to apply formatting programmatically with ease.

In this how-to, we'll explore how to stylize text content with custom settings using IronWord's TextStyle class.

Get started with IronWord

Nutzen Sie IronWord heute kostenlos in Ihrem Projekt.

Erster Schritt:
green arrow pointer


Adding Text Style Example

Applying text styles in IronWord is straightforward. Create a WordDocument object, then create a TextContent object with your text. Apply a TextStyle to it using properties such as IsBold, Color, or TextFont, and enhance the styling further with options like underline or strikethrough.

Once the text is fully styled, add it to a Paragraph, insert the paragraph into the document, and save the final result.

:path=/static-assets/word/content-code-examples/how-to/add-style-text-simple.cs
using IronWord;

// Load docx
WordDocument doc = new WordDocument("sample.docx");

// Configure text
TextContent text = new TextContent();
text.Text = "Add text using IronWord";

// Configure text style settings
text.Style = new TextStyle()
{
    TextFont = new Font()
    {
        FontFamily = "Calibri", // Text Font is "Calibri"
        FontSize = 24, // Text Size is 24
    },
    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, // No strike-through
};

Paragraph paragraph = new Paragraph();

// Add text to paragraph
paragraph.AddText(text);

// Add paragraph to document
doc.AddParagraph(paragraph);

// Save document
doc.SaveAs("add-text-style.docx");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Output

Add style to text in DOCX

The TextStyle class provides essential formatting options, including font properties, text color, bold, italic, and underline, giving you the flexibility to create professional-looking documents quickly.


Adding Specific Styles

Text Color

The Color property in TextStyle allows you to set text color using predefined colors from IronWord.Models.Color or custom hex values. This is useful for emphasizing specific content or matching brand colors in your documents.

:path=/static-assets/word/content-code-examples/how-to/add-style-text-add-text.cs
using IronWord;

// Create document
WordDocument doc = new WordDocument();

// Add colored text
TextContent text = new TextContent("This text is olive-colored!");
text.Style = new TextStyle()
{
    Color = IronWord.Models.Color.Olive // defining text to be colored olive
};

Paragraph paragraph = new Paragraph();
paragraph.AddText(text);
doc.AddParagraph(paragraph);

// Save document
doc.SaveAs("colored-text.docx");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Output

Add text color in DOCX

Font Family and Size

Customize text appearance with the TextFont property. Set FontFamily to any installed font name (e.g., "Arial", "Times New Roman") and FontSize in points. This allows you to match document styles or establish a clear visual hierarchy.

:path=/static-assets/word/content-code-examples/how-to/add-style-text-add-font.cs
using IronWord;

// Create document
WordDocument doc = new WordDocument();

// Add text with custom font family and size
TextContent text = new TextContent("This text uses Arial at 24pt!");
text.Style = new TextStyle()
{
    TextFont = new IronWord.Models.Font()
    {
        FontFamily = "Arial",  // Set font family
        FontSize = 24          // Set font size in points
    }
};

Paragraph paragraph = new Paragraph();
paragraph.AddText(text);
doc.AddParagraph(paragraph);

// Save document
doc.SaveAs("font-styled-text.docx");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Output

Add font style to text in DOCX

Bold

Use the IsBold property set to true to make text bold. Bold text is commonly used for headings, emphasis, or highlighting important information in your documents.

:path=/static-assets/word/content-code-examples/how-to/add-style-text-add-bold.cs
using IronWord;

// Create document
WordDocument doc = new WordDocument();

// Add bold text
TextContent text = new TextContent("this is bold!");
text.Style = new TextStyle()
{
    IsBold = true  // Make text bold
};

Paragraph paragraph = new Paragraph();
paragraph.AddText(text);
doc.AddParagraph(paragraph);

// Save document
doc.SaveAs("bold-text.docx");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Output

Add bold text in DOCX

Italic

The IsItalic property set to true applies italic styling to text. Italic text is typically used for emphasis, titles, foreign words, or technical terms.

:path=/static-assets/word/content-code-examples/how-to/add-style-text-add-italic.cs
using IronWord;

// Create document
WordDocument doc = new WordDocument();

// Add italic text
TextContent text = new TextContent("this is italic.");
text.Style = new TextStyle()
{
    IsItalic = true  // Make text italic
};

Paragraph paragraph = new Paragraph();
paragraph.AddText(text);
doc.AddParagraph(paragraph);

// Save document
doc.SaveAs("italic-text.docx");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Output

Add italic text in DOCX

Styling Properties

Expore more styling options in the below table.

Styling Method Description Example
TextFont Customizes text appearance with a Font object, setting font family and size in points. text.Style.TextFont = new Font() { FontFamily = "Calibri", FontSize = 24 };
Color Sets text color using predefined colors from IronWord.Models.Color or custom hex values. text.Style.Color = IronWord.Models.Color.Red;
IsBold Makes text bold when set to true, commonly used for headings or emphasis. text.Style.IsBold = true;
IsItalic Applies italic styling to text when set to true, typically used for emphasis or titles. text.Style.IsItalic = true;
Underline Adds an underline to text using an Underline object with various underline styles. text.Style.Underline = new Underline();
Strike Applies strikethrough to text using StrikeValue enum (Strike or DoubleStrike). text.Style.Strike = StrikeValue.Strike;
Caps Applies capitalization effects to text, converting all characters to uppercase display. text.Style.Caps = true;
CharacterScale Adjusts the proportional width of characters as a percentage of their normal size. text.Style.CharacterScale = 150;
Emboss Applies an embossed effect to text, creating a raised appearance. text.Style.Emboss = true;
Emphasis Adds emphasis marks to styled text using EmphasisMarkValues enum values. text.Style.Emphasis = EmphasisMarkValues.Dot;
LineSpacing Controls spacing between lines of text for improved readability using a LineSpacing object. text.Style.LineSpacing = new LineSpacing() { Value = 1.5 };
Outline Renders text with an outline effect, displaying only the character borders. text.Style.Outline = true;
Shading Applies background color or shading to text using a Shading object. text.Style.Shading = new Shading() { Color = Color.Yellow };
SmallCaps Converts lowercase letters to small capital letters while maintaining case distinction. text.Style.SmallCaps = true;
VerticalPosition Adjusts vertical placement of text relative to its baseline, measured in points. text.Style.VerticalPosition = 5.0;
VerticalTextAlignment Positions text vertically within its container using VerticalPositionValues enum. text.Style.VerticalTextAlignment = VerticalPositionValues.Superscript;

Häufig gestellte Fragen

Was ist IronWord?

IronWord ist eine .NET-Bibliothek, mit der Entwickler Word-Dokumente programmgesteuert erstellen, bearbeiten und manipulieren können. Sie bietet umfassende Funktionen für Textgestaltung und -formatierung.

Wie kann ich die Textfarbe in einer DOCX-Datei mit IronWord ändern?

IronWord bietet verschiedene Methoden zum Ändern von Textstilen, einschließlich der Textfarbe. Sie können den gewünschten Farbcode für den markierten Text in Ihrem Word-Dokument festlegen.

Kann IronWord Text in einem Word-Dokument fett formatieren?

Ja, IronWord unterstützt die Standardoptionen zur Textformatierung, einschließlich Fettdruck. Sie können bestimmte Textelemente in Ihren DOCX-Dateien fett formatieren.

Ist es mit IronWord möglich, mehrere Formatvorlagen auf einen Text anzuwenden?

Selbstverständlich bietet IronWord Ihnen die Möglichkeit, Text mit verschiedenen Formatierungsoptionen zu versehen. Sie können unterschiedliche Stile wie fett, kursiv und unterstrichen kombinieren, um Ihr Word-Dokument vollständig anzupassen.

Welche Arten von Textformatierungen können mit IronWord angewendet werden?

IronWord unterstützt eine Reihe von Textformatierungsoptionen, darunter Schriftgröße, Schriftfarbe, Fettdruck, Kursivschrift, Unterstreichung und mehr, sodass Sie das Erscheinungsbild Ihres DOCX-Dokuments individuell anpassen können.

Unterstützt IronWord benutzerdefinierte Schriftarten?

Ja, IronWord ermöglicht die Verwendung benutzerdefinierter Schriftarten in Ihren Word-Dokumenten. Sie können auf Ihrem System installierte Schriftarten auswählen, um das Erscheinungsbild des Dokuments zu verbessern.

Kann ich die Erstellung formatierter Word-Dokumente mit IronWord automatisieren?

IronWord wurde entwickelt, um die Erstellung und Formatierung von Word-Dokumenten zu automatisieren. Sie können Textstile programmgesteuert anwenden und ändern, um Dokumente effizient zu generieren.

Wie handhabt IronWord die Textausrichtung in DOCX-Dateien?

IronWord bietet Funktionen zum Anpassen der Textausrichtung in Ihren Word-Dokumenten. Sie können den Text je nach Ihren Layoutvorgaben linksbündig, rechtsbündig, zentriert oder im Blocksatz ausrichten.

Welche Vorteile bietet die Verwendung von IronWord für die Formatierung von DOCX-Texten?

Die Verwendung von IronWord zum Formatieren von DOCX-Texten bietet Vorteile wie die einfache Integration in .NET-Anwendungen, die Flexibilität bei der Anwendung verschiedener Textstile und die Möglichkeit, Aufgaben der Dokumentenverarbeitung zu automatisieren.

Ist IronWord mit verschiedenen Versionen von Microsoft Word kompatibel?

IronWord ist für die Arbeit mit DOCX-Dateien konzipiert, die mit verschiedenen Versionen von Microsoft Word kompatibel sind. Es bietet umfassende Unterstützung für das Erstellen und Bearbeiten dieser Dateien in unterschiedlichen Word-Versionen.

Ahmad Sohail
Full-Stack-Entwickler

Ahmad ist ein Full-Stack-Entwickler mit einer soliden Grundlage in C#, Python und Webtechnologien. Er hat ein großes Interesse am Aufbau skalierbarer Softwarelösungen und genießt es, zu erkunden, wie Design und Funktionalität in realen Anwendungen aufeinandertreffen.

Bevor er dem Iron Software Team beitrat, arbeitete ...

Weiterlesen
Bereit anzufangen?
Nuget Downloads 25,807 | Version: 2025.11 gerade veröffentlicht