Overview:
The latest versions of Excel (2007, 2010) differ from Excel 2003 in their support of streaming a HTML document containing Excel-specific markup. Although core markup features still work, some of the previously supported functionality has now been removed.
This directly affects the ability in code to stream a table to Excel and then use MSO tags to format the layout.
In the more recent versions of Excel (2007, 2010) Microsoft has reworked their support for streaming Excel information on the Web and has added refined control over the ability to create an Excel document with a series of worksheets. But sadly with each new version of Excel they are removing much of their support for streaming HTML information to the browser that worked so well for Web developers in the past.
Instead, when using the newer Microsoft syntax, a temporary file must be saved to the server before it can be sent to the browser. Further, using the new Microsoft method one cannot simply send an HTML table, but must re-query the database, and then re-generate the entire document.
In this article I cover the tried-and-true method of streaming Excel directly to a client’s browser and explain what Excel markup still works, and what doesn’t. I will cover the newer method of doing so in a future article.
If you are interested in further background on this topic or useful links please see Part 1 of this article at: Generating Excel documents through HTML, XML, and CSS – Part 1
How to Stream the Excel Document Directly:
I recently had the requirement to output an ASP.NET GridView report in Excel, but additionally with the following Excel formatting requirements:
- Print in Landscape layout
- Add a detailed header to each printed page
- Add a detailed footer to each printed page
- Show Excel Rows and Columns on each printed page
- Freeze the header table row when paging through Excel
- Show the frozen header table row on each printed page
The requirements that cause the printing process to fail with Excel 2007 or Excel 2010 are:
- Show Excel Rows and Columns on each printed page
- Freeze the header table row when paging through Excel
- Show the frozen header table row on each printed page