using IronWord;
using IronWord.Models;
// Load docx
WordDocument doc = new WordDocument("document.docx");
// Configure text
TextContent introText = new TextContent("This is an example paragraph with italic and bold styling.");
TextStyle italicStyle = new TextStyle()
{
IsItalic = true
};
Run italicRun = new Run(new TextContent("Italic example sentence."));
italicRun.Style = italicStyle;
TextStyle boldStyle = new TextStyle()
{
IsBold = true
};
Run boldRun = new Run(new TextContent("Bold example sentence."));
boldRun.Style = boldStyle;
Paragraph paragraph = new Paragraph();
// Add text
paragraph.AddText(introText);
paragraph.AddChild(italicRun);
paragraph.AddChild(boldRun);
// Add paragraph
doc.AddParagraph(paragraph);
// Export docx
doc.SaveAs("save_document.docx");
Imports IronWord
Imports IronWord.Models
' Load docx
Dim doc As New WordDocument("document.docx")
' Configure text
Dim introText As New TextContent("This is an example paragraph with italic and bold styling.")
Dim italicStyle As New TextStyle() With {
.IsItalic = True
}
Dim italicRun As New Run(New TextContent("Italic example sentence."))
italicRun.Style = italicStyle
Dim boldStyle As New TextStyle() With {
.IsBold = True
}
Dim boldRun As New Run(New TextContent("Bold example sentence."))
boldRun.Style = boldStyle
Dim paragraph As New Paragraph()
' Add text
paragraph.AddText(introText)
paragraph.AddChild(italicRun)
paragraph.AddChild(boldRun)
' Add paragraph
doc.AddParagraph(paragraph)
' Export docx
doc.SaveAs("save_document.docx")
Install-Package IronWord
添加段落
IronWord 中的"添加段落"功能允许开发人员将整个段落插入到现有的 Word 文档中,从而提供了一种有效构建和组织内容的方法。 通过添加段落,开发人员可以将格式不同的多段文本合并成一个连贯的文本块。 此功能对于构建需要将文本分组并设置样式的动态文档(例如报告、文章或信件)尤其有用。