First of all add reference of jquery before apply this code.this code is usefull for export html table data in excel sheet.
write this in .aspx or html page
<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 " />
Add below code in script tag
write this in .aspx or html page
<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 " />
$("#btnExport").click(function(e) {
window.open('data:application/vnd.ms-excel,' +encodeURIComponent($('#dvData').html()));
e.preventDefault();
});
window.open('data:application/vnd.ms-excel,' +encodeURIComponent($('#dvData').html()));
e.preventDefault();
});
when i m using this code in .aspx page. Every time empty popup window is opened.
ReplyDeleteI m using IE8
Please help..
IE not support so many scripts....
ReplyDeleteuse other browser like chrome,Firefox,safari,opera..etc
I am not able to change the excel sheet file name here..can you help me with that?
ReplyDelete