using IronWord;
using IronWord.Models;
// Load docx
WordDocument doc = new WordDocument("document.docx");
// Configure text
Text introText = new Text("This is an example paragraph with italic and bold styling.");
TextStyle italicStyle = new TextStyle()
{
IsItalic = true
};
Text italicText = new Text("Italic example sentence.");
italicText.Style = italicStyle;
TextStyle boldStyle = new TextStyle()
{
IsBold = true
};
Text boldText = new Text("Bold example sentence.");
boldText.Style= boldStyle;
Paragraph paragraph = new Paragraph();
// Add text
paragraph.AddText(introText);
paragraph.AddText(italicText);
paragraph.AddText(boldText);
// Add paragraph
doc.AddParagraph(paragraph);
// Export docx
doc.SaveAs("save_document.docx");
Imports IronWord
Imports IronWord.Models
' Load docx
Private doc As New WordDocument("document.docx")
' Configure text
Private introText As New Text("This is an example paragraph with italic and bold styling.")
Private italicStyle As New TextStyle() With {.IsItalic = True}
Private italicText As New Text("Italic example sentence.")
italicText.Style = italicStyle
Dim boldStyle As New TextStyle() With {.IsBold = True}
Dim boldText As New Text("Bold example sentence.")
boldText.Style= boldStyle
Dim paragraph As New Paragraph()
' Add text
paragraph.AddText(introText)
paragraph.AddText(italicText)
paragraph.AddText(boldText)
' Add paragraph
doc.AddParagraph(paragraph)
' Export docx
doc.SaveAs("save_document.docx")
Install-Package IronWord
Add Paragraph
One of the building blocks of a Word document is a paragraph. A paragraph can contain various elements, such as texts, images, and shapes. The code example above demonstrates adding a paragraph with differently styled text to a newly created Word document.
In this example, a new Word document is created along with multiple texts styled differently. Each text is added to the paragraph using the AddText method. The paragraph is then added to the document using the AddParagraph method. Finally, the new document is exported to a file.
Related Docs Links
Ready to get started? Version: 2024.10 just released