locked
excel file is not opening when converting html table to excel RRS feed

  • Question

  • User-1634604574 posted

    i convert html table to excel file is not opening

    <table id="tb_export_customer_insert" border="1" >
    <tr class="noExl">
    <th>series</th>

    </tr>

    </table>

     $("#tb_export_customer_insert").table2excel({

    exclude: ".noExl",

    name: "Worksheet Name",

    filename: "SomeFile" //do not include extension

    });

    Sunday, May 26, 2019 6:46 PM

All replies

  • User665608656 posted

    Hi zhyanadil,

    According to your description and the code you provided, I suggest you could try to add $(function () {}) outside the jQuery method for exporting excel files .

    This means the export to excel codes will be executed when the document is loaded.

    Your table export Excel method does not trigger an action to execute, so it could not complete the action.

     
    For more details, you could refer to the following code:

    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
        <script src="../jquery-table2excel-master/dist/jquery.table2excel.min.js"></script>
        <script type="text/javascript">
           $(function () {
                $(".table2excel").table2excel({
                    exclude: ".noExl",
                    name: "Excel Document Name",
                    filename: "myFileName" + new Date().toISOString().replace(/[\-\:\.]/g, ""),
                    fileext: ".xls",
                    exclude_img: true,
                    exclude_links: true,
                    exclude_inputs: true
                });
            });
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <table class="table2excel" data-tablename="Test Table 1">
                <thead>
                    <tr class="noExl">
                        <td>This shouldn't get exported</td>
                        <td>This shouldn't get exported either</td>
                    </tr>
                    <tr>
                        <td>This Should get exported as a header</td>
                        <td>This should too</td>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>data1a with a <a href="#">link one</a> and <a href="#">link two</a>.</td>
                        <td>data1b with a
                            <img src="image_file.jpg" alt="image" />.</td>
                    </tr>
                    <tr>
                        <td>data2a with a
                            <input type="text" value="text value" />.</td>
                        <td>data2b with a
                            <input type="text" value="second text value" />.</td>
                    </tr>
                </tbody>
                <tfoot>
                    <tr>
                        <td colspan="2">This footer spans 2 cells</td>
                    </tr>
                </tfoot>
            </table>
        </form>
    </body>
    </html>

    The result of my work demo:
      

     
    Best Regards,

    YongQing.

    Monday, May 27, 2019 5:56 AM