输出流导出Excel的方法和asp.net过滤html,急!!!!!!!!!!!!!!!

angellan 2008-09-23 11:17:27
输出流导出Excel的方法和asp.net过滤html
private void Export(string FileType, string FileName)
{
Response.Charset = "GB2312";
//Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AppendHeader("name","hao");
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
System.IO.StringWriter tw = new System.IO.StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
DataTable dt = new DataTable();
dt = NewMethod();
this.GridView1.RenderControl(hw);//这里如何换成dataTable

Response.Write(NoHTML(tw.ToString()));
Response.End();

}
...全文
193 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
zincy 2008-10-16
  • 打赏
  • 举报
回复
mark
lovehongyun 2008-09-23
  • 打赏
  • 举报
回复
可以借助DataGrid或GridView的RenderControl方法输出

private void Export(string FileType, string FileName) 
{
GridView gv= new GridView();
DataTable dt = NewMethod();
this.gv.DataSource = dt;
this.gv.DataBind();

Response.Charset = "GB2312";
//Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AppendHeader("name","hao");
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
System.IO.StringWriter tw = new System.IO.StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
gv.RenderControl(hw);//这里如何换成dataTable

Response.Write(NoHTML(tw.ToString()));
Response.End();

}
wolfsky1994 2008-09-23
  • 打赏
  • 举报
回复
TempContent = System.Text.RegularExpressions.Regex.Replace(TempContent,"<[^>]*>","");
wihtsky 2008-09-23
  • 打赏
  • 举报
回复

DataTable dt = new DataTable();
dt.Columns.Add("你需要的列");
dt.Columns.Add("你需要的列");
dt.Columns.Add("你需要的列");
dt.Columns.Add("你需要的列");
//循环遍历 添加
for (int i = 0; i < 给出条件; i++)
{
DataRow drow = dtContent.NewRow();
drow["你上面填写的列"] = 赋值;
drow["你上面填写的列"] = 赋值;
drow["你上面填写的列"] = 赋值;
drow["你上面填写的列"] = 赋值;
dtContent.Rows.Add(drow);
}
yegreen 2008-09-23
  • 打赏
  • 举报
回复
你是先读出来,然后再写入, 推荐你边读边写, 速度提高不知道多少倍.
onionandbaobao 2008-09-23
  • 打赏
  • 举报
回复
最好以gridview的形式导出来,比较清楚
shulei521 2008-09-23
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 lovehongyun 的回复:]
可以借助DataGrid或GridView的RenderControl方法输出


C# codeprivate void Export(string FileType, string FileName)
{
GridView gv= new GridView();
DataTable dt = NewMethod();
this.gv.DataSource = dt;
this.gv.DataBind();

Response.Charset = "GB2312";
//Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AppendHe…
[/Quote]
楼上的 是男是女呢

62,073

社区成员

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

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

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

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