How to export extjs grid data to excel?

a 夏天 提交于 2019-12-05 04:47:24

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.

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