ASP 101 - Active Server Pages 101 - Web06
The Place ASP Developers Go!

Please visit our partners


Windows Technology Windows Technology
15 Seconds
4GuysFromRolla.com
ASP 101
ASP Wire
VB Forums
VB Wire
WinDrivers.com
internet.commerce internet.commerce
Partners & Affiliates














ASP 101 is an
internet.com site
ASP 101 is an internet.com site
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash



 Top ASP 101 Stories Top ASP 101 Stories
An Overview of ASP.NET
Connections, Commands, And Procedures
What is ASP?

QUICK TIP:
Server-Side vs. Client-Side Scripting
Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates


Quick Tips


Displaying Data from ASP in Excel

The following sample script creates an Excel spreadsheet with three columns.

The first two contain numeric data in the cells and the third sends a function which will calculate a sum of the numbers in the first two columns.

<%@ Language=VBScript %>
<%
Response.Buffer = True
Response.ContentType = "application/vnd.ms-excel"
%>
<table border="1">
<tr>
    <th>Column A</th>
    <th>Column B</th>
    <th>Totals Column</th>
</tr>
<tr>
    <td>4</td>
    <td>3</td>
    <td><font color="red">=sum(a2:b2)</font></td>
</tr>
<tr>
    <td>2</td>
    <td>1</td>
    <td><font color="red">=sum(a3:b3)</font></td>
</tr>
</table>

The above code will work in IE 4 and above. The client also needs to have Microsoft Excel installed. The magic is the Response.ContentType command. It tells the browser what type of content to expect... in this case an Excel Spreadsheet. The rest of what happens is all dependent on how Excel handles the HTML and luckily it does a pretty darn good job.

While this won't let you do everything Excel is capable of, it can be quite handy if, for example, you're developing an Intranet and just want to send a user some data that they then need to perform some calculations with. Just return your data as standard HTML and let Excel handle it.

And don't hesitate to try things like borders or even complex formatting... you'd be amazed at how much Excel knows about HTML.


Previous      Show All Tips      Next

If you have a tip you would like to submit, please send it to: webmaster@asp101.com.


Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers