![](/img/trans.png)
[英]Internet Explorer 11 Last Session and ASP.Net WebForm App
[英]Asp.Net Webform export to excel is not working in Internet Explorer
這是問題所在:我有一個報告,該報告是由一些中繼器生成的,並且生成的HTML是可以的。 生成報告后,我調用導出到excel的函數:
protected void ExportToExcel(Control control)
{
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=Relatorio.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
control.RenderControl(hw);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
}
問題:例如,使用Firefox訪問報告時,此功能有效,但在Internet Explorer中卻無法使用。 當在行Response.Output.Write(sw.ToString())處設置斷點時; 當調試sw.ToString()時,我發現它為空。
我使用此功能與其他報告相同,但可以在Internet Explorer中使用,而在此特定報告中則不能。 我一直在嘗試查找HTML錯誤,例如缺少結束標記,但到目前為止沒有找到任何錯誤。
你們經歷過這種情況了嗎? 您對我的代碼有什么建議?
在此先感謝您的幫助。
通常,您先寫一個stringbuilder,然后調用stringbuilder.tostring()
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter hw = new HtmlTextWriter(sw);
control.RenderControl(hw);
Response.Output.Write(sb.ToString());
解決了。 我檢查了所有的html,刪除了更新面板,即使excel導出也不起作用。 對我而言,解決此問題的方法是將占位符傳遞給函數,而不是中繼器。
我仍然不明白為什么通過占位符而不通過中繼器的確切原因,但是問題已解決。
感謝您的答復!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.