将html导出为ex​​cel,排除一些单元格或列

<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插件导出HTML表格

我只使用:

 <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' 

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