简体   繁体   English

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

[英]export html to excel excluding some cells or columns

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

i use the above js to export to excel after modifying it with the following 2 lines to exclude cells in my table 我使用上面的js导出到excel后用以下2行修改它以排除我表中的单元格

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

but does not work 但不起作用

i used this plugin: jQuery Plugin to Export HTML Tables 我用这个插件: jQuery插件导出HTML表格

i only use: 我只使用:

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

HTML: 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>

the plugin has the following options: 该插件有以下选项:

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

so you could ignore some columns. 所以你可以忽略一些列。 Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM