0

All,

I am using OpenXML to automatically insert text into bookmarks. The following is working phenomenally:

Body body = mainPart.Document.GetFirstChild<Body>();
var bookMarkStarts = body.Descendants<BookmarkStart>();
var bookMarkEnds = body.Descendants<BookmarkEnd>();

foreach (BookmarkStart bookMarkStart in bookMarkStarts)
{
    if (bookMarkStart.Name == bookmarkName)
    {
        //Get the id of the bookmark start to find the bookmark end
        var id = bookMarkStart.Id.Value;
        var bookmarkEnd = bookMarkEnds.Where(i => i.Id.Value == id).First();

        var runElement = new Run(new Text("Hello World!!!"));

        bookmarkEnd.Parent.InsertAfter(runElement, bookmarkEnd);
    }
}

I was wondering if someone could help me change the styling of the text within the bookmarks. Right now they are all bolded and I would prefer if they were not. I would possibly like to change the color of the text as well.

I thank you

Maarten van Stam
  • 1,901
  • 1
  • 11
  • 16
AMAR PANRAY
  • 351
  • 3
  • 8
  • There's some example code on styling text in Word using OpenXml in [my answer here](https://stackoverflow.com/questions/25056927/unable-to-use-existing-paragraph-styles-in-open-xml/25058393#25058393). Does that help? – petelids Jun 22 '17 at 13:15
  • Yes it does. Thanks – AMAR PANRAY Jul 12 '17 at 16:35

0 Answers0