Javascript to export html table to Excel

后端 未结 3 1887
忘掉有多难
忘掉有多难 2020-11-28 04:45

I need to export the html table in my page to an Excel when user clicks \'Export\' button. Now, I found a solution here on stack overflow that works in Firefox.

Expo

3条回答
  •  醉酒成梦
    2020-11-28 05:10

    For UTF 8 Conversion and Currency Symbol Export Use this:

    var tableToExcel = (function() {
      var uri = 'data:application/vnd.ms-excel;base64,'
        , template = '{table}
    ' , 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)) } })()

提交回复
热议问题