导出到Excel无法在IE中工作 [英] Export to Excel not working in IE
本文介绍了导出到Excel无法在IE中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从论坛中获取了一些代码,这些代码从html页面导出一个表并导出到Excel中,但它在IE中不起作用但是在Chrome中。
有人可以帮忙吗?
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>
推荐答案
IE 8不支持window.btoa
它仅在IE10中引入。
看看以下内容。这是一个不支持window.btoa
或window.atob
$ b $的浏览器的polyfill b
https://github.com/davidchambers/Base64.js [ ^ ]
IE 8 doesn't provide support forwindow.btoa
It was only introduced in IE10.
Take a look at the following. It's a polyfill for browsers which don't supportwindow.btoa
orwindow.atob
https://github.com/davidchambers/Base64.js[^]
这篇关于导出到Excel无法在IE中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文