We just converted our Office Interop project over to Spire.Doc. Everything is working fine, but we just noticed that the bookmarks in the headers/footers aren't being replaced. We have a generic system that has thousands of word templates/docs that it will open and then replace the bookmarks with data from our DB (meaning we know neither which bookmarks are in a template nor which fields they will need from the DB).
The way we do this now is
- Code: Select all
var navigator = new BookmarksNavigator(doc);
List<Bookmark> bookmarks = doc.Bookmarks.Cast<Bookmark>().ToList();
foreach (Bookmark bookmark in bookmarks)
{
string dbValue = getDBValue(bookmark.Name);
navigator.MoveToBookmark(bookmark.Name);
navigator.ReplaceBookmarkContent(DBvalue, true);
}
This works great for all the bookmarks except for the ones in the headers/footers (which did work fine in Office Interop). I have no way of changing the Word templates, but I suspect my problem is just that doc.Bookmarks doesn't contain the header bookmarks and if I could just append to that list any bookmarks I find in the headers and footers then the rest of the code would fall magically into place.
However, in working down the object tree on the HeaderFooter.Header class, I don't see how I can get a list of bookmarks. Any help?
I can process headers and footers explicitly outside this foreach loop if need be, but it still doesn't help me as far as getting the bookmark names (which I will need as they match our DB field names).