.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報告中生成單個文件導出,我也樂意使用完全不同的方法。
看起來有趣,你能給我提供一些鏈接/教程嗎?我只是想知道隱藏報告是否仍然需要時間才能創建,或者只會被SSRS忽略。 – learner 2012-08-01 19:55:50
我沒有任何處理時間的基準。但看看這個樣本的子報告:http://www.codeproject.com/Articles/195017/SSRS-Series-Part-II-Working-with-Subreports-DrillD – nunespascal 2012-08-01 20:06:08