0

I'm trying to export a html table to IE but it doesn't work and it doesn't play anything. I tested on Firefox and Chrome. It can export. here is the source code that i use for Firefox and Chrome:

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, filename) {
            if (!table.nodeType) table = document.getElementById(table)
            var ctx = { worksheet: name || 'Worksheet', table: table.innerHTML }
            document.getElementById("dlink").href = uri + base64(format(template, ctx));
            document.getElementById("dlink").download = filename;
            document.getElementById("dlink").click();
        }
    })()
AngocA
  • 7,655
  • 6
  • 39
  • 55
  • Helps if you note **which** version of IE you're having trouble with. – Tieson T. Aug 12 '13 at 08:36
  • Tried on IE <=9 apparently the issue is with the 'btoa' as it is not supported in those versions, however, @elclanrs Linked me up to this gtub polyfill https://github.com/davidchambers/Base64.js, but,somehow I still can't have it Export to Excel...(Sad).. Find thread: http://stackoverflow.com/questions/18286745/iexplorer-script438-object-doesnt-support-property-or-method-btoa – ErickBest Aug 17 '13 at 09:00
  • I try to user IE<=9 version, but it still can't export. – TONY SOEUN Sep 20 '13 at 09:59
  • This is an ongoing problem, i need a fix too. – cooking good Nov 07 '13 at 17:02

0 Answers0