Reader Question - How to create documents programmatically.
Sometimes I get mail directly through the blog. I'm usually happy to answer questions directly, but I find most questions that are really pertinent for everyone.
"Previously with Office 2003, one could use com APIs to invoke word and create new documents (and insert data into it). WIth the new file formats, since we can use just XPS/WinFX APIs to create/navigate these documents, what's the approach one should take to create the xml/zip based document and then insert data into it? Also, the default behavior in office2003 was you could open this newly created doc and show the user the data you inserted. Any samples or references that will help me do the above? Would using VSTO here (in my application) be good? Also, was wondering how does one "read" (display) the new file formats without hosting word inside the applicatin? Since these are open file formats, I was hoping there is another way to do that. - Keeron"
You will be able to use the application COM or VBA programmability support to create Office files in Office 2007. Of course, we don't recommend or support doing this in a server environment. You can create, from scratch, a new Office Open XML file using the Packaging APIs and XML libraries. Just create a package and start adding the appropriate parts and relationships and validate the schemas of the parts. You can even use a third-party ZIP and XML library. However, it will require some code to do this (more than I can provide in a sample, anyway). My recommendation is to start with a template created from the application. Then, you can just fill in the data that is required.
You can display the data from the application using the same technologies (Zip and XML), but don't expect to get the fidelity that the Office applicaitons provide without a lot of code.
- Kevin