标题:asp.net Gridview导出excel出错
取消只看楼主
lukebc
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:3
帖 子:74
专家分:32
注 册:2009-8-18
结帖率:71.43%
已结贴  问题点数:10 回复次数:0 
asp.net Gridview导出excel出错
这是我的代码
protected void Button1_Click(object sender, EventArgs e)
{
ExcelOut(this.GridView1);
}

public void ExcelOut(GridView gv)
{
if (gv.Rows.Count > 0)
{
Response.Clear();
Response.ClearContent();
Response.AddHeader("Content-Disposition", "attachment; filename=" + DateTime.Now.ToString("_yyyyMMdd_HHmmss") + ".xls");
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gv.RenderControl(htw);
Response.Write(sw.ToString());
Response.Flush();
Response.End();
}
else
{
Response.Write("没有数据");
}
}
但是出现这样的错误,不知道是哪出错了

搜索更多相关主题的帖子: public excel 
2016-11-06 19:48



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-470801-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023201 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved