问题描述
有谁做个gridview导出到Excel文件.必须导出到officeexcel2007中,请大侠们给个例子参考参考!谢谢!
解决方案
解决方案二:
usingSystem.IO;usingSystem.Text;//页面增加一个按钮,单击事件添加如下方法:protectedvoidButton1_Click(objectsender,EventArgse){Export("application/ms-excel","学生成绩报表.xls");}privatevoidExport(stringFileType,stringFileName){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;StringWritertw=newStringWriter();HtmlTextWriterhw=newHtmlTextWriter(tw);GridView1.RenderControl(hw);Response.Write(tw.ToString());Response.End();}//如果没有下面方法会报错类型“GridView”的控件“GridView1”必须放在具有runat=server的窗体标记内publicoverridevoidVerifyRenderingInServerForm(Controlcontrol){}
解决方案三:
http://www.svnhost.cn/Download/Detail-79.shtml
解决方案四:
privatevoidExport(stringFileType,stringFileName){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;StringWritertw=newStringWriter();HtmlTextWriterhw=newHtmlTextWriter(tw);GridView1.RenderControl(hw);Response.Write(tw.ToString());Response.End();}
解决方案五:
publicstaticvoidToExcel(System.Web.UI.Controlctl,stringFileName){HttpContext.Current.Response.Charset="UTF-8";HttpContext.Current.Response.ContentEncoding=System.Text.Encoding.Default;HttpContext.Current.Response.ContentType="application/ms-excel";HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename="+""+FileName+".xls");ctl.Page.EnableViewState=false;System.IO.StringWritertw=newSystem.IO.StringWriter();HtmlTextWriterhw=newHtmlTextWriter(tw);ctl.RenderControl(hw);HttpContext.Current.Response.Write(tw.ToString());HttpContext.Current.Response.End();}//必须有下面这句!否则不会通过!publicoverridevoidVerifyRenderingInServerForm(Controlcontrol){//ConfirmsthatanHtmlFormcontrolisrenderedfor}
解决方案六:
在项目中我们经常会遇到要求将一些数据导出成Excel或者Word表格的情况,比如中国移动(我是中国移动用户)网上查话费的页面中就有一个导出到Excel的功能,光大网上银行查看历史明细也有这些功能....,原本以为这个问题不难的,不过看到网上经常有朋友问,于是我整理了一下,供大家参考。《GridView导出到Excel或Word文件》网址:http://blog.csdn.net/zhoufoxcn/archive/2008/05/16/2450642.aspx
解决方案七:
GridView数据导入Excel/Excel数据读入GridViewhttp://blog.csdn.net/liyin_liu/archive/2008/05/08/2415145.aspx
解决方案八:
网上很多的!