Before Java are used in the back end to do export, the data table to do too much trouble, directly at the front end of the table is derived, and very convenient.
Blog article link: https://www.zjhuiwan.cn/info/20200212/4004242219096560.html
html form code
JS code
method 1
// export Excel function ToExcel () { //window.location.href='<%=basePath%>pmb/excelShowInfo.do '; // Get form var exportFileContent = document.getElementById ( "table_report") the outerHTML;. / / format into Excel, table of contents by btoa into base64, this method is only used when the file is small (less than 1M) //exportFileContent=window.btoa(unescape(encodeURIComponent(exportFileContent))); // Link var = "Data : "+ MIMEType +"; Base64, "+ exportFileContent; // use Blob var = new new blob Blob ([exportFileContent], {type:" text / Plain; charset = UTF-. 8 "}); // solve the Chinese garbled blob Blob new new = ([the String.fromCharCode (0xFEFF), BLOB], {type: blob.type}); // set the link var link = window.URL.createObjectURL(blob); var a = document.createElement ( "a" ); // create a label a.download = "enterprise of the problem demands summary .xls"; // set the target of the hyperlink is downloaded (file name) 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); // removing a tab }
Simple table exported to excel just fine.
`There are several issues that need attention
1, no border excel derived, as shown below. Solution: table need to add border = "1";
2, the table name can add bold <h2> </ h2>
3, but may need to export Canadian display table pages do not show: none
4, the exported excel open will be prompted to insecurity, as shown below:
This has not been resolved .. look ye out tomorrow. Js export format should be the issue, force became excel. Pro-test with Java back-end guide does not have this problem,
However, to excel not prompt this type of error (usually customers do not want to download the file may change), you can:
1 while pressing the keyboard "Ctrl + R", open the "Run", type "regedit" open "Registry Editor"
2 Find "HKEY_CURRENT_USER \ Software \ Microsoft \ Office \ 16.0 \ Excel \ Security" option, you can also "see" in check "address bar" to copy the path into the address bar. Depending on the version may be 14.0 (Office 2010), etc., as the case may be.
3 Click in the blank and a new right, select "DWORD (32- bit) value (D)". At this point there will be a "New Value # 1" under the list of items.
4 Select "New Value # 1" Right-click and select "Rename", changed its name to "ExtensionHardening", case-sensitive.
5 Select just modified "ExtensionHardening", right-click "Edit."
6 change the value to 0, and keep the default hexadecimal unchanged, and then click OK to complete the setup.
Then open not suggesting that ...