Tuesday, November 4, 2014

How would you work with Office files

MS Word/Excel document in a web application? Look - what Microsoft offers besides office tools.

Problem Statement:

Clients might be interested in managing their data in the form of a Word/Excel/Powerpoint files in their application. You may have options to deal with them in the transportation or application design level. The best bet would be a SharePoint based App on the frontend. But, what would you do if you want to work with these files. For example, edit a word file and add some text into it or validate some input submitted by the user or add a custom macro into a file that will be used by user to do some specific operations. These are some of the examples you could have to do on a Microsoft office document. In such requirements, you will need to open up the file programmatically and get your hands dirty. Thankfully, Microsoft offers libraries to do that and more importantly with recent versions of office releases it has become easier and developer friendly.

File formats change:

Prior to Office 2007, office files used to have extension as .doc/.xls/.ppt etc. In 2007 and onwards, it has changed to .docx/.xlsx/.pptx etc. This is a whole new implementation of office suite by Microsoft. All the office documents are represented and defined by a set of interlinked XML files and flat files such as images. Its not a single binary file anymore. The file format is called Open Office XML(OOXML), also called as OpenXML. With this implementation, Microsoft's office files comply to a standard XML schema and can be read or interpreted by other applications by a different company.

We have two options:

1. Office Web Components (OWC) -  For office documents from 97-2003
2. OpenOfficeXML(OOXML) - For office documents 2007 or later

OWC components require office suite be installed on your server and it acts as just a wrapper between your code and the office installation.
OOXML is a complete support for working with documents with ease considering the fact that you have a specific schema in which the documents are built.
Additional benefits include -
 - OOXML library is a strongly typed set of classes wherein, you will be able to retrieve and insert objects and not just working with XML documents(nodes and attributes).
 - You could convert a 03 file into a 07 file (and vise-a-versa) with OOXML library.

OOXml SDK can be downloaded here.
 

No comments:

Post a Comment