首页 > 解决方案 > 使用 Jquery 插件将 HTML 表格和表单数据导出到 Excel

问题描述

我有一个 HTML 页面,它有一个 from 和两个表,数据是从 MySQL 中获取的。我想使用 Jquery Plugin 将表单和表格数据导出到 Excel。

我使用了以下 Jquery 插件。但是,它只导出表格数据,省略了表格数据。

https://www.jqueryscript.net/table/Export-Html-Table-To-Excel-Spreadsheet-using-jQuery-table2excel.html

<form id="ex1>
  <label>Roll No 2</label>
  <input type="text value="Anil">
  <label>Name</label>
  <input type="text value="Anil">
  <label>Dept</label>
  <input type="text value="CSE">
</form>

<table id="ex2>
  <tr>
    <th>Subject</th>
    <th>Mark</th>
  </tr>

  <tr>
    <td>English</td>
    <td>69</td>
  </tr>

  <tr>
    <td>Maths</td>
    <td>50</td>
  </tr>

  <tr>
    <td>Computer</td>
    <td>90</td>
  </tr>
</table>

出口

<script>
  $("#export").click(function(){
     $("body").table2excel({
        exclude: ".noExl",
        name: "Worksheet Name",
        filename: "Employee Details",
        fileext: ".xls", 
        exclude_img: true,
        exclude_links: true,
       exclude_inputs: true
   }); 
 });
</script>

标签: jqueryhtml

解决方案


您需要使用格式将form数据添加到 html中。tabletr td


推荐阅读