第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

js通過拼接table導(dǎo)出Excel,但數(shù)據(jù)行數(shù)有5萬多行,一點(diǎn)擊下載就出現(xiàn)網(wǎng)絡(luò)錯(cuò)誤

js通過拼接table導(dǎo)出Excel,但數(shù)據(jù)行數(shù)有5萬多行,一點(diǎn)擊下載就出現(xiàn)網(wǎng)絡(luò)錯(cuò)誤

PHP
猛跑小豬 2019-03-05 12:37:19
js通過拼接table導(dǎo)出Excel,但數(shù)據(jù)行數(shù)有5萬多行,一點(diǎn)擊下載就出現(xiàn)網(wǎng)絡(luò)錯(cuò)誤,數(shù)據(jù)量少時(shí)正常下載代碼如下: <script> var idTmr; function getExplorer() { var explorer = window.navigator.userAgent ; //ie if (explorer.indexOf("MSIE") >= 0) { return 'ie'; } //firefox else if (explorer.indexOf("Firefox") >= 0) { return 'Firefox'; } //Chrome else if(explorer.indexOf("Chrome") >= 0){ return 'Chrome'; } //Opera else if(explorer.indexOf("Opera") >= 0){ return 'Opera'; } //Safari else if(explorer.indexOf("Safari") >= 0){ return 'Safari'; } } function toExcel(tableid) { if(getExplorer()=='ie') { var curTbl = document.getElementById(tableid); var oXL = new ActiveXObject("Excel.Application"); var oWB = oXL.Workbooks.Add(); var xlsheet = oWB.Worksheets(1); var sel = document.body.createTextRange(); sel.moveToElementText(curTbl); sel.select(); sel.execCommand("Copy"); xlsheet.Paste(); oXL.Visible = true; try { var fname = oXL.Application.GetSaveAsFilename("Excel.xls", "Excel Spreadsheets (*.xls), *.xls"); } catch (e) { print("Nested catch caught " + e); } finally { oWB.SaveAs(fname); oWB.Close(savechanges = false); oXL.Quit(); oXL = null; idTmr = window.setInterval("Cleanup();", 1); } } else { tableToExcel(tableid,'name', '項(xiàng)目分期報(bào)表.xls') } } function Cleanup() { window.clearInterval(idTmr); CollectGarbage(); } 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]-->' + '<style type="text/css">\n' + ' #table thead{width:100%;z-index:5;}\n' + ' #table td{overflow: hidden;text-overflow: ellipsis;white-space: nowrap;table-layout: fixed;padding-right: 0;}\n' + ' #table .project_title{background-color: #88e1ff;font-weight: bold;}\n' + ' #table .batch_title {font-weight: bold}\n' + ' #table .not_end{color: red;}\n' + ' #table tbody tr>td{text-align: left;padding-left: 5px;}'+ ' .not_charge{color: blue}\n' + ' .charge{color: green}\n' + ' .pay_month{color: purple}\n' + ' </style>'+ '</head><body><table id="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, filename) { if (!table.nodeType) table = document.getElementById(table) var ctx = { worksheet: name || 'Worksheet', table: table.innerHTML } document.getElementById("dlink").href = uri + base64(format(template, ctx)); document.getElementById("dlink").download = filename; document.getElementById("dlink").click(); } })() </script> 請(qǐng)問各位大神我該怎么寫才能讓這個(gè)excel可以下載下來。
查看完整描述

1 回答

?
有只小跳蛙

TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超8個(gè)贊

因?yàn)闉g覽器URL有長度限制. 你這種方法是將 excel數(shù)據(jù)轉(zhuǎn)換成 base64. 數(shù)據(jù)量大的時(shí)候長度超過瀏覽器GET 限制. 部分被阻斷了. 就自然識(shí)別不出來這個(gè)excel.

具體解決辦法
使用blob對(duì)象.

let blob = new Blob([format(template, ctx]);
document.getElementById("dlink").href = URL.createObjectURL(blob)
查看完整回答
反對(duì) 回復(fù) 2019-03-18
  • 1 回答
  • 0 關(guān)注
  • 1669 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)