ExtJs Excel Export and download problems with the IIS server side _extjs

Source: Internet
Author: User
Tags base64
The project is ExtJS mainly for the ExtJS gridpanel data export This piece first does the explanation.
We can get to the Gridpanel object through the EXT.GETCMP () method and get the Excel string by rewriting the method can be Baidu to. This should not be a big problem either.
Copy Code code 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 for form virtual submission. But there are many ways to experiment. It is not possible to generate Excel after the data post has been passed through the build download method. (That is, it cannot be generated on the server side, but this machine can be generated.) After many ideas of the transition later thought through data analysis to debug. See if the data is post to the Web page
Copy Code code as follows:

String tmpfilename = "Export.xls";
String tmpcontent = request["Exportcontent"];
if (request["FileName"]!= "")
{
Tmpfilename = request["filename"];//get the filename passed?
Tmpfilename = System.Web.HttpUtility.UrlEncode (Request.ContentEncoding.GetBytes (Tmpfilename));//handling of Chinese filename
}
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 ();

Above is the generated and downloaded CS file

Then I found this tool.

The exact steps are simple:

Open a plugin on the toolbar

Although it is in English, it is a cinch. The documents are all read in English.

Two recent pictures

Here you can see the post past the error message.

This is a page that cannot be seen without a refresh post. Because of this and tangled for a long time. Today I finally know what's wrong.

Copy the error message to the text to generate the HTML file.

It turns out to be a ghost of the. NET security mechanism.

After Web.config's system.web, add two words to fix it.

<pages validaterequest= "false"/>

All right, solve the problem and settle the BO.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.