0
我想将extjs网格内容输出为excel文件。所以我做了什么已经: 我送过Ext.Ajax.request电网的servlet的JSON内容,如从extjs grid输出excel
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的我得到的JSON在servlet的做一些东西,例如创建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文件,但是当我打开它会出现错误,说格式或扩展名是无效的。
原因? 是否可能取决于编码? 我做错了什么?