1

I am getting a

ERROR: "SCRIPT438: Object doesn't support property or method 'btoa'"

in Internet Explorer when trying to Export HTML Table to Excel using code:.

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

        $('#'+table+' .rowNumbers').remove();

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

        }
    })()

What could possibly be a workaround for this quandary in IE for those still in IE < = 9?

Script gotten from: HTML Table to Excel Javascript

Community
  • 1
  • 1
ErickBest
  • 4,586
  • 5
  • 31
  • 43
  • 2
    Tada! https://github.com/davidchambers/Base64.js – elclanrs Aug 17 '13 at 08:30
  • Man that was Quick!... Still, does this require the installation of all files in the ZIP?..(Sad) – ErickBest Aug 17 '13 at 08:33
  • Just include the minified file, that's all you need. – elclanrs Aug 17 '13 at 08:35
  • how to mix with the `tableToExcel` function?... any Idea? – ErickBest Aug 17 '13 at 08:42
  • 1
    If you include the script it should work. If the functions don't exist in `window` it will create them, that's what a "polyfill" does. – elclanrs Aug 17 '13 at 08:43
  • Relax Man!... am Asking coz I Still get the Error even after adding it... – ErickBest Aug 17 '13 at 08:44
  • It Changed to: `SCRIPT122: The data area passed to a system call is too small.`... Firefox, Chrome, Opera perfectly Exporting to Excel... but IE not still – ErickBest Aug 17 '13 at 08:48
  • Were you able to resolve this? Iam currently facing same issue...Most of the JS libraries work for FireFox but not in IE.. – Nayeem Jun 07 '14 at 13:58
  • onclick="return ExcellentExport.excel(this, 'datatable', 'Sheet Name Here'); Give's an window data:application/vnd.ms-excel;base64,PGh0bWwgeG1sbnM6bz0idXJuOnNjaGVtYXMtbWljcm9zb2Z0LWNvbTpvZmZpY2U6b2ZmaWNlIiB4bWxuczp4PSJU+PC9ib2R5PjwvaHRtbD4= window with url like this – Nayeem Jun 07 '14 at 13:59
  • For answer refer http://stackoverflow.com/questions/18508582/alternative-btoa-encoding-in-internet-explorer – Yogesh Manware Jan 02 '15 at 08:12

0 Answers0