Home >Web Front-end >JS Tutorial >ExtJs Excel export and download problems encountered on the IIS server side_extjs

ExtJs Excel export and download problems encountered on the IIS server side_extjs

WBOY
WBOYOriginal
2016-05-16 18:01:591643browse

The project is Extjs. It mainly focuses on Extjs GridPanel data export. Let me first explain it.
We can obtain the GridPanel object through the Ext.getcmp() method and obtain the Excel string through the overridden method. The specific method can be found on Baidu. This shouldn't be a big problem.

Copy code The code is as follows:

//Output report
function ExportReport(title) {
var vExportContent = Ext.getCmp("gridPanel").getExcelXml(null, title);
if (Ext.isIE6 || Ext.isIE7 || Ext.isSafari || Ext.isSafari2 || Ext. isSafari3 || Ext.isIE8) {
// var frm = document.createElement('form');
// frm.id = 'frmExtjs';
// frm.className = 'x- hidden';
// document.body.appendChild(frm);
var f = document.createElement("form");
f.id = "frmExtjs";
document.body. appendChild(f);
var i = document.createElement("input");
i.type = "hidden";
i.id = "exportContent";
i.name = " exportContent";
f.appendChild(i);
i.value = vExportContent;
Ext.Ajax.request({
url: 'frmExcel.aspx',
method: 'POST ',
form: Ext.get('frmExtjs'),
isUpload: true,
params: { FileName: title '.xls' }
})
} else {
document.location = 'data:application/vnd.ms-excel;base64,' Base64.encode(vExportContent);
}

The above is the method of virtual submission of the form. But I tried many methods. It was found that Excel cannot be generated after the data is posted, and it cannot be achieved through the download method after generation. (That is, it cannot be generated on the server side, but it can be generated on the local machine.) After many twists and turns of ideas, I finally thought of debugging through data analysis. Check whether the data is posted to the web page
Copy the code The code is as follows:

string tmpFileName = " export.xls";
string tmpContent = Request["ExportContent"];
if (Request["FileName"] != "")
{
tmpFileName = Request["FileName"]; //Get the passed file name?
tmpFileName = System.Web.HttpUtility.UrlEncode(Request.ContentEncoding.GetBytes(tmpFileName));//Handling Chinese file names
}
Response.Clear ();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename="" tmpFileName """);
Response.Charset = "";
System.IO.StringWriter tmpSW = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter tmpHTW = new System.Web .UI.HtmlTextWriter(tmpSW);
tmpHTW.WriteLine(tmpContent);
Response.Write(tmpSW.ToString());
Response.End();

The above is the CS file generated and downloaded

clip_image002

I later found this tool

The specific steps are very simple:

Open the plug-in on the toolbar

clip_image004

Although it is in English, it doesn’t matter. The documents are all in English.

clip_image006

clip_image008

Two recent photos

Here you can see the error message after the post has been posted.

This is a page that cannot be seen without refreshing the post. I have struggled with this for a long time. Today I finally figured out what was wrong.

Copy the error message to text to generate an html file.

clip_image010

It turns out that it was caused by the .net security mechanism.

Add two sentences after System.Web in web.config and it’s done.

Okay, the problem is solved.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn