-
10 Jun 2011 4:08 AM #1
Export store to Excel
Export store to Excel
Well, here's an exporter that can export a grid, tree or simply a store to excel. It's a fork from another project, I adapted it to work with ExtJs 4, using the new class system and fixed a couple of bugs.
The Csv exporter isn't implemented and the example and compiled files are not updated (so don't use Exporter-all.js).
It exports all the data in the store loaded at that time. If a grid is used it uses the renderers and column configurations from it.
The download is made through a button and uses datauri, so it doesn't work in older ie versions.
I hope it's useful, if you find bugs or make improvements, just fork it and send me a pull request.
https://github.com/iwiznia/Ext.ux.Exporter
-
10 Jun 2011 5:52 AM #2Sencha - Sales Team
- Join Date
- Mar 2007
- Location
- Melbourne, Australia (aka GMT+10)
- Posts
- 738
- Vote Rating
- 6
nice work. I'll check it out this weekend! :-)
Check out SenchaWorld.com for articles, screencasts, conference videos and more.
Sencha Technical Training : Asia Pacific Region
Code Validation : JSLint | JSONLint | JSONPLint
-
18 Jul 2011 4:03 PM #3
I did not use the Exporter-all.js file as the author suggested but included all other files:
<script type="text/javascript" src="Base64.js"></script>
<script type="text/javascript" src="Button.js"></script>
<script type="text/javascript" src="Formatter.js"></script>
<script type="text/javascript" src="./excelFormatter/ExcelFormatter.js"></script>
<script type="text/javascript" src="./excelFormatter/Workbook.js"></script>
<script type="text/javascript" src="./excelFormatter/Worksheet.js"></script>
<script type="text/javascript" src="./excelFormatter/Cell.js"></script>
<script type="text/javascript" src="./excelFormatter/Style.js"></script>
<script type="text/javascript" src="Exporter.js"></script>
However, I got the namspace undefined error when loading:
namespace is undefined
if (namespace === from...substring(0, from.length) === from) { ext-all-debug.js (line 3487)
Any idea?
-
19 Jul 2011 1:52 AM #4
You don't have to include all the files if you have the ext loader activated. It uses the new class method and defines it's dependencies. You only have to include Exporter.js
-
19 Jul 2011 5:25 AM #5
Hello,
It does not work for me on ext4.
I just add the script in my index:
And add the button to my grid:Code:<script type="text/javascript" src="app/lib/Exporter-all.js">
I get Ext.ux.Exporter is undefinedCode:dockedItems:[{ xtype: 'toolbar', dock: 'top', items: [{ text: 'Nouveau ticket', iconCls:'addticket', action: 'newticket' },{ text: 'Prendre en charge', iconCls:'linkticket', action: 'chrg', hidden:true },{ iconCls: 'summary', text: 'Aperçu', enableToggle: true, pressed: true, scope: this, toggleHandler: this.onSummaryToggle },'->',{ text: 'Archiver', iconCls:'datab', action: 'archi' },new Ext.ux.Exporter.Button({ component: this, text : "Download as .xls" })] }],
Thx in advance for your help
Vaucer
-
19 Jul 2011 6:43 AM #6
The exporter-all.js is not updated, so you have to include Exporter.js
-
19 Jul 2011 9:56 AM #7
Ran into the same problem as nuskin, but happened for me when I tried just including Exporter.js, when I included all the files, I was able actually get into the button class when adding the button but not sure what I need to set in the buttons config to get it to work. Tried the storeId, tried the store itself, and even tried the grid as the component. Any ideas?
-
19 Jul 2011 11:36 AM #8
I use it like this. If the exporterebutton is inside a grid or a tree it autodetects the store. You can use it in a grid without creating a new class, just add the 'uses' config and the exporterbutton in the dockedItems.
Code:Ext.Loader.setConfig({enabled: true}); Ext.Loader.setPath('Ext.ux', '/path-to-ext-ux'); Ext.define('App.view.SomeGrid', { extend: 'Ext.grid.Panel', uses: [ 'Ext.ux.exporter.Exporter' ], initComponent: function() { this.store = "SomeStore"; this.dockedItems = [{ xtype: 'toolbar', dock: 'top', items: [{ xtype: 'exporterbutton' }]; this.columns = [/* YOUR COLUMNS */]; this.callParent(arguments); } });
-
19 Jul 2011 12:59 PM #9
Thanks that worked except that in the button class setComponent function the columns don't have the .on function off them, seem like a simple array. Also the show and hide events never seemed to get fired. So I set it on the render and used the headerCt instead of columns, which seems to work but when I actually click the download, it navigates to data:application/vnd.ms-excel;base64,PD94bWwgdm....Lots more just like it, but doens't do anything more. As I haven't tried to use the data stuff before not sure what's it's supposed to do. I'm trying to make a simpler version of my grid to show as an example and see if it works, but wanted to see if you had ideas ahead of time, thanks again for any help you can provide.
Code:Ext.Array.each( this.component.headerCt.items.items, function(col) { col.on( "render", setLink, me); });
-
20 Jul 2011 1:25 AM #10
Hi all
I have the same problem as teemac, I think.
I get the same result from my app, as I get from the exporter example. When I click the button in both the example and my app, I get a part file from firefox and this only contains some column information plus some other values that doesn't appear in the grid.
I'm using the Exporter.js in my app, so that should be okay.
I made a small change to the Worksheet.js after line 150:
I changed it because I have an empty column that it didn't like. But I don't think that is a problem.Code:if(record.fields.get(name)) { var value = record.get(name), type = this.typeMappings[col.type || record.fields.get(name).type.type]; }
Any suggestions?


Reply With Quote


