How can I read MS Office files in a server without installing MS Office and without using the Interop Library?

StackOverflow https://stackoverflow.com/questions/153079

Question

The interop library is slow and needs MS Office installed. Many times you don't want to install MS Office on servers.

I'd like to use Apache POI, but I'm on .NET.

I need only to extract the text portion of the files, not creating nor "storing information" in Office files.

I need to tell you that I've got a very large document library, and I can't convert it to newer XML files.

I don't want to write a parser for the binaries files. A library like Apache POI does this for us. Unfortunately, it is only for the Java platform. Maybe I should consider writing this application in Java.

I am still not finding an open source alternative to POI in .NET, I think I'll write my own application in Java.

Was it helpful?

Solution

For all MS Office versions:

For the new Office (2007):

For the old Office (before 2007):

OTHER TIPS

Check out the Aspose components. They are designed to mimic the Interop functionality without requiring a full Office install on a server.

As the new docx formats are inherently XML based files, you can create and manipulate them programmatically with standard XML DOM techniques, once you know the structure.

The files are basically zip archives with an alternate file extension. Use the System.IO.Packaging namespace to get access to the internal elements of the file, then open them into a XmlDocument to perform the manipulation.

There are examples available for doing this, and the Office Open XML project on SourceForge may be worth looking at for inspiration.

As for the older binary formats, these were proprietary to MS, and the only way you're likely to get at the content from within is through the Office object model (requires an Office install), or a third party file converter/parser.

Unfortunately there's nothing first party and native to the .NET platform to work with these files.

What do you need to do with those file? If you just want to stream them to the user, then the basic file streams are fine. If you want to create new files (perhaps based on a template) to send to the user that the user can open in Office, there are a variety or work-arounds.

If you're actually keeping data in Office documents for use by your web site, you're doing it wrong. Office documents, even Excel spreadsheets and access databases, are not really an appropriate choice for use with an interactive web site.

If the document is in word 2007 format, you can use the system.io.packaging library to interact with it programatically.

RWendi

In Java world, there is also JExcelApi. It is very clearly written, from what I was able to see, much cleaner then POI. So maybe even a port of that code to .NET is not out of the question, depending of course you have enough of time on your hands.

OpenOffice.

You can program against it and have it do a lot for you, without spending the money on a license for the server, or have the vulnerability associated with it on your server.

Microsoft Excel workbooks can be read using an ODBC driver (or is it an OLE DB driver? can't remember) that makes the workbook look like a database table. But I don't know whether that driver is available without the Office Suite itself.

You can use OpenOffice. It has a command-line conversion tool:

Conversion Howto

In short, you define a macro in OpenOffice and you call that macro with a command-line argument to OpenOffice. In that argument the name of the local file (the Office file) is encoded.

It's not a great sollution, but it should be workable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top