50,126 Members
1 added today
271,899 Resources
17 added today

All Devdex   All Gurus  

Convert your HTML Tables to Excel
Author: Bruce Johnson
Rating: Rate this Resource
Visits: 5524

Discuss in Newsgroups

A common request from users is to be able to take the HTML-based report that is currently sitting in their browser and move it into Excel. While it's too late to help after the fact, with a little preparation, you can push that HTML table into Excel for them.
To accomplish this feat, we take advantage of the ContentType property in the Response object. And the fact that most people have Excel on their computer. By setting the ContentType to application/vnd.ms-excel, we are instructing the browser to send the HTML output directly to Excel for processing. This nifty trick works because Excel recognizes and can load HTML output.
<%@ 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>
When this page is hit through a browser, the data will be loaded into Excel executing within the browser. Again, we assume that the user has Excel installed on their system. Also, some security settings on the browser might cause the user to be prompted to open or save the data. Only if the data is opened will Excel be loaded
You will also notice that we are including some formatting information in the cells, as well as specifying formulae. All of this information is picked up and interpreted by Excel automatically.

Visit my guru profile

Visitor Comments

Be the first to rate this code sample!

 

Rate this Code Sample






	
	
	



ASP.NET Shopping Cart
Unlimited items/categories
Unlimited options/choices
Ecommerce toolkit for .NET!

ASP ArticlesThis category has been added to your weekly newsletter
ASP Web Sites
ADSI & WSH BooksThis category has been added to your weekly newsletter
FREE ComponentsThis category has been added to your weekly newsletter
ASP EventsThis category has been added to your weekly newsletter
ASP HeadlinesThis category has been added to your weekly newsletter

CSharp ArticlesThis category has been added to your weekly newsletter
C# Web SitesThis category has been added to your weekly newsletter

SQL ArticlesThis category has been added to your weekly newsletter
SQL Events
SQL HeadlinesThis category has been added to your weekly newsletter
SQL Jobs

Jobs in CaliforniaThis category has been added to your weekly newsletter

XML ArticlesThis category has been added to your weekly newsletter
XML BooksThis category has been added to your weekly newsletter
XML Web Sites
XML Tutorials

free asp host

"Alex Homer"This search has been added to your weekly newsletter

Edit My Favorites Edit Profile & Favorites

 




Developersdex Home | ASP | C# | SQL | VB | XML | Gurus
Add Your Link | Add Your Code | FAQ | Advertise | Link To Us | Contact Us |
Copyright © 2010 Developersdex™. All rights reserved.