How to export extjs grid data to excel?

一世执手 提交于 2019-12-10 03:47:03

问题


I have a grid with large number of records. I use filters to filter the data as required. But i want to export the filtered data to a excel sheet for further usage.

I went through some articles available but they seem different and not compatible with latest 4.2 version.

Please help me in achieving this in simple manner.

Thanks much!


回答1:


For extjs < 4 http://edspencer.net/2009/11/24/ext-ux-exporter-export-any-grid-to-excel-or-csv/

For extjs >= 4 http://www.sencha.com/forum/showthread.php?136598-Export-store-to-Excel




回答2:


As far as I know this isn't possible without a Serverside implementation in a cross browser manner.

In theory you create a OpenXML document string by reading the current records from the store and encode it with base64. Then write this to a Data Uri. The first that didn't allow inline data other then images is IE so this won't work for all IE browser version due to limitations like size and images only. This will be the reason why there are no up to date implementations.




回答3:


Successfully implemented this approach for Ext JS 4. To give it a flexibility of an abstract class, follow the instructions:

  1. Take functions from here and extract them into a separate class as global.
  2. Replace all "this" function references to global function calls.

  3. Add "grid" parameter to all functions starting with the entry one (downloadExcelXml()).

  4. Replace the remaining "this" calls to grid references (as functions were expected to act inside a grid).

  5. Now add this button in your grid constructor and call downloadExcelXml() as a handler like this:

    exportButton = {
      xtype: 'button',
      text: 'xls',
      listeners: {
        click: function (button, event, eOpts) {
          downloadExcelXml(
            false,
            "TableHeader",
            eOpts.data.grid);
        },
      data: {
        grid: this
      }
    };
    


来源:https://stackoverflow.com/questions/17715833/how-to-export-extjs-grid-data-to-excel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!