编辑文字
使用IronWord编辑现有Word文档中的文本,方法是在文档树中定位文本并更改其内容。 上面的代码示例访问位于第一段中的TextRun。 然后,它将TextRun内容更改为“这是编辑后的文本。”此操作仅更改文本内容,不会改变与该TextRun关联的任何样式。
using IronWord; // Open existing Word WordDocument doc = new WordDocument("sample.docx"); // Edit existing text doc.Paragraphs[0].Texts[0].Text = "This is the edited text."; // Export docx doc.SaveAs("document.docx");
Imports IronWord ' Open existing Word Private doc As New WordDocument("sample.docx") ' Edit existing text Private doc.Paragraphs(0).Texts(0).Text = "This is the edited text." ' Export docx doc.SaveAs("document.docx")
Install-Package IronWord
使用IronWord编辑现有Word文档中的文本,方法是在文档树中定位文本并更改其内容。 上面的代码示例访问位于第一段中的TextRun。 然后,它将TextRun内容更改为“这是编辑后的文本。”此操作仅更改文本内容,不会改变与该TextRun关联的任何样式。