C
C#3w ago
Piero512

Edit a custom templated Word document and preview a read only version of the modified text.

Hello. I was looking into some libraries to manipulate a word document and to preview it on WinForms, but I can't seem to find good candidates for a single one that does it. My existing solution takes the template docx, makes a copy of it, uses the openxml package to go through each Text node to look for the #PLACEHOLDER# and replaces it, but it can't deal with line breaks. It also can't preview the document, so it calls the default docx handler to print/display the document.
4 Replies
Piero512
Piero512OP3w ago
The current algorithm has the problem that sometimes Word, by inserting tracking information, splits the runs so the placeholder ends up like this.
Piero512
Piero512OP3w ago
No description
Piero512
Piero512OP3w ago
left is how it's giving me problems, right is how the algorithm will probably pick it up. I wonder if I can instead tell the user to create mail merge placeholders, but openxml probably doesn't mail merge There's also the constraint that how the existing placeholder infrastructure works is that there are header/footer placeholders, and body placeholders, which could be dealt later, but before we could just use Word Interop, but now we can't.
Anton
Anton2w ago
you can word interop if your app is windows only

Did you find this page helpful?