导出到Excel从中继? [英] Export to Excel from a Repeater?

查看:89
本文介绍了导出到Excel从中继?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我用这个导出一个中继器(具有多重嵌套中继器)创先争优:

Right now I am using this to export a repeater (with multiple nested repeaters) to 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(); 
}

但是,这是不是在做我想要的。相反,它是HTML给我的Excel文件(虽然数据是存在的),这是我所得到的(每一行是在Excel工作表的单元格):

But this is not doing what I want. Instead it is giving me html in the excel file (though the data is there) this is what I get (each line is a cell in the excel sheet):

<tr class="alt">
 <td class='hidden'>LOR In Development</td>
 <td>MOD</td>
 <td>Air Force</td>
 <td class="size1"></td>
 <td>Hellfire (AGM-114) Follow On</td>
 <td>10-Mar-08</td>
 <td class="align_right ">$50,000,000.00</td>
 <td class="align_right hidden">$0.00</td>
</tr>

<tr class="alt">
 <td class='hidden'>LOR In Development</td>
 <td>MOD</td>
 <td>Air Force</td>
 <td class="size1"></td>
 <td>Precision Strike Mi-17 (block 20)</td>
 <td>17-May-08</td>
 <td class="align_right ">$20,100,000.00</td>
 <td class="align_right hidden">$0.00</td>
</tr>

等等...现在的数据是正确的,但我怎么才能得到它在S preadsheet正确显示?

and so on... now the data is correct, but how can I get it to show up correctly in the spreadsheet?

推荐答案

您需要附上所有的表标签。 Excel可以理解HTML表结构。

You need to enclose all of that in table tags. Excel can understand HTML table structures.

尝试:

Response.Write("<table>");
Response.Write(stringWrite.ToString()); 
Response.Write("</table>");

这篇关于导出到Excel从中继?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆