我跑進了錯誤:無法獲取ExportDiv內的內容,因爲內容不是文字我做了搜索,得到這個非常useful resource!無法獲取內部HTML
我知道我使用的服務器控件在我的aspx頁面。頁面從數據庫中動態獲取數據。如何將這些數據導出爲excel,因爲我的html頁面中有服務器控件。
我這裏還有一些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">
a.) Overall Quality Taste and Flavour.<br />
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();
將受到歡迎所有的答案!
您是否使用查詢字符串來確定您正在查看哪些數據記錄?如果是這樣,你可以使用HttpWebRequest和HttpWebResponse獲取頁面的HTML,然後解析這個,但是你喜歡 – jgok222