Answered by:
how to export html table into excel file then download the excel

Question
-
User-1634604574 posted
i want to export html table data into the excel file then download the excel by button click
Wednesday, January 30, 2019 12:55 PM
Answers
-
User839733648 posted
Hi zhyanadil.it@gmail.com,
According to your description, I suggest that you could use jQuery table2excel Plugin to achieve your requirement.
I've made a demo on my side and you may refer to.
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdn.rawgit.com/rainabba/jquery-table2excel/1.1.0/dist/jquery.table2excel.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" /> </head> <body> <table class="table table-bordered table-striped table-hover" id="demo-export"> <thead> <tr class="danger"> <th>Hosting Packgae</th> <th>Features</th> <th>Price</th> </tr> </thead> <tbody> <tr class="info"> <td>Bluehost</td> <td>One FREE Domain</td> <td>$1.95</td> </tr> <tr class="active"> <td>HostGator</td> <td>One FREE Domain</td> <td>$1.95</td> </tr> <tr class="info"> <td>iPage</td> <td>Unlimited Space and Bandwidth</td> <td>$5.95</td> </tr> <tr class="active"> <td>DreamHost</td> <td>A free domain</td> <td>$7.25</td> </tr> </tbody> </table> <script> $(function () { $("#btnExport").click(function () { $("#demo-export").table2excel({ filename: "tab2exl" }); }) }); </script> <button id="btnExport" class="btn btn-primary btn-lg">Export table data to excel</button> </body> </html>
result:
For more about the plugin, you could refer to: https://www.npmjs.com/package/jquery-table2excel
Best Regards,
Jenifer
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, January 31, 2019 2:37 AM
All replies
-
User839733648 posted
Hi zhyanadil.it@gmail.com,
According to your description, I suggest that you could use jQuery table2excel Plugin to achieve your requirement.
I've made a demo on my side and you may refer to.
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdn.rawgit.com/rainabba/jquery-table2excel/1.1.0/dist/jquery.table2excel.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" /> </head> <body> <table class="table table-bordered table-striped table-hover" id="demo-export"> <thead> <tr class="danger"> <th>Hosting Packgae</th> <th>Features</th> <th>Price</th> </tr> </thead> <tbody> <tr class="info"> <td>Bluehost</td> <td>One FREE Domain</td> <td>$1.95</td> </tr> <tr class="active"> <td>HostGator</td> <td>One FREE Domain</td> <td>$1.95</td> </tr> <tr class="info"> <td>iPage</td> <td>Unlimited Space and Bandwidth</td> <td>$5.95</td> </tr> <tr class="active"> <td>DreamHost</td> <td>A free domain</td> <td>$7.25</td> </tr> </tbody> </table> <script> $(function () { $("#btnExport").click(function () { $("#demo-export").table2excel({ filename: "tab2exl" }); }) }); </script> <button id="btnExport" class="btn btn-primary btn-lg">Export table data to excel</button> </body> </html>
result:
For more about the plugin, you could refer to: https://www.npmjs.com/package/jquery-table2excel
Best Regards,
Jenifer
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, January 31, 2019 2:37 AM -
User-2054057000 posted
There are many ways to Export HTML table data into excel file. You can use set Response.ContentType = “application/vnd.ms-excel” and it will do your work.
Reference - How to Export Database Records into Excel File in ASP.NET MVC
Friday, February 1, 2019 5:54 PM