[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Export HTML Table to Excel

Posted on 2006-07-18
6
Medium Priority
?
16,668 Views
Last Modified: 2012-05-05
Dear Experts,

How to export a html table within a dive tag to excel??

Below is what I have so far but it is not working properly.
I expect by clicking on "export to excel" hyperlink, a separate browser window will open up the excel application with the information in the table.

Thanks for any help in advance

etalexit

---------------------------------------------------------------------------------------------------------------------
<html>
<head>
<script language="JavaScript">
function ExporttoExcel()
{
   var sOption="toolbar=yes,location=no,directories=yes,menubar=yes,";
       sOption+="scrollbars=yes,width=750,height=600,left=100,top=25";

   var sWinHTML = document.getElementById('contentstart').innerHTML;

   var winprint=window.open("","",sOption);
       winprint.document.open();
       winprint.document.write('<html><head>')

       winprint.document.write('<meta http-equiv="Content-Type" content="application/vnd.ms-excel">')
         winprint.document.write('<meta http-equiv="Content-disposition": attachment; filename="file.xls">')
         winprint.document.write('</head><body>')

       winprint.document.write(sWinHTML);
       winprint.document.write('</body></html>');
       winprint.document.close();
       winprint.focus();
}

</script>
</head>

<body>
<a href="javascript:ExporttoExcel();" >Export to Excel</a>

<div id="'contentstart'">
<table>
<tr><td>testing</td></tr>
</table>
</div>
</body>
</html>
0
Comment
Question by:etalexit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 5

Expert Comment

by:koolie
ID: 17135288
This probably isnt what you are looking for, but the easiest way to do this is with Internet Explorer ( and a computer that has Excel installed on it ).  You can right-click on a page and export to excel and insert a html table into an excel page...
0
 
LVL 6

Expert Comment

by:davecestria
ID: 17137765
Are you familiar with ASP... it's a much better, efficient way. I can post an example if you need me to.

Dave
0
 

Author Comment

by:etalexit
ID: 17137830
Dave,
Yes, I am familiar with ASP. In fact, the application is done in ASP. Please post the code. Thanks
etalexit
0
 
LVL 6

Accepted Solution

by:
davecestria earned 2000 total points
ID: 17137923
The following code allows you to display your table as normal in IE, then if the page is loaded with ?action=export as the querystring it will prompt you to save or open the exprted excel document.

If you only wish to hide parts of your page just use:

<%if Request.QueryString("action") <> "export" then%>
Content Which You Do Not Want Seen When You Export
<%end if%>

----CODE:

<%
if Request.QueryString("action") = "export" then
Response.Buffer = True
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment;filename=Export.xls"
else
Response.Write "<a href=""?action=export"">Export</a><br><br>"
end if
%>
<table>
<tr><td>Your HTML Table Here</td></tr>
</table>




Hope This Helps,


Dave
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question