protected void imgExport_Click(object sender, ImageClickEventArgs e)
{
GvList.Columns[0].Visible = false;
GvList.Columns[3].Visible = false;
DateTime dt = DateTime.Now;//给导出后的Excel表命名,结合表的用途以及系统时间来命名
string filename = dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Second.ToString();
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment;filename=" +"国家" + filename + ".xls");//导出文件命名,此处如果也编码的话,导出的中文名会是乱码
Response.ContentEncoding = System.Text.Encoding.UTF7;//如果设置为"GB2312"则中文字符可能会乱码
Response.ContentType = "applicationshlnd.xls";
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
GvList.RenderControl(oHtmlTextWriter);//Add the GvList into the output Stream.
Response.Write(oStringWriter.ToString());//Output the stream.
Response.Flush();
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
//override VerifyRenderingInServerForm.
}