[thelist] Get excel files from html

Andreas Wahlin Andreas.Wahlin at ufl.gu.se
Wed Dec 8 04:07:33 CST 2004

I have a "web application" with quite some tabular data, that my client
want to be able to get as excel files as well.
My solution to this is to first build up a session variable (using ASP
here) with the entire table of data, then redirect to another page, and
print out that session variable and have the content type as
application/vnd.ms-excel, then go back in history using javascript to
end up from the beginning, this creates the effect of a normal popup
asking to save the excel file.
I can't just ask them to take save as something, since the first page
contains navigation, header and footer as well as the tabular data, and
I might wish to include some extra data in the excel file as well. 

--File 1--
//Session("report") = build the data using sql queries and such

--file 2--
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;
<table border="1">

<script language="javascript" type="text/javascript">

Now apart from breaking rather embarrasing for non-javascript users, is
this a pretty good approach? Anyone with suggestions of improvement or
something? I'm looking at a possible overhaul of some functions and this
seems a bit clumsy, but it does work (except for non-javascripters, will
have to think about something for that)
A possible alternative might perhaps be to have a print css style in
some way ... But I'm not entirely sure how. I'm also thinking about
making it possible to save the data as a comma separated file, for easy
import into other programs.


More information about the thelist mailing list