Link to home
Start Free TrialLog in
Avatar of etalexit
etalexit

asked on

Export HTML Table to Excel

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>
Avatar of koolie
koolie

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...
Are you familiar with ASP... it's a much better, efficient way. I can post an example if you need me to.

Dave
Avatar of etalexit

ASKER

Dave,
Yes, I am familiar with ASP. In fact, the application is done in ASP. Please post the code. Thanks
etalexit
ASKER CERTIFIED SOLUTION
Avatar of davecestria
davecestria

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial