在系統中經常出現這樣的情況就是生成excel流 并將生成的excel 流傳給用戶
一般的來講可以利用 response 來向客戶端發送一個http頭 ,并將excel流發送出去就可以了,但會出現一個問題就是點擊打開的時候會出現兩次 文件下載 對話框,主要的原因:(現在的猜測,還沒有找到準確的原因)。
第一次打開 時 ,在系統中已經存在了excel流的臨時文件(就是文件,沒有文件的后綴名的存在) ,但沒有原來的(真實文件的存在),要求用戶是否將臨時文件保存到計算機其他的位置上。(是否跟沒有后綴名有關)
第二次 ,選擇客戶端文件的位置,是否保存到其他的非臨時文件夾位置。
現在的解決方案是
新建一個頁面專門提供導出數據的
在這個頁面中的page_load中寫這樣的代碼
private void page_load(object sender, system.eventargs e)
{
// 在此處放置用戶代碼以初始化頁面
reportrule reportrule=new reportrule();
byte[] result= reportrule.renderreport(httpcontext.current.server.urldecode(this.request.querystring["peportpath"]),request.querystring["id"]); //生成excel流
httpcontext.current.response.contenttype = "application/vnd.ms-excel";
httpcontext.current.response.appendheader("content-disposition","attachment;filename=hahh.xls");
httpcontext.current.response.binarywrite(result);
httpcontext.current.response.end();
}
新聞熱點
疑難解答