Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have some code taken from a forum that exports a table from html page and exports into Excel, however it doesn't work in IE but does in Chrome.

Can anyone help please?

<script type="text/javascript">
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]--><meta http-equiv="content-type" content="text/plain; charset=UTF-8"/></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 || 'RegistrationData', table: table.innerHTML}
    window.location.href = uri + base64(format(template, ctx))
  }
})()
</script>
Posted
Comments
ZurdoDev 1-Dec-15 12:58pm    
What happens in IE?
Suvendu Shekhar Giri 1-Dec-15 13:00pm    
Doesn't work in IE means?
Can you provide more information ?
padders01 2-Dec-15 6:23am    
Hi, when I click on the button in IE, nothing happens. An error in the corner of IE comes up. Webpage error details



Message: Object doesn't support this property or method
Line: 67
Char: 30



Message: Object doesn't support this property or method

There is nothing on line 67 though

Stephen Hewison 2-Dec-15 6:40am    
What version of IE?
padders01 2-Dec-15 6:43am    
IE8, using work computer on XP. Only have Chrome and IE8 installed on my machine. No problems with Chrome

1 solution

IE 8 doesn't provide support for window.btoa

It was only introduced in IE10.

Take a look at the following. It's a polyfill for browsers which don't support window.btoa or window.atob

https://github.com/davidchambers/Base64.js[^]
 
Share this answer
 
Comments
padders01 2-Dec-15 6:52am    
Ah, thank you. Tried that, getting a different error now
Webpage error details


Message: The data area passed to a system call is too small.

Line: 72
Char: 5
Code: 0
Stephen Hewison 2-Dec-15 7:00am    
That's a new question but I think it's going to be a limit on how much information can be passed through a uri attribute. Please accept if this answered your original question. Feel free to ask a new question.
padders01 2-Dec-15 7:49am    
Ok thank you, I have accepted that. Thanks for your help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900