I have some code to replace text inside a 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);
This works without formatting. But when {id} is formatted it does not replace the text.
How can I make this code ignore formatting?
I use this function to find and replace. you can specify any of the options.
And usage would be :
And you can use the FindAndReplace function over and over....
Hope this helps.
A method that divides a string if the string contains more than 255 characters.
From Visual Studio 2013 you can do this:
(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.)
You can try this :