User Tools

Site Tools

blog:2023-09-19_c_replace_text_in_word_document



2023-09-19 C#: Replace Text in Word Document

  • This code replace the text in word document from C#
  • foreach (Microsoft.Office.Interop.Word.Range tmpRange in oDoc.StoryRanges)
    {
      tmpRange.Find.Text = "{Date}";
      tmpRange.Find.Replacement.Text = DateTime.Now.ToString("MM/dd/yyyy");
      tmpRange.Find.Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;
      object replaceAll = Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll;
      tmpRange.Find.Execute(ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                            ref missing, ref missing, ref missing, ref replaceAll,
                            ref missing, ref missing, ref missing, ref missing);
    }

TAGS

  • 49 person(s) visited this page until now.

Permalink blog/2023-09-19_c_replace_text_in_word_document.txt · Last modified: 2023/09/19 17:02 by jethro

oeffentlich