html导出excel
function base64 (content) {
return window.btoa(unescape(encodeURIComponent(content)))
}
function exportTab () { // 导出
let tath = this
let table = document.getElementById('tableID') //tableID为dom层 table ID
let excelContent = table.innerHTML
let excelFile = "<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'>"
excelFile += '<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>'
excelFile += '<body><table>'
excelFile += excelContent
excelFile += '</table></body>'
excelFile += '</html>'
let link = 'data:application/vnd.ms-excel;base64,' + tath.base64(excelFile)
let a = document.createElement('a')
a.download = tath.tabtitle + '课时计划表' + '.xlsx'
a.href = link
a.click()
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步