[thelist] Export page to excel

Ray Hill ray.hill at informative.com
Mon Jun 17 14:49:01 CDT 2002


> How can I put a button in the page so when the user clicks
> is, the script will export all the content in the tables
> to an Excel file? (Can this be done?)

It's actually easier than you might think.  If you open up an Excel
spreadsheet, you'll see a Web Page option under the File > Save As menu.
The nifty thing is that the HTML file it produces will retain all of its
original formatting if you open it using Excel instead of a browser.

If you look at the HTML that's produced, you'll see it's just a bunch of
Microsoft-specific XML attached to a regular HTML table.  So all you need to
do is have your script produce the same HTML table you normally do, but
surround it with the necessary MS-XML, and send the HTTP headers to tell the
browser it's an Excel file you're opening and not an HTML file, and the
browser will do the rest.

This article goes more in depth on how to accomplish it, step by step.  It
uses PHP as the example scripting language, but it should be pretty easy to
figure out how to do the same in ASP, JSP or whatever your language of
choice is:
http://www.evolt.org/article/Using_MySQL_and_PHP_to_Present_Excel_Spreadshee
ts/20/26896/index.html

--ray



More information about the thelist mailing list