In general, the table export of the project is to send the ID to the back end, and then return a network link. After the interface returns, the automatic download is realized through a link. However, if the amount of data is not large, and the data has been obtained in the front end, you can directly generate excel files through the front end.

Requirements are as follows: Click batch Export after multiple selectionClick export to get the current table array, render the table node on the page, and set display: None

document.getElementById("table").outerHTML + "</body></html>"; Const Blob = new Blob([HTML], {type: "application/vnd.ms-excel"}); // Const Blob = new Blob([HTML], {type: "application/vnd.ms-excel"});Copy the code

CreateObjectURL (blob); then, the link a can be exported by triggering the click event.

Matters needing attention: When creating a table node, you can set the text template of the node first and then use the. InnerHTML = text template to export the table node and a link multiple times. You need to check and remove the table node and a link first

A.setattribute ("download", "export table "); a.setAttribute("target", "_blank");Copy the code

If there is a deeper customization of the table style you need to introduce other packages for processing, or back-end processing.