wordpress hit counter
Welcome to OpenXML Developer Sign in | Join | Help

Data-Driven Document Generation (docx) from a Template (dotx)

Last post 04-12-2009, 11:21 PM by pratikkothari1. 2 replies.
Sort Posts: Previous Next
  •  01-14-2009, 8:23 AM 3996

    Data-Driven Document Generation (docx) from a Template (dotx)

    I would like to automate the generation of documents from data stored in an Excel spreadsheet. The task is not to simply replace content controls with text because there is an iterative element - I need to take a template (stored as a Building Block or docPart), make several copies of it and fill in the blanks to produce the final document.

    I have created the docPart in my dotx template and I can see it in glossary/document.xml as a <w:docPart> element. This allows me to edit the style of the repeatable elements using the Word UI.

    What is the best method for generating a docx from this dotx by creating multiple new instances of the <w:DocPart> element and filling in the placeholders with data within each instance?

    I am writing the application as a Windows Forms C#.NET and don't mind using either Interop Automation or the OpenXML SDK - whichever is most useful.

    Any ideas on what I need to read up on?
  •  02-08-2009, 4:51 PM 4047 in reply to 3996

    Re: Data-Driven Document Generation (docx) from a Template (dotx)

    Hi There.

    I'd probably work this up with the Open XML Format SDK. Make sure that you use version 2.0 of the SDK.

    You may find that for the actual content generation it is useful to use XSLT to take your source data (as XML) and use this to generate your docPart (as XML) then use the Open XML Format SDK to package this up.
  •  04-12-2009, 11:21 PM 4471 in reply to 4047

    Re: Data-Driven Document Generation (docx) from a Template (dotx)

    Hello cauld,

    I have very little experience with OpenXML. I was very amused with your reply.

    When you say the actual content generation, what exactly do you mean by that? Can you please elaborate on this technique?

    Why would be the usage of XSLT be beneficial when you can use OpenXML by itself? I am sure there are some advantages. What are they?

    Thanks in advance.
View as RSS news feed in XML