JS Tip: Compatibility Export table for Excel file February 2013 20:06 Monday by CabinTags: JS tips export Excel JS Export JS export Excel
The project often needs to export Excel files, not server-side processing, but rich clients use JavaScript scripts to process data and export files.
JS Export table is a common way to Excel files is called: ActiveXObject ("Excel.Application"), but this method has limitations, can only be implemented in the browser under the IE series, compatibility is not ideal.
After testing, the proposed method in this paper can be better compatibility of the export table content to Excel files. var str = "blog, domain name \nblog, 2\nsjolzy.cn, 3";
var uri = ' data:text/csv;charset=utf-8, ' + str;
var downloadlink = document.createelement ("a");
Downloadlink.href = URI;
Downloadlink.download = "Export.csv";
Document.body.appendChild (Downloadlink);
Downloadlink.click ();
Document.body.removeChild (Downloadlink);
This method is OK in the Google/Firefox browser, but in IE there is a " small data area passed to the system call " error tip because the number of bytes specified by href is too high.
So, for IE browser had to judge, using the form of ActiveXObject.
This will be a good use of JavaScript to export HTML content to Excel files. Author: sjolzy | Google + address: http://sjolzy.cn/ js-skills-export-table-to-excel-file-compatibility.html