【问题标题】:export excel from extjs grid从 extjs 网格导出 excel
【发布时间】:2016-11-30 03:02:43
【问题描述】:

我想将 extjs 网格内容导出到 excel 文件。所以我已经做了什么: 我通过Ext.Ajax.request发送到网格的servlet json内容,比如

Ext.Ajax.request({
        url : 'ExportToExcel',
        method:'POST',
        jsonData: this.store.proxy.reader.rawData,
        scope : this,
        success : function(response,options) {
            this.onExportSuccess(response, options);
        },
        //method to call when the request is a failure
        failure: function(response, options){
            alert("FAILURE: " + response.statusText);
        }
    });

然后在 servlet 中我得到 servlet 中的 json 做一些事情,例如创建excel文件,将其转换为字节数组并尝试响应。 在 Ext.Ajax.request 在成功方法中,当我尝试做这样的事情时:

var blob = new Blob([response.responseText], { type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet});

var downloadUrl = window.URL.createObjectURL(blob);
var a = document.createElement("a");
a.href = downloadUrl;
a.download = filename;
document.body.appendChild(a);
a.click();

它下载excel文件,但是当我打开它时出现错误,说格式或扩展名无效。

为什么? 是否可能取决于编码? 我做错了什么?

【问题讨论】:

    标签: servlets extjs


    【解决方案1】:

    Ext 带有一个内置的 excel 导出器。您可能想尝试使用它来查看是否获得所需的结果

      grid.saveDocumentAs({
        type: 'excel',
        title: 'My Excel Title',
        fileName: 'MyExcelFileName.xml'
    });
    

    来自工具包:Ext.grid.plugin.Exporter

    【讨论】:

      猜你喜欢
      • 2023-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-07
      • 2023-03-19
      • 1970-01-01
      • 2023-03-30
      • 2013-11-08
      相关资源
      最近更新 更多