0
我正在處理角項目。現在我需要將數據導出到複雜的表結構中。有任何圖書館可以爲我處理這個問題嗎? 使用javascript從複雜結構表(rowspan或colspan)從html導出excel或csv
我正在處理角項目。現在我需要將數據導出到複雜的表結構中。有任何圖書館可以爲我處理這個問題嗎? 使用javascript從複雜結構表(rowspan或colspan)從html導出excel或csv
你可以試試下面的功能:
function ExportToExcel(fileName)
{
var isIE = (navigator.userAgent.indexOf('MSIE') !== -1 || navigator.appVersion.indexOf('Trident/') > 0);
if (isIE) {
// IE > 10
if (typeof Blob != 'undefined') {
var fileData = new Blob([document.getElementById("datatable").innerHTML.replace(/=" "/gi, "")], {type: 'application/vnd.ms-excel,'});
window.navigator.msSaveBlob(fileData, fileName + '.xls');
}
// IE < 10
else {
myFrame.document.open("text/html", "replace");
myFrame.document.write(document.getElementById("datatable").innerHTML.replace(/=" "/gi, ""));
myFrame.document.close();
myFrame.focus();
myFrame.document.execCommand('SaveAs', true, fileName + '.xls');
}
}
// crome,mozilla
else {
var uri = 'data:application/vnd.ms-excel,' + document.getElementById("datatable").innerHTML.replace(/ /g, '%20');
var link = document.createElement("a");
link.href = uri;
link.style = "visibility:hidden";
link.download = fileName + ".xls";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
}
爲了使此功能工作,在舊的IE瀏覽器,你需要有和IFRAME與名myFrame,這架被用於在這個功能。另外,還要確保通過div的ID來包裝你的表DIV裏面,在這個片段是數據表
感謝,讓我試試這個。我也希望它是base64。你可以告訴我嗎? –
你想在base64中使用什麼?數據或Excel工作表? –
是的,在html上呈現數據後的Excel工作表 –