One common way to export a table as an Excel file in Js is to call ActiveXObject ("Excel. application "), but this method has limitations and can only be implemented in browsers in the IE series, but the compatibility is not ideal.
After testing, the recommended method can export the table content to an Excel file with good compatibility.
Copy codeThe Code is as follows:
Var str = "blog, domain name \ nBlog, 2 \ njb51.net, 3 ";
Var uri = 'data: text/csv; charset = UTF-8, '+ str;
Var downloadLink = document. createElement ("");
DownloadLink. href = uri;
DownloadLink. download = "export.csv ";
Document. body. appendChild (downloadLink );
DownloadLink. click ();
Document. body. removeChild (downloadLink );
This method is OK in Google/Firefox browsers, but an error message "The data area passed to the system call is too small" appears in IE, the reason is that the number of bytes specified by href is too large.
So, the IE browser has to judge that the ActiveXObject format is used.
In this way, you can use Javascript to export HTML content to an Excel file.