gpt4 book ai didi

c# - 从 Repeater 导出到 Excel?

转载 作者:太空狗 更新时间:2023-10-29 21:00:34 26 4
gpt4 key购买 nike

现在我正在使用它来将中继器(具有多个嵌套中继器)导出到 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 工作表中的一个单元格):

<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>

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

最佳答案

您需要将所有这些包含在表格标签中。 Excel 可以理解 HTML 表格结构。

尝试:

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

关于c# - 从 Repeater 导出到 Excel?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/438184/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com