ExtJS4 dynamically generated grid exported to Excel (front-desk only)

Source: Internet
Author: User

Search for quite a long time, find some examples, because I am a beginner's sake mostly do not know how to use.



Study of the source code, get to now finally achieve the basic download. Fixed a small bug where a table could not be downloaded repeatedly, a bug that occurred using grid initialization


The following steps are documented: Maybe next time it works.


1. The download need to use the JS code, I have uploaded

http://download.csdn.net/detail/hu8471479/7281703


2. Add a reference to your HTML file, the path problem yourself, below is my path


3. At the beginning of the Ext.onready () of the JS code you want to use, add

Ext.Loader.setConfig ({enabled:true}); Ext.Loader.setPath (' Ext.ux.exporter ', ' ... /export/exporter '); Ext.require ([    ' Ext.ux.exporter.Exporter '    ]);

Set the namespace: Note the path


4. Use in the code, in the grid where you need to download the function of the appropriate place to join

  Xtype: ' Exporterbutton ',         //STORE:STORECOMPONENT:EXT.GETCMP (' gird_a ')

Here are two ways to initialize Excel, one to initialize with store, to use store's fields and data, because the fields in my store are in English, and the exported column names are in English so I'm not using this, I'm initializing it directly with a grid.


Here's what I'm modifying on the basis of someone else's code.


1. On line 40th of Exporter.js, changed to

  var columns = Ext.Array.filter (Grid.columnManager.columns,
The original code in the first parameter there is grid.columns, and then I found that the dynamically generated grid after reconfigure columns placed in Columnmanager.columns, so change


2. In the Workbook.js 77.78 lines, add two words

This.styles=[];this.worksheets=[];

The above 2 lines of code for some initialization, or Excel each generation because the previous data is not emptied resulting in a malformed format



After the simple modification of the above can be freely exported to a grid, and support the custom field of the table export, that is, the export table display columns


Over here:



Custom field generated code has been improved, and the speed has increased by n times, see my previous article

Have a question can leave a message, discuss together, Http://blog.csdn.net/decoderworld

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.