The project is extjs, which is mainly used to export extjs gridpanel data.
You can use Ext. getcmp () to obtain the gridpanel object and use the rewrite method to obtain the Excel String. This should not be a big problem.
CopyCode Code: // 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 = 'framejs ';
// 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 ('framejs '),
Isupload: True,
Params: {filename: Title + '.xls '}
})
} Else {
Document. Location = 'data: Application/vnd. MS-Excel; base64, '+ base64.encode (vexportcontent );
}
The above is the form virtual submission method. However, I tried many methods. After the data is post, the Excel file cannot be generated. After the data is generated, the download method cannot be implemented. (That is, it cannot be generated on the server side, but can be generated on the local machine .) After several turning points, I thought of debugging through data analysis. Check whether the data is post to the webpage.Copy codeThe 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); // process 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 generated and downloaded CS File
Later I found this tool.
The procedure is simple:
Open the plug-in on the toolbar
Although it is in English, let alone. All documents are in English.
Two recent photos
Here we can see the error message after post.
This is a page that cannot be seen without refreshing the new post. This is why I have struggled for a long time. I finally know what is wrong today.
Copy the error message to the text to generate an HTML file.
It turned out to be a ghost of the. NET security mechanism.
Add two sentences after system. Web in Web. config.
<Httpruntime requestvalidationmode = "2.0" type = "codeph" text = "/codeph"/>
<Pages validaterequest = "false"/>
Okay, the problem is solved.