jQuery

Download excel file using jQuery with example

Spread the love

Download excel file using jQuery is very simple. You follow given bellow steps –

Step : 1Create HTML button to Download Excel file

Download excel file using jQuery
<!DOCTYPE>  
<html>  
<head>  
<title> Download Excel </title>  
</head>  
<body>  
<p> 
<input type="button" id="ExportButton" value="Click here to Download Excel" />
<p>
</body>  
</html>

Step : 2 – Add jquery.min.js and table2excel.js library in header section.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://rawgit.com/unconditional/jquery-table2excel/master/src/jquery.table2excel.js"></script>
<script type="text/javascript">
	$(function () {
          /* button id 'ExportButton' */
		$("#ExportButton").click(function () { 
           /* HTML table id 'tblListId' */
			$("#tblListId").table2excel({ 
				filename: "Data-Report.xls"
			});
		});
	});
</script>

Step : 3 – Add HTML Table in body section.

<table id="tblListId" cellspacing="0" width="100%">	
	<tr>                 
		<th>Sr. No.</th>
		<th>First Name</th>
		<th>Last Name</th>
		<th>Mobile No.</th>				                  
		<th>Address</th>					
	</tr>               
	<tr>                     
		<td>1</td>
		<td>Aman</td>				
		<td>Singh</td>			
		<td>1111111111</td>
		<td>H.No.-E/125</td>								  
	</tr> 
	<tr>                     
		<td>2</td>
		<td>Ashok</td>				
		<td>Singh</td>				
		<td>2222222222</td>
		<td>H.No.-E/130</td>								  
	</tr> 
</table>

Download excel file using jQuery with example

Read more…

Leave a Reply

Your email address will not be published. Required fields are marked *