Welcome to MSDN Blogs Sign in | Join | Help

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

Published Saturday, March 11, 2006 6:20 PM by KevinBoske

Comments

# re: Reader Question - How to create documents programmatically.

Hello Kevin,

I understand you should use the Packaging APIs to create or manipulate documents on the server. But can you use the same APIs from, for example, a custom task pane within the Office application? E.g. when you have a new document, can you access it via the Packaging APIs or should you then use the COM and VBA APIs?

Regards,

Onno
Thursday, March 23, 2006 10:06 AM by Onno

# re: Reader Question - How to create documents programmatically.

Great question!

Well, the Packaging API's are for accessing files on disk.  Yes, you could do this from a CTP, however, you'd be accessing another file (not the file that might be the Active document, for instance).  Once the file is loaded into an Office client, you then need to use COM/VBA and the client object model.
Friday, March 24, 2006 1:13 PM by KevinBoske

# Learning about Open XML on-line

Links to blog posts that contain useful technical information for developers.  Open XML is a new standard, but there's some good information already available if you know where to look.
Monday, March 27, 2006 11:26 AM by OpenXML Developer
New Comments to this post are disabled
 
Page view tracker