Welcome to MSDN Blogs Sign in | Join | Help

Erika Ehrli

Adventures in Office Development and .NET

News

  • who's online visitors here with you. Programming Microsoft® Office Business Applications Locations of visitors to this page
    Bookmark and Share
    Erika Ehrli on Twitter MSDN_Office in Twitter Follow us on Twitter
    MSDN_Office in Facebook Join MSDN Office on Facebook
A common business need: Generating server-side documents on the fly

I gathered a list of common Open XML questions related to programmability:

  1. What are the Open XML File Formats and what can I do with them?
  2. Can you show me the internal structure of a Word 2007 document?
  3. What are WordprocessingML, SpreadsheetML, PresentationML, and DrawingML?
  4. Do you have a .NET API that I can use to generate documents programmatically (server-side)?
  5. What is the architecture of a server-side OBA document generation solution?
  6. How can I generate a document programmatically and have more control over document content?
  7. How do you add images to an Open XML document?
  8. How can I pull data from my data source and create a table in a document?
  9. How can I add styles and format to my document content?
  10. What about compatibility with previous versions of Office?

Office Business Applications + Open XML File Formats

When you are trying to create a document assembly solution and you are want to understand how you can use the Open XML File Formats to generate a document programmatically, you may be faced to some of the previous questions. All this questions have been answered in multiple MSDN articles, SDKs, blogs, trainings, forums, and newsgroups. However, I am the kind of person that loves end-to-end documentation and code samples that take you from zero to a working solution. We all have limited time to learn new technologies and walkthrough articles and code sample downloads are always a nice option.

Some time ago I tried to do the same thing and I blogged to show you how to generate a document using a document template, content controls, and XML mapping. I also created a little video and article that shows how to bind custom xml to a document template. This approach is great when you are trying to replace placeholder data in document templates like an invoice or contract. However, your business needs may be different and you may want to have more control over document content and formatting. In that case a better approach would be to manipulate the WordProcessingML content stored in different document parts.

I wrote a new article that helps answer the Open XML questions listed in this blog entry. I split the article in two parts and a code sample download. I start by discussing all the theory and basic concepts you need to learn to work with the Open XML File Formats. For example, I talk about Open XML Package Architecture, WordprocessingML basics, the Open XML object model, and the conceptual architecture of a document integration solution.

The second part explains all the coding that needs to happen to generate a simple sales document from scratch. I show you how to deal with images, tables, styles, and formatting. I also show how to create a helper class that pulls data from your line of business systems (in this case the AdventureWorks sample database to keep the LOB piece as simple as possible), and a helper class that uses the Open XML object model and WordprocessingML to create a document.

You can find the articles and code samples here:

Many thanks go to Doug Mahugh, Wouter van Vugt, and Frank Rice for sharing all their knowledge and helping me put this together. I hope this helps you get started with custom document generation with Open XML.

Enjoy!

Posted: Wednesday, August 22, 2007 1:08 PM by erikaehrli

Comments

Brena said:

Hi Erika - Thank you thank you thank you!

# August 22, 2007 6:16 PM

Wouter said:

It's looking great Erika, nice!

# August 23, 2007 10:32 AM

Doug Mahugh said:

Erika Ehrli has a great post on "Building Server-Side Document Generation Solutions" that shows how to

# August 23, 2007 12:55 PM

Andrew Coates ::: MSFT said:

Via Doug . One of the great features of the New OpenXML file formats used by Office 2007 is their server-side

# August 23, 2007 11:50 PM

Noticias externas said:

Via Doug . One of the great features of the New OpenXML file formats used by Office 2007 is their server

# August 24, 2007 12:09 AM

Mike Walker's Ramblings about Industry Architecture said:

Erika has a post on OpenXML integration.Check it out. Tags: OBA OpenXML

# August 27, 2007 3:29 AM

iFX said:

OpenXML Integration into Applications

# August 27, 2007 4:32 AM

Jan Novak, Czech Republic said:

Hi, I read on Slashdot and other reliable sources that in both Sweden and Germany your company, Erika, is _cheating_ in order to push OOXML into ISO standard. Format name (OOXML) resambling Open Office product is pitiful on its own. As any programmer trying to make convertor for this format knows, this whole thing makes no sense and is only ment to extend MS monopoly, not to help sharing of documents among various applications. As another guy said "two ways to represent the date - one of them representing dates between 1900 and 20000 and another one to represent dates between 1904 and 20000 where the second one is a complete subset of the first one are dangerous to the mental health of the reader.".

# August 28, 2007 12:15 PM

erikaehrli said:

Brena, Wouter, Andrew, and Mike: Thanks for the nice comments and trackbacks. I am glad to see you find this useful.

Jan, you should follow-up Doug's blog post:

http://blogs.msdn.com/dmahugh/archive/2007/08/30/oh-the-drama-of-it-all.aspx

I am sure you will find his blog quite useful :).

# August 31, 2007 8:39 PM

Sofia said:

[...]Very handy post.

http://paper-machines.com/

[...]

# November 8, 2007 6:54 AM

Christoffel Klimbie said:

An alternative towards building your own document composition engine is to purchase an out of the box solution. I work for Aia Software and we deliver such solutions. Many of the articles on my blog www.datatextmerge.com are related to the question make or buy - there may be information on it which is relevant for you.

# November 12, 2008 10:39 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker