Sunday, May 24, 2009

Streaming Office 2007 Documents Requires New Content Types

Streaming out content that opens in Microsoft Office applications is a fairly common feature in web applications. This involves setting a Content-Type header to the appropriate MIME type. The new XML/ZIP-based file formats in Office 2007 bring with them new MIME types. There is a complete list of those here.

Another common technique is to stream XML or HTML and basically lie about the content type to get data presented in Word or (especially) Excel. After all, generating true native Office-formatted files on a web server generally involves third-party components, and depending on your platform and specific needs, those can get expensive. But Excel 2007 creates a gotcha for this use case called "extension hardening", where Excel actually verifies that a file format matches the extension it claims to be before opening it, and if not, gives an annoying, scary prompt to the user.

I first experienced this last week, with Excel 2007 trying to open an Excel 2007 document from a web site which set the content type to "application/" -- i.e. an Excel 2007 document claiming to be an Excel 2003 document. This is bothersome, but at least it's easy to work around by changing the content type to "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet". (That's a mouthful.) It doesn't do much for the HTML case, however, as described in the above link. No good workaround...

No comments: