繁体   English   中英

无法获得内部HTML

[英]Cannot get inner HTML

我遇到了错误: 无法获取ExportDiv的内部内容,因为内容不是文字我做了搜索并得到了这个非常有用的资源!

我知道我在aspx页面中使用了服务器控件。 该页面从数据库中动态获取数据。 如果我的html页面中有服务器控件,如何将此数据导出到excel。

这是页面的一些site.aspx代码

    <form id="form1" runat="server">
    <div runat="server" id="ExportDiv">
        <asp:Panel ID="ResultsPanel" runat="server">
        <table cellpadding="0" class="style1">
            <tr>
                <td class="style2">
                    <asp:DetailsView ID="DetailsView1" runat="server" CellPadding="4" 
                    </asp:DetailsView>
                </td>
                <td>
                    Poor</td>
                <td>
                    Good</td>
                <td class="style3">
                    Very Good</td>
                <td>
                    Total Responses</td>
                <td>
                    Average Score</td>
            </tr>
            <tr>
                <td class="style2" colspan="6" bgcolor="#CCCCCC">
                    1. How would you rate the food served to you?</td>
            </tr>
            <tr>
                <td class="style2">
                    &nbsp; &nbsp;a.) Overall Quality Taste and Flavour.<br />
                    &nbsp; &nbsp;b.) Variety of Food.</td>
                <td>
                    <asp:Label ID="lblResult0" runat="server" Text="Label"></asp:Label><br/>
                    <asp:Label ID="lblResult3" runat="server" Text="Label"></asp:Label>
                </td>
                <td>
                    <asp:Label ID="lblResult1" runat="server" Text="Label"></asp:Label><br/>
                    <asp:Label ID="lblResult4" runat="server" Text="Label"></asp:Label>
                </td>
                <td class="style3">
                    <asp:Label ID="lblResult2" runat="server" Text="Label"></asp:Label><br/>
                    <asp:Label ID="lblResult5" runat="server" Text="Label"></asp:Label>
                </td>
                <td>
                    <asp:Label ID="aveNum0" runat="server" Text="Label"></asp:Label>
                    <br/>
                    <asp:Label ID="aveNum1" runat="server" Text="Label"></asp:Label>
                    <br/>
                </td>
                <td>
                    <asp:Label ID="aveScore0" runat="server" Text="Label" style="font-weight: 700"></asp:Label>
                    <br />
                    <asp:Label ID="aveScore1" runat="server" Text="Label" style="font-weight: 700"></asp:Label>
                    <br/>
                </td>
            </tr>
           </table>
        </asp:Panel>


    </div>
                    <asp:GridView ID="gvSurveyResult" runat="server">
    </asp:GridView>
    <asp:GridView ID="GridView1" runat="server">
    </asp:GridView>
    </form>
</body>

这里也是site.aspx.cs代码

    Response.AppendHeader("content-disposition", "attachment;filename=ExportedHtml.xls");
    Response.Charset = "";
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.ContentType = "application/vnd.ms-excel";
    this.EnableViewState = false;
    Response.Write(ExportDiv.InnerHtml);
    Response.End();

欢迎所有答案!

自从我完成服务器控件等以来已经有一段时间了,但是这样做会有什么作用吗?

http://harouny.com/2012/10/15/render-asp-net-controls-user-controls-to-html-by-code/

我建议你创建一个函数,将你的数据转换为逗号分隔值,然后渲染相同的CSV而不是excel格式。 CSV和excel格式文件在excel中都会以相同的方式打开。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM