
It is for refresh cross reference bookmark, that you can use one bookmark on different location in document. Var sealPath = ConfigurationManager.AppSettings īookmarksNavigator.MoveToBookmark("seal", true, true) īookmarksNavigator.InsertParagraph(paragraph) Var bookmarksNavigator = new BookmarksNavigator(document) īookmarksNavigator.MoveToBookmark("client_name") īookmarksNavigator.ReplaceBookmarkContent("Ramil", true) īookmarksNavigator.MoveToBookmark("client_taxno") īookmarksNavigator.ReplaceBookmarkContent("VN-12300254178XY6", true) īookmarksNavigator.MoveToBookmark("amount") īookmarksNavigator.ReplaceBookmarkContent("871 AZN", true) īookmarksNavigator.MoveToBookmark("date") īookmarksNavigator.ReplaceBookmarkContent(("dd.MM.yyyy"), true) Var document = new Document(sourceFilePath) Var saveFilePath = ConfigurationManager.AppSettings Var sourceFilePath = ConfigurationManager.AppSettings
#Word numwords in a bookmark how to
I have a github repo, that I showed an example how to working it. You can use Spire.Doc or FreeSpire.Doc library for this purpose. If you need more examples I'm working on a blog post as well, so I have a lot more detail if this wasn't clear enough for your use case. Sometimes if you have large amounts of fields you can build objects/classes to contain the values.
#Word numwords in a bookmark code
This code should get you up and running unless you want to pass in all the values into a function.

Application app = new Application() ĭocument doc = ("sDocumentCopyPath.docx") ĭoc.Bookmarks.get_Item(ref oBookMark).Range.Text = My Text To Replace bookmark_1 ĭoc.Bookmarks.get_Item(ref oBookMark).Range.Text = My Text To Replace bookmark_2 ĭoc.ExportAsFixedFormat("myNewPdf.pdf", WdExportFormat.wdExportFormatPDF)

The function call can get long sometimes, but it works for me. I always create a function to accomplish this, and I end up passing in the path - as well as all of the text to replace my in-document bookmarks. So basically if you want to automate word documents (building word document templates via word bookmarks) Here's how I normally go about doing it.Įach of the sections that you are replacing within your word document you have to insert a bookmark for that location (easiest way to input text in an area).
