javascript - tableToExcel jQuery throws strange error in IE - Stack Overflow

I am using a jQuery function to export my HTML table to Excel. This is a function I have seen used in p

I am using a jQuery function to export my HTML table to Excel. This is a function I have seen used in plenty of other places, and it works fine for me in Chrome:

var tableToExcel = (function() {
            var uri = 'data:application/vnd.ms-excel;base64,'
, template = '<html xmlns:o="urn:schemas-microsoft-:office:office" xmlns:x="urn:schemas-microsoft-:office:excel" xmlns=""><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) table = document.getElementById(table)
                var ctx = { worksheet: name || 'Worksheet', table: table.innerHTML }
                window.location.href = uri + base64(format(template, ctx))
            }
        })()

However, in IE 10, this line: "window.location.href = uri + base64(format(template, ctx))" - is throwing the error: "SCRIPT122: The data area passed to a system call is too small."

I've done a bit of research and it seems like IE is not able to handle the length of the URI for some reason. Are there any workarounds?

I am using a jQuery function to export my HTML table to Excel. This is a function I have seen used in plenty of other places, and it works fine for me in Chrome:

var tableToExcel = (function() {
            var uri = 'data:application/vnd.ms-excel;base64,'
, template = '<html xmlns:o="urn:schemas-microsoft-:office:office" xmlns:x="urn:schemas-microsoft-:office:excel" xmlns="http://www.w3/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) table = document.getElementById(table)
                var ctx = { worksheet: name || 'Worksheet', table: table.innerHTML }
                window.location.href = uri + base64(format(template, ctx))
            }
        })()

However, in IE 10, this line: "window.location.href = uri + base64(format(template, ctx))" - is throwing the error: "SCRIPT122: The data area passed to a system call is too small."

I've done a bit of research and it seems like IE is not able to handle the length of the URI for some reason. Are there any workarounds?

Share asked Sep 4, 2013 at 17:09 JMax2012JMax2012 3732 gold badges6 silver badges25 bronze badges 1
  • solved here :- stackoverflow./questions/27039474/… – Alok Commented Dec 4, 2014 at 15:05
Add a ment  | 

1 Answer 1

Reset to default 4

You my friend are in big trouble ( kidding )!

The main issue with older versions of IE is the support for base64 encoding which can be taken care of using this Javascript library.

But the main issue is the Data URL Scheme which is available on WebKit based browsers and you can have it on IE based on RCA 2397. It has a limited functionality and mostly works for images and css. Here is a useful link. Also make sure to read the Wikipedia page for Data URL Scheme

**Now to talk about workarounds! **

The main solution is writing a server side script that creates the Excel file and you just use an Ajax call to send it back to the user! you can even store that file on your server's Filesystem and just send the address of that file.

Though if you are mostly focusing on the client side and you really need to work on IE, you should use a download library, preferably the ones that have swf (Flash support) here is one that I have not used yet, though I am hoping to get the result that you are looking for. There are claims that downloadify does it well and let me know how it goes!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742292318a4416429.html

相关推荐

  • javascript - tableToExcel jQuery throws strange error in IE - Stack Overflow

    I am using a jQuery function to export my HTML table to Excel. This is a function I have seen used in p

    18小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信