0

首先,我必须使用 PHP 和 MySQL 从数据库中获取数据。
然后,我在表格中显示内容。
最后,我使用 Javascript 将表格内容导出到 Excel。

它在除 IE 之外的所有浏览器中都可以正常工作。

我在 IE 中收到的错误是:Object doesn't support this property or method

<script Language="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="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:Excel‌​Worksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><t‌​able>{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)) } })() </script>
4

0 回答 0