Office Open XML needs wrapper classes

I’ve been writing a hands-on style article on using the Packaging API and Office Open XML. It all works smoothly, but its glaringly apparent that Microsoft needs to provide some wrapper classes for Open XML documents to make the API more usable. You can download some code snippets, which is a start, but these only scratch the surface. After all, Office developers are used to the COM automation API which makes it relatively easy to create and manipulate documents. By contrast, to get anywhere with Open XML you have to understand the raw XML. It is still miles better than working with RTF, or with the binary Office formats, but more difficult than it should be.

By way of illustration, look no further than the official code snippet for XLInsertStringIntoCell, which does what its name suggests: writes a string into the specified cell of an Excel spreadsheet. It is over 200 lines of code and comment (in fairness, more comment than code). That would be just 2 or 3 lines in VBA. Of course, once you have the wrapper function, it is just as easy. Unfortuntely there is a lot to wrap, but it is not necessary to be comprehensive. A simplified DOM that enabled the creation of basic formatted documents and spreadsheets without having to write thousands of lines of code would meet most needs.

I realise that you can write a “Hello world” document fairly easily; I’ve done it myself. But “Hello World” is not particularly useful. After all, you could output plain text or CSV, and Word and Excel will open them happily enough. The point of Open XML is to enable documents that have a little more to them: headers and footers, specified margins, rich formatting with fonts and paragraph styles, tables and graphics. Doing all that in Open XML is not trivial.

I am not the first to think along these lines. For example, here’s some code posted to CodePlex for working with Excel. Good stuff, but personally I’d like to see some official libraries, or even a well-run (WIX-style) officially endorsed open source project for this. It’s badly needed.


Technorati tags: , ,