日期:2014-05-17  浏览次数:20795 次

C#中如何将GridView数据导入到Excel,请指教!
我从数据库查出一些数据绑定到一个GridView,
我想把GridView的数据导入到Excel表格,可以做到吗?
我以前在VB中可以将DataGrid中数据导入到Excel,但是C#我不会,请指教!

------解决方案--------------------
vb.net和C#好像差别不大哦
------解决方案--------------------
Response.Clear();
Response.Buffer = true;
Response.Charset = "GB2312 ";
Response.AppendHeader( "Content-Disposition ", "attachment;filename=FileName.xls ");

Response.ContentEncoding = System.Text.Encoding.UTF7;

Response.ContentType = "application/ms-excel ";
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
this.GridView1.RenderControl(oHtmlTextWriter);
Response.Output.Write(oStringWriter.ToString());
Response.Flush();
Response.End();
------解决方案--------------------
http://www.zzcx.net.cn/