I've been running at a fast pace for the past few days, so I'm going to add a few posts here to catch up.
Day 3 of the DevDays event in the Netherlands was a success. I delivered a session on "Open XML Solution Building With Word and Excel Services". Huge thanks to Zeyad Rajabi for pulling together some of the server-side demos I showed.
Among the 10 or so demos I showed I showed people how to connect to a datasource and start pumping data into a document. For example, what about connecting to a database and producing a Word document through Open XML? It's a common scenario, and there are lots of blog entries out there that show how to do this. Well, here's another one!
A common developer task to produce Word documents based on data in a database. I'm going to show you how to pump data into a table in Word with some formatting.
By following these steps you will be able to:
1. Create a new project for your Open XML Solution
2. Add the proper references
3. Connect to a database (in this case SQL Azure!)
4. Loop through LINQ query results
5. Add a new table to the document with columns and rows
6. Test the application
All mistakes herein, if any, are my own. Please alert me to potential errors.
Set Up The VS Project & Debug
Before creating this solution, make sure you have installed the Open XML SDK 2.0. Also, make sure you have access to the AdventureWorks database. You can still install this database from here: http://sqlserversamples.codeplex.com/wikipage?title=SQLServerDatabasesandSamplesOverview.
Now, you can alter the code in the GenerateContent procedure to alter the formatting, add new columns etc.
· Brian Jones & Zeyad Rajabi's blog: http://blogs.msdn.com/brian_jones/
· Eric White's blog: http://blogs.msdn.com/ericwhite/
· Open XML Web Site: www.openxmldeveloper.org
· Open XML on MSDN: http://msdn.microsoft.com/en-us/office/bb265236.aspx
Here's a vide of two people I meet at the show in the Netherlands. They are both very smart and very nice!