62,025
社区成员
发帖
与我相关
我的任务
分享
#region 导出EXCEL
//导出Excel
protected void btn_Excel_Click(object sender, EventArgs e)
{
Export("application/ms-excel", "导出EXCEL.xls");
}
private void Export(string FileType, string FileName)
{
//以下三行可选,如果没有的话导出的只是当前页数据,没有其他页数据
//this.Grv_Outlay.AllowPaging = false;
//this.Grv_Outlay.AllowSorting = false;
//Grv_Date();//这里是你绑定gridview的方法
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF7;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
this.Grv_Depot.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
Response.Clear();
Response.Close();
}
public override void VerifyRenderingInServerForm(Control control)
{
}
#endregion