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.
//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
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
I later found this tool
The specific steps are very simple:
Open the plug-in on the toolbar
Although it is in English, it doesn’t matter. The documents are all in English.
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.
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.