Enhancing the ExcelGen Class (for Creating Excel Spreadsheets), Part 3
By Scott Mitchell
In Part 2 we examined how to use the FileSystemObject to generate random file names for each spreadsheet. We also looked at how to have the out-of-date spreadsheets deleted every so often to ensure that our Web server's filesystem doesn't become overbloated with old spreadsheet files. In this part we'll (finally) look at how to stream the content of the spreadsheet to the user.
Ideally we would like to have the user visit a single ASP page that would do a couple of things:
- Generate a dynamic Excel spreadsheet based on some database query
- Stream this spreadsheet directly to the client's browser
If the user has Excel or Excel
Viewer installed he will see the spreadsheet in her browser. We can accomplish something
very close to this. The StreamWorksheet() method accomplishes this, sort of.
The method does two things: first it saves the spreadsheet to the Web server's filesystem using
the random file name technique discussed in Part 2 of this
article; next, it uses a Response.Redirect to send the user to this newly created
Excel spreadsheet. This has the effect of seemingly streaming the Excel spreadsheet to the
user's browser. The code for the StreamWorksheet() method follows below:
|
Pretty simple, eh? At the end of this article you can grab the complete code for the
ExcelGen class. This code should be placed in an include file for easy access.
The code below demonstrates a quick example of generating a dynamic Excel spreadsheet based
on a database query and streaming the spreadsheet to the visitor. (Note that it assumes that
the ExcelGen class has been placed in an include file named /include/ExcelGen.class.asp.)
|
Well, that wraps up this article! Be sure to check out the related articles and support code links below. Happy Programming!
Attachments:
ExcelGen class in text formatExcelGen class in text format




