locked
Export HTML to excel RRS feed

  • Question

  • User1858009984 posted

    How to export html table data to excel / csv using jquery.

    Monday, December 9, 2019 9:11 AM

All replies

  • User665608656 posted

    Hi SaiRam,

    To implement this function, you can download Table2excel jquery plugin ,here is the link you can refer and download it :

    Exporting HTML Table To Excel Using jQuery

    You can also refer to the following code:

    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script src="../Scripts/jquery-3.0.0.min.js"></script>
        <script src="../Table2excel/jquery.table2excel.js"></script>
        <script type="text/javascript">
            $(function () {
                $("#btnExport").click(function () {
                    $("#tblData").table2excel({
                        name: "Table2Excel",
                        filename: "myFileName",
                        fileext: ".xls"
                    });
                })
            })
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <table id="tblData">
                    <tr>
                        <td>ID</td>
                        <td>Name</td>
                        <td>Age</td>
                    </tr>
                    <tr>
                        <td>1</td>
                        <td>AAA</td>
                        <td>21</td>
                    </tr>
                    <tr>
                        <td>2</td>
                        <td>BBB</td>
                        <td>22</td>
                    </tr>
                    <tr>
                        <td>3</td>
                        <td>CCC</td>
                        <td>21</td>
                    </tr>
                    <tr>
                        <td>4</td>
                        <td>DDD</td>
                        <td>21</td>
                    </tr>
                </table>
                <button id="btnExport">EXPORT </button>
            </div>
        </form>
    </body>
    </html>
    

    Here is the result :

    Best Regards,

    YongQing.

    Monday, December 9, 2019 10:07 AM