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

关于GridView导出Excel的问题!
GridView导出Excel的方法已经搞定了.

但有个问题,就是在GridView前、后有标题、说明(不止一两行的),还有打印按钮、导出按钮、DropdownList等,这些如果在导出方法里使用整个页面导出Excel是可以,但影响了美观和使用(按钮、DropdownList不需要)。

1、如何不导出按钮、DropdownList呢?
2、或者纯导出GridView的内容,再在Excel动态的加入这些标题和说明。

希望能给个代码例子示例。谢谢你们。

------解决方案--------------------
Gridview中的内容导出到Excel:
protected void Button1_Click(object sender, EventArgs e)
{
Response.Clear();
 Response.AddHeader( "content-disposition ", "attachment;filename=FileName.xls ");
 Response.Charset = "gb2312 ";
 Response.ContentType = "application/vnd.xls ";
 System.IO.StringWriter stringWrite = new System.IO.StringWriter();
 System.Web.UI.HtmlTextWriter htmlWrite =new HtmlTextWriter(stringWrite);

 GridView1.AllowPaging = false;
 BindData();
 GridView1.RenderControl(htmlWrite);

 Response.Write(stringWrite.ToString());
 Response.End();
 GridView1.AllowPaging = true;
 BindData();
}
要想打印其他的(例如GridView1的标题拦)我也不会,希望有人会告诉我啊!
yangji1980@163.com
谢谢了啊!