gpt4 book ai didi

jquery - 将选定的行从表导出到Excel

转载 作者:行者123 更新时间:2023-12-02 14:43:03 28 4
gpt4 key购买 nike

我表中有数据。每行都有一个复选框。我希望当用户单击导出按钮时将选中的行导出到excel文件。

这是我的代码(GSP):

<div id="downloadExcelPopup" style="display: none">
<div id="" class="newserial_popup1"
style="width: 80%; height: 70%; float:left; ">
<div class="newbrand">
<div
style="background: #ff9900; width: 100%; float: left; padding: 15px;">
<h3 style="float: left; width: 80%; margin: 0px; color: #ffffff;">Export to Excel</h3>

<button class="close md-close cancelDownload" aria-hidden="true"
data-dismiss="modal" type="button">×</button>

</div>
<div class="form-horizontal group-border-dashed"
style="border-bottom: 1px solid #E5E5E5; margin-bottom: 10px;">
<div class="modal-body form"
style="clear: both; padding: 15px 0px 0px 0px;">
<div class="content" >

<div class="table-responsive" id="clienttrievent">
<table class="table table-bordered" id="datatable3" >
<thead>
<tr>
<th><g:checkBox name="myCheckbox" id="selectall" value="${false}" /></th>
<th>Company Name</th>
<th>ROC No</th>
<th>Contact Address</th>
<th>Contact No</th>

<th>E-Mail</th>
<th>Status</th>
</tr>
</thead>
<tbody id="clienttable">
<g:each in="${clientyeardetailsInstanceList}" status="i" var="customerInstance">
<tr class="${(i % 2) == 0 ? 'even gradeC' : 'odd gradeX'}">

<td><g:checkBox name="myCheckbox1" class="case" value="${false}" /></td>
<td>${customerInstance?.client?.companyname}</td>
<td>${customerInstance?.client?.registerno}</td>
<td>${customerInstance?.client?.companyaddress}</td>
<td>${customerInstance?.client?.contactno}</td>
<td>${customerInstance?.client?.email}</td>
<td>${(customerInstance?.client?.clientstatus) == 'on' ? 'ACTIVE' : 'INACTIVE'}</td>
</tr>
</g:each>


</tbody>
</table>

</div>
<input type="button" onclick="tableToExcel('datatable3', 'W3C Example Table')" value="Export to Excel">
</div>
</div>
</div>
</div>

<div class="modal-footer">
<button class="btn btn-default btn-flat md-close cancelDownload"
data-dismiss="modal" type="button">Cancel</button>
</div>
</div>
</div>
</g:form>

<script>
$("#selectall").click(function () {
var checkAll = $("#selectall").prop('checked');
if (checkAll) {
$(".case").prop("checked", true);
} else {
$(".case").prop("checked", false);
}
});
var tableToExcel = (function() {
var uri = 'data:application/vnd.ms-excel;base64,'
, template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
, base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
, format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) }
return function(table, name) {
if (!table.nodeType) table = document.getElementById(table)
var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
window.location.href = uri + base64(format(template, ctx))
}
})()
</script>

请指导我添加以下代码:
  • 如果选择了所有行,则将整个表下载到excel。
  • 仅下载选定的行即可精益求精。
  • 最佳答案

    使用Grails的Export to Excel plugin。因此,一旦设置好,就可以在 Controller 中调用一个函数,该函数将自动将表中的所有行导出到excel。但是,由于只希望导出一些行,因此可以将行的ID发送回 Controller 功能,该功能可以仅基于选定的ID创建条件查询,然后自动将其导出到Excel。

    关于jquery - 将选定的行从表导出到Excel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24755144/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com