connection.php
<?php
$sernamename="localhost";
$username="root";
$password="";
$dbname="tea";
$conn=new mysqli($sernamename, $username, $password, $dbname);
if(!$conn){
die ("Connection fail" .mysqli_error());
}
?>
index.php
<?php
require_once ('connection.php');
$qry = "SELECT * from tea_record";
$res = mysqli_query($conn,$qry);
?>
<html>
<head>
<title>Table</title>
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="row">
<button id="export" class="btn btn-info">Export Excel</button>
</div>
<div class="row">
<table id="product" class="table table-bordered">
<thead>
<tr>
<th>ID</th>
<th>Date</th>
<th>Name</th>
<th>KG</th>
<th>Rate</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<?php while($row = mysqli_fetch_assoc($res)){ ?>
<tr>
<td><?php echo $row['Tea_ID']; ?></td>
<td><?php echo $row['Tea_Date']; ?></td>
<td><?php echo $row['Name']; ?></td>
<td><?php echo $row['Tea_KG']; ?></td>
<td><?php echo $row['Tea_Rate']; ?></td>
<td><?php echo $row['Tea_Total']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
<script src="jquery-3.2.0.min.js" type="text/javascript"></script>
<script src="jquery.table2excel.js" type="text/javascript"></script>
<script>
$("#export").click(function(){
$("#product").table2excel({
exclude: ".noExl",
name: "Worksheet Name",
filename: "product"
});
});
</script>
</body>
</html>
Download jquery.table2excel.js
Output