[thelist] Get excel files from html

Jacques Capesius Jacques.Capesius at compellent.com
Wed Dec 8 09:20:29 CST 2004


Here's the approach I've used to produce excel output from the web. As
luck would have it, you can create an excel document as XML, save it
with an .xls extension, and the user can view it in excel as if it were
a native spread sheet. 

The XML header tags being created, you populate the spreadsheet using
<tr> and <td> tags, just as if you were laying out the data in HTML.
Then, after the file is created, I redirect them to it and bang-zoom. 

One note, in the slim chance you didn't know this already, when getting
the data, it's better to write it directly to the file, rather than
concatenating some string and writing it in one big chunk. Your page
will run remarkably faster.

Anyway, this function would of course, sit behind a "submit" button on
your page.

HTH

-jacques :)

************************************************************************
****

Set fso = createobject("scripting.filesystemobject")
Set act = fso.CreateTextFile("myfile.xsl",true)
createSpreadsheet(act)

Function createSpreadsheet (act)
act.WriteLine "<html
xmlns:x=""urn:schemas-microsoft-com:office:excel"">" &_
"<head>" & _
	        "<!--[if gte mso 9]><xml>" & _
	        "<x:ExcelWorkbook>" & _
	        "<x:ExcelWorksheets>" & _
		  "<x:ExcelWorksheet>" & _
		  "<x:Name>My Spreadsheet</x:Name>" & _
		  "<x:WorksheetOptions>" & _
		  "<x:Print>" & _
		  "<x:ValidPrinterInfo/>" & _
		  "</x:Print>" & _
		  "</x:WorksheetOptions>" & _
		  "</x:ExcelWorksheet>" & _
		  "</x:ExcelWorksheets>" & _
		  "</x:ExcelWorkbook>"  & _
		  "</xml>" & _
		  "<![endif]--> "  & _
		  "</head>"  & _
		  "<body>"  & _
		  "<table>"  & _
		  "</tr>" & _
		  "<tr bgcolor=""lightgrey"">"  & _
		  "<td><b>Survey: </b></td>"  & _
		  "<td colspan=""5""><b>Your Title Here</b></td>" & _
		  "</tr>" & _
		  "<tr>" & _
		  "<td>col1 data</td><td>col2 data</td>" & _
	act.WriteLine "</tr>"
End Function



More information about the thelist mailing list