I can't vouch for how portable this solution is, since I believe that it requires certain versions of IE and Excel (and Windows, of course) However, if you want to stay entirely within ASP in order to meet your authorization requirements, try this out. If you know that your users will be using at least IE 5.01 and that they have at least Excel 2000 on their machines, then you can change $Response->{Content-Type} to 'application/vnd.ms-excel' as suggested above and simply $Response->Write the content as normal HTML tables.
IE and Excel should cooperate via OLE/ActiveX and display the content as an Excel spreadsheet within IE itself, and if the users want to save the file out, they can just select File->Save As from the IE menu, and it will default to saving as an Excel .xls file. As I mentioned, I believe that this requires minimum versions of IE and Excel, although I haven't personally tested it on other versions.
Also, for formatting purposes, you can use CSS within the various table tags via the "style" attribute. Unfortunately, using a separate CSS stylesheet (whether linked or elsewhere in the HTML) and "class" attributes doesn't seem to be reliable.
Granted, this is a narrow subset of user requirements, and you're essentially limited to non-dynamic Excel content, i.e. pure data, no formulas or other such things. However, we use a solution like this at my company to provide web-based reports to our marketing department. This allows us to use the same basic presentation code for both the HTML and Excel versions of the reports. The only modifications required to make the reports Excel-friendly are to strip out any sort of UI widgets or other unnecessary sections and then change the Content-Type.
Now, if we could just wean the marketing department off of Excel, that would be a MUCH better solution. But, alas ...
-jehuni
| [reply] |