Export dynamic html table to excel in javascript in firefox browser

前端 未结 4 445

Want to Export dynamic html table to excel in javascript is there any way can i do do in firefox browser without using activex object in code .please help me

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-04 16:27

    Here's a function for doing this in Firefox with JavaScript, assuming the user has Excel installed on their machine:

    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)) } })()

    jsFiddle live example:

    • http://jsfiddle.net/insin/cmewv/

提交回复
热议问题