Alternatives to using Office COM objects within web apps

Don't use Office COM objects within web applications. Developer Justin James explains why it's a bad idea and suggests three better alternatives.

A requirement that comes up at least several times a year for me is "how do we work with Office documents in our web application?" The common thought by those who have never done it is almost invariably to host the Office COM objects and use them to manipulate the documents. After all, nothing is definitely going to be 100% compatible, a copy of Office is pretty cheap, and the techniques are well known and documented. Unfortunately, this is the worst thing possible to do.

The problem with working with Office inside a web application is simple: It is a desktop application. For one thing, the various pieces sometimes require or expect user interaction, so the object can lock up. And it requires a desktop session and for the Office application to be started, which can be a performance drag. There is a lot more to it, but Microsoft has made it very clear that using Office COM in web apps is a really bad idea. There are three better alternatives.

The first one is to re-evaluate the need for manipulating Office formats. Perhaps the use case officially says "import data from Excel" but the real use case can be met with a CSV file import, or the "must read/write Word documents" in the feature list is really a substitute for an on-screen HTML editor component. Many times when I have seen the "needs to work with Office files" requirement, deeper investigation showed it was not a true need.

The more likely alternative is to buckle down and get a library to work with Office formats. I have used Syncfusion's packages and really liked them; Syncfusion packages also handle PDFs, making the offering a fine value. I have heard good things about Aspose. There may be some less expensive or free components available.

The third alternative is to ignore the older Office formats and only work with the newer XML-based formats, which are fairly easy to manipulate (just unzip them and there's a pile of XML inside). However, by working directly with the XML, you lose the business logic that the format represents. Depending on your needs, this may be just fine.

Whichever path you take, remember: do not use the Office COM objects in a web application.


Keep your engineering skills up to date by signing up for TechRepublic's free Software Engineer newsletter, delivered each Tuesday.


Justin James is the Lead Architect for Conigent.

Editor's Picks