c# - word-interop-suchen und ersetzen alles

Ich habe einige code zu ersetzen text innerhalb eines word 2010-docx.

        object fileName = Path.Combine(System.Windows.Forms.Application.StartupPath, "document.docx");

        Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application { Visible = true };

        Microsoft.Office.Interop.Word.Document aDoc = wordApp.Documents.Open(ref fileName, ReadOnly: false, Visible: true);

        aDoc.Activate();

        Microsoft.Office.Interop.Word.Find fnd = wordApp.ActiveWindow.Selection.Find;

        fnd.ClearFormatting();
        fnd.Replacement.ClearFormatting();
        fnd.Forward = true;

        fnd.Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;

        fnd.Text = "{id}";
        fnd.Replacement.Text = "123456";
        fnd.Execute(Replace: WdReplace.wdReplaceAll);

Dies funktioniert ohne Formatierung. Aber wenn {id} formatiert ist, es ersetzt nicht den text.

Wie kann ich diese code Formatierung ignorieren?

InformationsquelleAutor Tom van den Berk | 2013-10-08

Schreibe einen Kommentar