<html>
<title>Export Table Data To Excel</title>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<style type="text/css">
body
{
font-size: 12pt;
font-family: Calibri;
padding : 10px;
}
table
{
border: 1px solid black;
}
th
{
border: 1px solid black;
padding: 5px;
background-color:grey;
color: white;
}
td
{
border: 1px solid black;
padding: 5px;
}
input
{
font-size: 12pt;
font-family: Calibri;
}
</style>
<script type="text/javascript">
$(function(){
$("#btnExport").click(function(e) {
window.open('data:application/vnd.ms-excel,' + $('#dvData').html());
e.preventDefault();
});
});
</script>
</head>
<body>
<br/>
<div id="dvData">
<table>
<tr>
<th>Column One </th>
<th>Column Two</th>
<th>Column Three</th>
</tr>
<tr>
<td>row1 Col1</td>
<td>row1 Col2</td>
<td>row1 Col3</td>
</tr>
<tr>
<td>row2 Col1</td>
<td>row2 Col2</td>
<td>row2 Col3</td>
</tr>
<tr>
<td>row3 Col1</td>
<td>row3 Col2</td>
<td>row3 Col3</td>
</tr>
</table>
</div>
<br/>
<input type="button" id="btnExport" value=" Export Table data into Excel " />
</body>
</html>
Donot forget to give your comments /suggestions and refer to your friends.
it is not working with IE browser.. Please I want to work it out using Internet Explorer 8
ReplyDeletethx...
ReplyDeleteI think it's great that everyone keeps passing around the same HTML and jQuery tutorial, however if it does not work in IE 8 or below then it's not much of a solution.
ReplyDelete