我需要将表格中占位符的内容导出到excel。当我简单地将占位符放在 div 中时,我可以将数据(表)导出到 excel 中。但是当我把它放在表格的 td 中时,我只能导出标题,但不能导出占位符的内容。
<asp:Panel ID="pnlMilestone" runat="server" CssClass="milestone-wrapper">
<div id="TableLists" runat="server" class="milestone-chart-wrapper">
<table>
<tr>
<td style="text-align: center;">
<asp:Label ID="lblChartTitle" runat="server" Visible="False" Font-Bold="True"></asp:Label>
</td>
</tr>
<tr>
<td>
<div runat="server" id="bartable_render">
<div id="bar_chart" style="height: 315px; width: 800px; margin-left: 150px;">
</div>
<div id="bar" style="height: 345px; width: 800px; margin-left: 10px;">
</div>
</div>
<asp:PlaceHolder ID="phDynamicTabular" runat="server"></asp:PlaceHolder>
</td>
</tr>
</table>
</div>
</asp:Panel>
出口代码:
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=ProjectTarget_" + CampaignID + ".xls");
Response.Charset = "";
Response.ContentType = "application/vnd.xls";
StringWriter stringWrite = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
TableLists.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();