Search code examples
c#ms-wordbookmarks

filling word bookmarks from view


Context of my problem is, I have to build a connection to word from another program. The user has all the fields visible in a template to set them as bookmarks, so the user will dynamicly create a template with bookmarks. If this is a document with no lists (multiple rows of view) all is good. The bookmarks are replaced with the needed information.

The problem I have is when there are lists in the template. They only set the bookmark once, so i have to copy it in somehow with the right position and style etc, cause i have to be able to print the list per line.

An example of this is: enter image description here

When i print one line, i lose the bookmark. Is there any way to know if the bookmark is in a table or not? And is it possible to copy the bookmark with the right position etc?

I am using C# with microsoft.office.interop.word.
Currently putting all the list items in one cell devided by an enter. Should i use the xml scheme to do this?
(it should be possible to get even subrows to the current table)


Solution

  • I've solved the problem with merge fields in Word.

    First i load the template in my docx.

    Then i copy the paragraphs (with the right level indication) as many times as there are rows for that level.

    Then what's left is to fill all the merge fields with the according rows.