protected void BtnDao2_Click(object sender, EventArgs e) { string filename = "chongzhi" + DateTime.Now.ToString("yyyyMMdd") + ".xls"; string style = @"<style> .text { mso-number-format:/@; } </script> "; //解决第一位字符为零时不显示的问题 //this.GridView2.AllowPaging = false; //this.GridView2.DataBind(); filename = HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8);//解决导出EXCEL时乱码的问题 Response.ClearContent(); Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); Response.ContentType = "application/excel"; Response.AppendHeader("Content-Disposition", "attachment;filename=" + filename); System.IO.StringWriter sw = new System.IO.StringWriter();//定义一个字符串写入对象 HtmlTextWriter htw = new HtmlTextWriter(sw);//将html写到服务器控件输出流 this.GridView2.RenderControl(htw);//将控件GRIDVIEW中的内容输出到HTW中 Response.Write(style); Response.Write(sw); Response.End(); //这里对于分页的gridview,可以向将分页取消,重新绑定,在写入,完成后再允许分页,再绑定。 } 总结,导出文件为2003的,但是打开时还是会有点问题,虽然能显示。