当前位置:  开发笔记 > 编程语言 > 正文

从Repeater导出到Excel?

如何解决《从Repeater导出到Excel?》经验,为你挑选了1个好方法。

现在我用它来导出转发器(带有多个嵌套转发器)excel:

protected void ExportToExcel(object sender, EventArgs e) 
{     
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=finance.xls");
Response.Charset = ""; 
Response.ContentType = "application/vnd.ms-excel"; 
System.IO.StringWriter stringWrite = new System.IO.StringWriter(); 
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); 
rptMinistry.RenderControl(htmlWrite); 
Response.Write(stringWrite.ToString()); 
Response.End(); 
}

但这不是我想要的.相反,它在excel文件中给我html(虽然数据在那里)这是我得到的(每行是excel表中的一个单元格):


 LOR In Development
 MOD
 Air Force
 
 Hellfire (AGM-114) Follow On
 10-Mar-08
 $50,000,000.00
 $0.00



 LOR In Development
 MOD
 Air Force
 
 Precision Strike Mi-17 (block 20)
 17-May-08
 $20,100,000.00
 $0.00

等等...现在数据是正确的,但我怎样才能让它在电子表格中正确显示?



1> Spencer Rupo..:

您需要将所有这些都包含在表标记中.Excel可以理解HTML表结构.

尝试:

Response.Write("");
Response.Write(stringWrite.ToString()); 
Response.Write("
");

推荐阅读
mobiledu2402851173
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有