title: Iterating through word document in OpenXml entering text into bookmarks (losing formatting)
body: <p>I have a word document with bookmarks set. The bookmarks are ultra-simple and do not span tables or paragraphs. The following code works but I lose the formatting from the document and the insert uses word's default font &amp; size etc. How can I just enter text into the bookmark keeping the documents formatting?</p>
  
  <pre><code>using (var wordDoc = WordprocessingDocument.Open(targetFileName, true))
  {
      MainDocumentPart mainPart = wordDoc.MainDocumentPart;
  
      var bookmarkStarts = mainPart.Document.Descendants&lt;BookmarkStart&gt;().ToList();
  
      foreach (BookmarkStart bookmarkStart in bookmarkStarts)
      {
        InsertIntoBookmark(bookmarkStart, "Hello");
      }
  }
  
  private static void InsertIntoBookmark(BookmarkStart bookmarkStart, string text)
  {
      OpenXmlElement elem = bookmarkStart.NextSibling();
  
      while (elem != null &amp;&amp; !(elem is BookmarkEnd))
      {
          OpenXmlElement nextElem = elem.NextSibling();
          elem.Remove();
          elem = nextElem;
      }
      Run run = new Run();
      run.Append(new Text(text));
      bookmarkStart.Parent.InsertAfter&lt;Run&gt;(run, bookmarkStart);
  }
  </code></pre>