JS Tip: Compatibility Export table for Excel file __ compatible

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.