#region 請購信息導出Excel wkk 2008-4-12
protected void lbtn_Excel_Click(object sender, EventArgs e)
{
Response.Clear();
Response.Buffer = true;
Response.Charset = "utf-8";
Response.AppendHeader("Content-Disposition", "attachment;filename=PRInfo.xls");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");//设置输出流为繁體中文
Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
this.EnableViewState = false;
System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true);
System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
this.DataGrid_PO.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
} public override void VerifyRenderingInServerForm(Control control)
{
//输出Excel文件用
}
#endregionEnableEventValidation="false"在html頁面也設置了,但是出現的是一個對話框英文,都不知道是什么原因?
protected void lbtn_Excel_Click(object sender, EventArgs e)
{
Response.Clear();
Response.Buffer = true;
Response.Charset = "utf-8";
Response.AppendHeader("Content-Disposition", "attachment;filename=PRInfo.xls");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");//设置输出流为繁體中文
Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
this.EnableViewState = false;
System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true);
System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
this.DataGrid_PO.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
} public override void VerifyRenderingInServerForm(Control control)
{
//输出Excel文件用
}
#endregionEnableEventValidation="false"在html頁面也設置了,但是出現的是一個對話框英文,都不知道是什么原因?
public override void VerifyRenderingInServerForm(Control control)
{
//输出Excel文件用
} 是什么意思? 你哪里用 AJAX ?
我貼的代碼那2個函數是做導入excel,因為沒+ajax,代碼是可以用的,+了之后,
response.write()就不可以用了,用System.Web.UI.ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "click", oStringWriter.ToString(), true);還是不行,不知道什么原因?
請高手幫我