gridview控件中的内容导出至excel的问题
web窗体中有一个gridview控件ID=“TelephoneView”,我想吧其中的数据导入到excel中,代码如下:
protected void toExcel(object sender, EventArgs e) //导出搜索结果至excel
{ Response.ClearContent();
Response.AddHeader("content-disposition", "attachment;filename=MyExcel2.xls");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");//设置输出流为简体中文
Response.ContentType = "application/excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
TelephoneView.AllowPaging = false;
TelephoneView.DataBind();
TelephoneView.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
TelephoneView.AllowPaging = true;
}
public override void VerifyRenderingInServerForm(Control control)
{
}
但MyExcel2.xls中什么内容也没有只有一对<div></div>,请高手指点一下我的代码有问题吗?