c# word interop find and replace everything

后端 未结 4 470
离开以前
离开以前 2020-12-05 06:07

I have some code to replace text inside a word 2010 docx.

        object fileName = Path.Combine(System.Windows.Forms.Application.StartupPath, \"document.doc         


        
4条回答
  •  独厮守ぢ
    2020-12-05 06:26

    From Visual Studio 2013 you can do this:

    Microsoft.Office.Interop.Word.Range range = this.Application.ActiveDocument.Content;
    range.Find.ClearFormatting();
    range.Find.Execute(FindText: "find text", ReplaceWith: "replace text", Replace: Word.WdReplace.wdReplaceAll);
    

    (Posted for the benefit of anyone, like me, who came across this question but is not necessarily using the same versions of the tools as the OP.)

提交回复
热议问题