To create text documents based on data from an SQL database, I use the Office Open XML SDK to avoid using interoperability. This speeds up the process and eliminates the need to install the Microsoft office suite on the client system.
While this works very well, a problem arises when replacing certain text in a document. To save the final document setting as an option, I created a document with some tags in it as a template. This template contains tags such as [TagHere]. Since tag names should be easy to read, they can be used throughout the document, so I surrounded the tag with braces [].
This works fine, but sometimes a problem occurs. When you enter a docx document, the text can be divided into several tags, even in the same word. A tag of type [TagHere] can be divided into
<tag>[</tag><tag>TagHere</tag><tag>]</tag>
If this happens, the replacement will not work.
Now in the docx format, there are several alternative options for performing operations such as Content Controls, but they make the process of creating a template more complex. Moreover, there is nothing unusual in these documents to get one row of a table with tags and copy it several times, which is likely to violate the principle of a content tag. Therefore, I decided not to use this option.
It would be great if someone had a solution to this problem.
source share