ASP.NET导出Excel文件问题,导出后表里没内容

Cerulean_ZC 2006-06-08 05:57:36
我用以下方法做的导出,为什么导出的Excel文件没有内容?谢谢大家帮个忙
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Buffer= true;
HttpContext.Current.Response.Charset="utf-8";

HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename=会员消费汇总表.xls");
HttpContext.Current.Response.ContentEncoding=System.Text.Encoding.Default;

HttpContext.Current.Response.ContentType = "application/ms-excel";
this.EnableViewState = false;

System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);

this.rpResult.RenderControl(oHtmlTextWriter);

HttpContext.Current.Response.Write(oStringWriter.ToString());
HttpContext.Current.Response.End();
...全文
301 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
HELLO_JIM 2007-04-03
  • 打赏
  • 举报
回复
學習中.............
nnh 2006-06-09
  • 打赏
  • 举报
回复
Sub ExportToExcel_Click(s as object, e as eventargs)
'-------------------
MyDataGrid.AllowPaging = "false"
BindGrid()
'-------------------

Response.Clear
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls")
Response.Charset = ""
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.ContentType = "application/vnd.xls"
Dim stringWrite As System.IO.StringWriter = New System.IO.StringWriter
Dim htmlWrite As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringWrite)
MyDataGrid.RenderControl(htmlWrite)
Response.Write(stringWrite.ToString)
Response.End

'-------------------
MyDataGrid.AllowPaging = "true"
BindGrid()
'-------------------
End Sub
lovechenlila 2006-06-09
  • 打赏
  • 举报
回复
我也做好了,我做的就是导出时不能导中文字体
duyhui 2006-06-09
  • 打赏
  • 举报
回复
rpResult控件里没有内容吧?
ChengKing 2006-06-08
  • 打赏
  • 举报
回复
这样导出不是最正确的方式,请参考:
http://blog.csdn.net/ChengKing/archive/2005/11/29/539514.aspx

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧