views:

314

answers:

2

We have a requirement that our web app will do a mail merge and generate some Word documents. Of course this is very easy to do using Word automation but is not recommended by Microsoft http://support.microsoft.com/kb/257757.

"Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment."

What do people generally do in this situation? Just accept that Word will occasionally hang or go for some third party solution.

+3  A: 

Basically you have three choices:

  1. Run it on the server and accept those consequences. I know from experience that things do go wrong, but depending on how real-time and high priority the tasks you're doing are, it may be something you can live with. Basically if you have to do this, try to do as little Word integration as possible; if it's just a mail merge then you will probably get away without any problems 99.9% of the time.
  2. Use a third-party solution. But from experience, except for very simple documents, these never do the job quite properly. For example if you're talking about something that will generate PDFs from Word documents on the server, it will never look the same as it does in Word.
  3. Instead of directly invoking Word, use the .NET Open XML libraries to manipulate the documents yourself. I've even written stuff in VB6 that manipulates Word/Excel 2007 documents, since they're all in very-well documented XML formats. You have to use the 2007 formats, but it's fast and good. But something like a mail merge you'd have to do manually I think, so it may not be suitable. This solution is generally better for manipulating documents rather than replacing Word API functions.

From personal experience I've done the first and it worked well enough for our customer to accept, I messed around with the second and was never satisfied, and I've done the third with great success (but a fair bit of work).

In short, people do all sorts depending on cost (time etc) vs. reliability: I'd suggest option 1 or 2 for a fast (but less reliable) solution, or 3 for a more reliable (but costly) one.

Gavin Schultz-Ohkubo
A: 

I built a Powerpoint application using automation. Basically it was a Slide Library Website that opened multiple files and moved slides into a template.

The first issue I encountered was security, I ended up setting the application to run as administrator, which isn't recommended and most places would probably frown apon that action. You will need to have the flexibility to customize the security settings.

I did experience a few app pool crashes that we're never tracked down, and I believe I also had to have a user logged into the Remote Desktop, but disconnected, at all times.

Bottom line is you can get automation to work, but its hacky. If you have the flexibility and automation is your best bet then go for it. Otherwise I have two thoughts.

  1. Explore the use of Open XML and the Open XML SDK
  2. Look into running a WCF Sevice on a trusted user account. then have your webpage call out or queue a job for processing the request.
bendewey