I'm working in C# (.NET, WPF, MS VS 2013) with Microsoft.Office.Interop.Word. I open some MS word document. I change text and I save the result. But the problem is that the format of document (mainly font size) is changed. For example:
Hello World! (bold, font size 14)
Say Hello World! (regular, font size 12)
after changing and saving:
Hello World! (bold, font size 14)
Do not Say Hello World! (bold, font size 14)
Where make I mistake? Here is my code:
Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document doc = app.Documents.Open(FileName);
doc.Content.Text = Regex.Replace(doc.Content.Text, "Say", "Do not Say", RegexOptions.IgnoreCase);
FileName = FileName.Replace(".", "_new.");
object fileName = FileName;
doc.SaveAs2(ref fileName);