Several ways to export Excel files in Web

Source: Internet
Author: User

In general, there are two approaches: server-side generation and browser-side generation.

Server-side generation is: according to the user request, to obtain the corresponding data, using POI/JXL, Jacob/jawin+excel, or using the data to spell HTML table or CVS plain text data format. Then, in the form of. xls or. cvs format, the file is returned to the user, specifying Content-type:application/vnd.ms-excel, and the browser prompts the file to be downloaded as an Excel file.

POI/JXL, Jacob/jawin generates the BIFF format for Excel. Html/csv is a text format, not saved as an Excel file, many Excel features are not available. Jacob/jawin requires a Windows system on the server side and has excel2000 or later installed. POI/JXL and Html/csv Way, the server side can cross the platform.

The browser-side generated Excel file does not have a particularly perfect solution, because JS cannot handle binary. There are probably the following options, each with its pros and cons.

1. ActiveX Mode: Use Js/vbs to invoke the Excel object, http://setting.iteye.com/blog/219302, there is an example of ExtJS Gridpanel exported as Excel. (Ie+excel)

2. IE Command mode: output HTML or CSV to open window, then use ExecCommand's SaveAs command to save as CSV or XLS. (IE6 only)

3. Server-Side Transfer method: the HTML table or the concatenation of the CSV to the server side, the server and then follow the Content-type:application/vnd.ms-excel back, the browser will be processed in Excel. Compared to server-side stitching, there is less time to take the number of operations. (All)

4. Data protocol mode: for browsers that support the data protocol, HTML or CSV can be processed first with JS base64 and then prefixed Data:application/vnd.ms-excel;base64, You can enable the browser to handle the data as Excel, the browser will prompt to download or open Excel file, unfortunately, IE does not support. ExtJS's official website has a grid of plugin, implemented to export the XHTML format of the pseudo-Excel file, that is done. (except IE)

Only the first option in the browser is to export a real Excel file in the BIFF format, other ways are text format. ActiveX mode can only be used on the Windows platform of IE browser, and need to reduce the security of IE, so the application is relatively limited. Complex Excel files, or it is better to generate Excel with POI/JXL on the server side. If the browser is fixed bit IE6, browser-side mode 2 is the best solution. If you want to reduce the computational pressure on the server-side CPU, client scenario 3 is feasible, and cross-platform (less fetching and generating binaries than POI/JXL). Scenario 4 is also a good way to do this if it's a non-IE browser.

PS: Another option is to have the IE and Excel users on the Web page right click "Export to Microsoft Excel", then you can select the table area to export, click the "Import" button to complete the import.

Several ways to export Excel files in Web

Related Article

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.