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,locat ion=no,dir ectories=y es,menubar =yes,";
sOption+="scrollbars=yes,w idth=750,h eight=600, left=100,t op=25";
var sWinHTML = document.getElementById('c ontentstar t').innerH TML;
var winprint=window.open("","" ,sOption);
winprint.document.open();
winprint.document.write('< html><head >')
winprint.document.write('< meta http-equiv="Content-Type" content="application/vnd.m s-excel">' )
winprint.document.write('< meta http-equiv="Content-dispos ition": attachment; filename="file.xls">')
winprint.document.write('< /head><bod y>')
winprint.document.write(sW inHTML);
winprint.document.write('< /body></ht ml>');
winprint.document.close();
winprint.focus();
}
</script>
</head>
<body>
<a href="javascript:ExporttoE xcel();" >Export to Excel</a>
<div id="'contentstart'">
<table>
<tr><td>testing</td></tr>
</table>
</div>
</body>
</html>
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,locat
sOption+="scrollbars=yes,w
var sWinHTML = document.getElementById('c
var winprint=window.open("",""
winprint.document.open();
winprint.document.write('<
winprint.document.write('<
winprint.document.write('<
winprint.document.write('<
winprint.document.write(sW
winprint.document.write('<
winprint.document.close();
winprint.focus();
}
</script>
</head>
<body>
<a href="javascript:ExporttoE
<div id="'contentstart'">
<table>
<tr><td>testing</td></tr>
</table>
</div>
</body>
</html>
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
Dave
ASKER
Dave,
Yes, I am familiar with ASP. In fact, the application is done in ASP. Please post the code. Thanks
etalexit
Yes, I am familiar with ASP. In fact, the application is done in ASP. Please post the code. Thanks
etalexit
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.