使用下面给出的代码为“ Double header”和“ CSS”导出HTML表,因为使用此代码很容易,DataTables不支持这些功能,但是我有3个问题。
下面是am中用于勒索的代码。
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="https://www.w3.org/TR/html401"><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
}
var blob = new Blob([format(template, ctx)]);
var blobURL = window.URL.createObjectURL(blob);
if (ifIE()) {
csvData = table.innerHTML;
if (window.navigator.msSaveBlob) {
var blob = new Blob([format(template, ctx)], {
type: "text/html"
});
navigator.msSaveBlob(blob, '' + nothing + '.xlsx');
}
} else
window.location.href = uri + base64(format(template, ctx))
}
})()
function ifIE() {
var isIE11 = navigator.userAgent.indexOf(".NET CLR") > -1;
var isIE11orLess = isIE11 || navigator.appVersion.indexOf("MSIE") != -1;
return isIE11orLess;
}
答案 0 :(得分:-1)