<body>
<a href="javascript:exportFile()">导出</a>
<table id="showTable" border="1" width="100%">
<c:forEach begin="0" end="5000" var="i">
<tr>
<c:forEach begin="0" end="30" var="j">
<!-- mso-number-format:'@' 数字以文本方式显示 -->
<td style="text-align:center; mso-number-format:'@';">${i }${j }</td>
</c:forEach>
</tr>
</c:forEach>
</table>
<script type="text / JavaScript "> * 2) Date: 'yyyy / mm / dd' *. 1) text: '@' * style =" MSO-Number-the format: '@'; " * table export
/ **
* 3) numbers: '#, ## 0.00'
* 4) Currency: '¥ #, ## 0.00'
*. 5) Percentage: '0.00% #'
* /
function exportfile () {
// Get form
var exportFileContent = document .getElementById ( "ShowTable") the outerHTML;.
// set format into Excel, table of contents by btoa into base64, this method is only used when the file is small (less than 1M)
// = window.btoa exportFileContent (unescape (the encodeURIComponent (exportFileContent )));
// Link var = "Data:" + MIMEType + "; Base64," + exportFileContent;
// use Blob
var = new new BLOB Blob ([exportFileContent], {type: "text / Plain; charset = UTF-. 8 "});
// solve the problem of Chinese garbled
= new new Blob BLOB ([the String.fromCharCode (0xFEFF), BLOB], {type: blob.type});
// set the link
var = window.URL.createObjectURL Link (BLOB);
var A = document.createElement ( "A "); // create a label
a.download =" data show .xls "; // set the hyperlink target (file name) to be downloaded
a.href = link; // set link a label
document.body.appendChild (a); // a label added to the page
a.click (); // set a click event tag trigger
document.body.removeChild (a); // remove a label
}
</ Script>
</ body>
page
download
After downloading Excel