Clean Office automation on the server... at last!

One of the very common requests we see on the ASP.NET forums is how to generate Excel or Word documents on the server? There are currently three approaches to answer this need:
  1. Output HTML or XML and just change the mimetype so that the relevant Office application opens the stream. All Office applications being quite HTML and XML friendly, chances are you'll get a pretty good result while leaving server resources reasonably untapped. But it's hacky to say the least, and what you get is not a real Office document, just some HTML or XML document open in Office. This means that you won't be able to use most of the features of the Office application (like formulas in Excel, which is quite a large drawback). If you're brave, you may generate a proper Office XML format (the keywords here are WordprocessingML and SpreadsheetML), but you may want to fall back on 2:
  2. Use a third party server library that generates well-formed Office documents. There are quite a few floating around. Google MSN Search is your friend.
  3. Install Office on the server, spawn one of the Office applications and automate it from the server. You shouldn't do this if you can avoid it, as this KB article explains. The problems (apart from licensing) are due to Office applications being built to be desktop applications, not scalable server components. Read the KB article for more details, but in a nutshell, you'll have to deal with singletons, queues, cleanup procedures, etc. and even if you do it relatively cleanly, it will perform poorly. It just does not seem worth the trouble. The Office Web Components are also client-side objects that won't give good results server-side.
Starting with Visual Studio Tools for Office (VSTO) 2005, server-side objects are provided that solve this problem. It's like option 2., only it's done by Microsoft.
 
Check out the article here:

2 Comments

  • Sounds really cool !!! I planned to have a XSLT rendering of the article of Tech Head Brothers website as Word 2003 documents, using WordML, but it is not on a high priority on my task list, at least far from the WSE integration to publish directly from Word 2003. But I will for sure have a look to this.



    Thanks.

    Laurent

  • Regarding point 2.): can you or any reader recommend some libraries?

Comments have been disabled for this content.