Back to Papers and Articles
Building an Excel Spreadsheet using ASP
Copyright 1999 Paragon Corporation   ( July 27, 1999)
The easiest way to build an Excel spreadsheet in HTML is to use the application/vnd.ms-excel content type specification. Specifying the content type of an HTML document as application/vnd.ms-excel will instruct the web browser to load the page in Excel. Note that this only works for Excel 97 and above because previous versions of Office do not register this content type.

This approach supports simple functionalities in Excel such as formulas, but does not support the more advanced features like creating multiple worksheets.

Below is a sample ASP page that will generate an Excel spreadsheet:
<%@ LANGUAGE="VBSCRIPT" %>
<%
'Set content type to Excel so page will open in Excel
	Response.ContentType = "application/vnd.ms-excel"
%>

<TABLE cellspacing=1 cellpadding=1>
	<TR>
		<TD align=center colspan=4><FONT size=4 color=blue>Price Quote</FONT></TD>
	</TR>
	<TR>
		<TD><B>Product</B></TD>
		<TD><B>Price</B></TD>
		<TD><B>Quantity</B></TD>
		<TD><B>Total</B></TD>
	</TR>
	<TR>
		<TD>Widget A</TD>
		<TD>36</TD>
		<TD>2</TD>
		<TD>=B3*C3</TD>
	</TR>
	<TR>
		<TD>Widget B</TD>
		<TD>45</TD>
		<TD>3</TD>
		<TD>=B4*C4</TD>
	</TR>
	<TR>
		<TD></TD>
		<TD></TD>
		<TD><B>Total</B></TD>
		<TD>=Sum(D3:D4)</TD>
	</TR>


 </TABLE>

Three things to remember:

  • Do not include the <HTML></HTML> tags.
  • Use the standard HTML table construct to form the rows and cells.  Excel cells are expressed as table cells and Excel rows are expressed as table rows.
  • When specifying an Excel formula, do so as you would in Excel, e.g., =Sum(D3:D4).



Back to Papers and Articles