I have a C# program that generates documents using OpenXml. It replaces bookmarks with values using the following method :
private void FillBookmark(BookmarkStart bookmark, string value)
{
var text = new Text(value);
bookmark.RemoveAllChildren();
IEnumerable<OpenXmlElement> elementsAfter = bookmark.ElementsAfter();
IEnumerable<OpenXmlElement> insideBookmark = elementsAfter.TakeWhile(element => !(element is BookmarkEnd));
foreach (OpenXmlElement element in insideBookmark)
{
element.RemoveAllChildren();
}
OpenXmlElement previousSibling = bookmark.PreviousSibling();
while (previousSibling is BookmarkStart || previousSibling is BookmarkEnd)
{
previousSibling = previousSibling.PreviousSibling();
}
var container = new Run(text);
previousSibling.AppendChild(container);
}
In this particular word document, the font used is Raleway. There are several bookmarks and after the execution of this method, two bookmarks are using the Calibri font. I tried to rewrite theses bookmarks to be sure they are in Raleway but they continue to change to Calibri.
How is this possible ?