Search code examples
c#.netopenxmlwordml

Custom placeholders/tags for dynamic content in a Word template


I have a web application (ASP.NET C#) where I would like the users to be able to upload word templates (essentially word document with predefined set of tags serving as placeholders). Part of the complication is I want to allow for using loops as well. Finally I want to be able to parse the XML and replace the placeholders with content fetched from the database. For example a conceptual template may be:

Name: <firstName> <lastName>
Phone Numbers:
<for-each:phoneNumber>
Region Code: <regionCode>
Number: <number>
</end:for-each>

Are there any existing solutions that address this issue? Has anyone tried to achieve this or similar?


Solution

  • I've documented the approach to this that I have devised at opendope.org

    It is based on CustomXML databinding (not to be confused with the stuff at issue in the i4i patent farce), extendedto allow loops.

    For a proof of concept demo, see www.fabdocx.com

    There isn't an OpenXML SDK C# implementation yet so far as I am aware, but you could convert the equivalent Java code.