英文:
how can i find and replace text in .docx(Microsoft word file) using Interop
问题
我想打开一个docx文件,并替换我想要的特定单词。
例如,我想把A改成B,对于文档中的所有文本...
我对此一无所知... 请帮帮我... 谢谢
英文:
enter image description here
i wanna open a docx file and replacing a specific word that i want.
for example i wanna change A with B for all the texts inside the word file..
i have no idea for this... please help me.. thank you
答案1
得分: 1
你已经完成了一半。在你的示例中,你打开了文档:
Document docs = word.Documents.Open("path/file.docx");
现在我们需要替换文本:
docs.Content.Find.Execute(FindText: "oldtext", ReplaceWith: "newtext", Replace: WdReplace.wdReplaceAll, Missing: System.Reflection.Missing.Value);
docs.Save();
docs.Close();
wordApp.Quit();
英文:
Hey you are already halfway there. In your example you opend the doc
Document docs = word.Documents.Open("path/file.docx");
Now we need to replace the text
docs.Content.Find.Execute(FindText: "oldtext", ReplaceWith: "newtext", Replace: WdReplace.wdReplaceAll, Missing: System.Reflection.Missing.Value);
docs.Save();
docs.Close();
wordApp.Quit();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论