是一种常见的需求,可以通过以下步骤实现:
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="jquery.plugin.js"></script>
<table id="myTable">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
</tr>
</thead>
<tbody>
<tr>
<td>John Doe</td>
<td>john@example.com</td>
<td>1234567890</td>
</tr>
<tr>
<td>Jane Smith</td>
<td>jane@example.com</td>
<td>0987654321</td>
</tr>
</tbody>
</table>
<form id="myForm">
<label for="name">Name:</label>
<input type="text" id="name" name="name" value="John Doe"><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email" value="john@example.com"><br>
<label for="phone">Phone:</label>
<input type="tel" id="phone" name="phone" value="1234567890"><br>
</form>
<button id="exportBtn">Export to Excel</button>
table2excel
插件来导出表格数据,使用form2excel
插件来导出表单数据。可以通过以下方式调用插件:$(document).ready(function() {
// 导出表格数据
$('#exportBtn').click(function() {
$('#myTable').table2excel({
filename: 'table_data',
sheetName: 'Sheet1'
});
});
// 导出表单数据
$('#exportBtn').click(function() {
$('#myForm').form2excel({
filename: 'form_data',
sheetName: 'Sheet1'
});
});
});
以上代码中,filename
参数指定导出的Excel文件名,sheetName
参数指定导出的工作表名称。
Export to Excel
将会导出表格数据或表单数据到Excel文件。这种方法可以方便地将HTML表格和表单数据导出到Excel文件,适用于需要将数据进行导出、备份或与其他系统进行数据交互的场景。
腾讯云相关产品和产品介绍链接地址:
领取专属 10元无门槛券
手把手带您无忧上云