gpt4 book ai didi

jquery - 将 html 导出到 Excel,排除某些单元格或列

转载 作者:行者123 更新时间:2023-12-01 07:58:17 25 4
gpt4 key购买 nike

   <script>
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){
var exTable = $('#mywarning').clone();
exTable.find('.exclude').remove();
}
var ctx = {worksheet: name || 'Worksheet', table: exTable.innerHTML}
window.location.href = uri + base64(format(template, ctx))
}
})()
</script>

我使用上面的js导出到excel后用以下两行修改它以排除表格中的单元格

 var exTable = $('#mywarning').clone();
exTable.find('.exclude').remove();

但不起作用

最佳答案

我使用了这个插件:jQuery Plugin to Export HTML Tables

我只使用:

<script src="jquery-tableexport/tableExport.js"></script>
<script src="jquery-tableexport/jquery.base64.js"></script>

HTML:

<a href="#" onClick ="$('#table-name').tableExport({type:'excel', separator:';', escape:'false'});" id="buttonExportData" class="ui-btn ui-btn-inline ui-mini ui-shadow ui-corner-all">Export XLS</a>

该插件有以下选项:

separator: ','
ignoreColumn: [2,3],
tableName:'yourTableName'
type:'csv'
pdfFontSize:14
pdfLeftMargin:20
escape:'true'
htmlContent:'false'
consoleLog:'false'

所以你可以忽略一些列。希望这可以帮助。

关于jquery - 将 html 导出到 Excel,排除某些单元格或列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21975325/

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