日期:2014-05-18  浏览次数:20457 次

GridView导出到Excel,只导出某些特定列怎么做?
导出代码如下:  

Response.ClearContent();
                //Response.AddHeader( "content-disposition ",   "attachment;   filename=MyExcelFile.xls ");
                Response.AddHeader( "content-disposition ",   "attachment;   filename=test.xls ");
                Response.ContentEncoding   =   System.Text.Encoding.GetEncoding( "GB2312 ");//设置输出流为简体中文
                Response.ContentType   =   "application/excel ";
                StringWriter   sw   =   new   StringWriter();
                HtmlTextWriter   htw   =   new   HtmlTextWriter(sw);
                //gvData.Columns[1].Visible   =   false;
                gvData.RenderControl(htw);
                Response.Write(sw.ToString());
                Response.End();

比如第一列代码   不想导出怎么办?
谢谢各位指点

------解决方案--------------------
SF
------解决方案--------------------
gridview.columns[0].visible = false;
------解决方案--------------------

就是对GridView进行列操作啊,可以用代码隐藏/删除列,再下载...