2012-08-01 60 views
0

.net中的報告查看器具有出色的內置導出功能,支持word,pdf和excel等不同的導出格式。對於我的asp應用程序中的管理員,我想要這個導出功能生成一個包含多個rdlc報告的導出文件,這樣他們可以浮動一個文檔並保持喝咖啡!需要導出的報告根據某些業務邏輯動態決定。
我發現了一個有用的代碼片斷在一個論壇來實現這個看起來不錯:將多個rdlc報告導出爲單個單詞文檔

protected void ExportReportsToWord(object Sender, EventArgs e) 
    { 
     // Variables 
     Warning[] warnings; 
     string[] streamIds; 
     string mimeType = string.Empty; 
     string encoding = string.Empty; 
     string extension = string.Empty; 

     // reportViewer1 and reportViewer2 are reports on my asp.net page 
     byte[] bytes1 = reportViewer1.LocalReport.Render("WORD", null, out mimeType, out encoding, out extension, out streamIds, out warnings); 
     byte[] bytes2 = reportViewer2.LocalReport.Render("WORD", null, out mimeType, out encoding, out extension, out streamIds, out warnings); 

     //create a single byte array out of multiple arrays 
     byte[] bytes = (bytes2.Concat(bytes1)).ToArray(); 

     // Now that you have all the bytes representing the Word report, buffer it and send it to the client. 
     Response.Buffer = true; 
     Response.Clear(); 
     Response.ContentType = mimeType; 
     Response.AddHeader("content-disposition", "attachment; filename=" + "singleReport" + "." + extension); 
     Response.BinaryWrite(bytes); // create the file 
     Response.Flush(); // send it to the client to download 
     Response.End(); 

    } 

此代碼符合很好,但與此代碼導出的文件仍然showup僅1時開放word文檔報告,甚至儘管更大的文件大小表明數據可能也在其他報告中。
有人可以指出可能是什麼問題?如果能夠從多個rdlc報告中生成單個文件導出,我也樂意使用完全不同的方法。

回答

1

一個簡單的解決方案是創建一個大的主報告。

在每個元素的子報表中都有列表。

將參數傳遞給主報告以決定顯示哪些報告以及要隱藏哪些報告。

這樣,用戶可以選擇他想要查看的報告,並獲得SSRS爲標準報告提供的所有功能。

+0

看起來有趣,你能給我提供一些鏈接/教程嗎?我只是想知道隱藏報告是否仍然需要時間才能創建,或者只會被SSRS忽略。 – learner 2012-08-01 19:55:50

+1

我沒有任何處理時間的基準。但看看這個樣本的子報告:http://www.codeproject.com/Articles/195017/SSRS-Series-Part-II-Working-with-Subreports-DrillD – nunespascal 2012-08-01 20:06:08

1

嗨,我會建議你寧願有一個報告,然後包含所有這些報告作爲兒童報告,然後安排主要報告作爲電子郵件發送到您的老闆作爲word文檔。

相關問題