The code below gives a brief example on how to create an .xls file from an asp webpage. I use this to often to export my customers data(database) to an offline version wich they can use for archiving/reporting.
To to so you have to change the contenttype of the asp file to "application/vnd.ms-excel". This code has to be at the top of you page.
From then on you can use the response.write() function to write data to the .xls file. The data must be structured in table rows("<TR>") .
You can define the fields in the .xls with TH and TD.
code snippet:
ASP:
<% Response.ContentType = "application/vnd.ms-excel" strfilename = "Filename_" & Day(Date) & Month(Date) & Year(Date) & ".xls" Response.AddHeader "Content-Disposition","filename=" & strfilename response.expires = -1 %> strContent =”fill this variable(strContent) the same way as an html table” <able border="1" cellpadding="4" cellspacing="1" width="100%" %> <% response.write strContent %> </table%>
| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| « Nov | ||||||
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | ||||
RSS feed for comments on this post · TrackBack URI
Leave a reply