简体   繁体   English

无法获得内部HTML

[英]Cannot get inner HTML

I ran into the error: Cannot get inner content of ExportDiv because the contents are not literal I did a search and got this very useful resource! 我遇到了错误: 无法获取ExportDiv的内部内容,因为内容不是文字我做了搜索并得到了这个非常有用的资源!

I know I used server controls in my aspx page. 我知道我在aspx页面中使用了服务器控件。 The page fetches data dynamically from the database. 该页面从数据库中动态获取数据。 How can I export this data to excel given that there're server controls in my html page. 如果我的html页面中有服务器控件,如何将此数据导出到excel。

Here're some of the site.aspx code to the page 这是页面的一些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>

And here's also the site.aspx.cs code 这里也是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();

All answers would be welcomed! 欢迎所有答案!

It's been a while since I've done Server Controls, etc., but will this do the trick? 自从我完成服务器控件等以来已经有一段时间了,但是这样做会有什么作用吗?

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

I would suggest you to create a function that will convert your data into comma separated values and then render the same as CSV instead of excel format. 我建议你创建一个函数,将你的数据转换为逗号分隔值,然后渲染相同的CSV而不是excel格式。 Both CSV and excel format files would open the same way in excel. CSV和excel格式文件在excel中都会以相同的方式打开。

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

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