Generating Open XML WordprocessingML Documents

This is a blog post series on parameterized Open XML WordprocessingML document generation.  While it is easy enough to write an purpose-built application that generates WordprocessingML documents, too often, developers find themselves building new applications for similar but somewhat different scenarios.  However, if we take the right approach, it is possible to build a simple document generation system that makes it far easier to address a wide variety of scenarios.  I believe that a flexible document generation system can be written in a few hundred lines of code.  This page lists the posts that are part of the series.  I’ll be updating this page with new posts as I write them.

When I started this series, I initially started using a design where the document template designer writes C# code in content controls. That approach is interesting, and it was fun to write. However, I have determined that writing XPath expressions in content controls is a superior approach. I am going to let those twelve posts stand on their own, and start a new list of posts. I’ll maintain both lists on this page.

XPath-in-Content-Controls

Post Title Description
1 Generating Open XML WordprocessingML Documents using XPath Expressions in Content Controls In this post, I present the ideas around configuring the document template for mass document generation using XPath expressions in content controls.
2 Release of V2 of Doc Gen System: XPath in Content Controls Release of V2 of a simple document generation system. In this example, you configure the document generation process by creating a template document that contains content controls. You then enter XPath expressions in the content controls to configure how the document generator pulls data from a source XML file.
3 Review of XPath Semantics of LINQ to XML In this post, I discuss the semantics of the XPath extension methods. In addition, I provide a small example that demonstrates how the various XPath expressions in the template document are related to each other.
4 Change the Schema for Simple Free Doc Generation System Short (3-minute) screen-cast that shows changing the schema for the XPath-in-Content-Controls approach to document generation.

C#-in-Content-Controls

Post Title Description
1 Generating Open XML WordprocessingML Documents Introduces this blog post series, outlines the goals of the series, and desribes various approaches that I may take as I develop some document generation examples.
2 Using a WordprocessingML Document as a Template in the Document Generation Process In this post, I examine the approaches for building a template document for the document generation process. In my approach to document generation, a template document is a DOCX document that contains content controls that will control the document generation process.
3 The Second Iteration of the Template Document Based on feedback, this post shows an updated design for the template document.
4 More enhancements to the Template Document This post discusses an enhancement to the document template that enables the template designer to add infrastructure code. In addition, it discusses how the document generation process will work.
5 Generating C# Code from an XML Tree using Virtual Extension Methods Presents code that given any arbitrary LINQ to XML tree, can generate code that will create that tree. The code to generate code is written as a recursive functional transform from XML to C#.
6 Simulating Virtual Extension Methods Shows one approach for extending a class hierarchy by simulating virtual extension methods.
7 Refinement: Generating C# code from an XML Tree using Virtual Extension Methods Makes the approach of generating code that will generate an arbitrary XML tree more robust.
8 Text Templates (T4) and the Code Generation Process Explores T4 text templates, and considers how they can be used in the Open XML document generation process.
9 A Super-Simple Template System Defines a template system that makes it easier to generate C# code.
10 Video of use of Document Generation Example Screen-cast that shows the doc gen system in action.
11 Release of V1 of Simple DOCX Generation System Release of the first version of this simple prototype doc gen system.
12 Changing the Schema for the Document Generation System Contains a short screen-cast that shows how to adjust the data coming into the doc gen system, and to adjust the document template to use the new data.