【发布时间】:2012-08-01 19:40:41
【问题描述】:
.net 中的报表查看器具有出色的内置导出功能,支持不同的导出格式,如 word、pdf 和 excel。但是,对于我的 asp 应用程序中的管理人员,我希望此导出功能能够生成包含多个 rdlc 报告的单个导出文件,以便他们可以浮动单个文档并继续喝咖啡!。需要导出的报表是根据一些业务逻辑动态决定的。
我在论坛上找到了一个有用的代码 sn-p 来实现这一点,看起来不错:
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();
}
此代码符合要求,但使用此代码导出的文件在打开 word 文档时仍仅显示 1 个报告,即使较大的文件大小表明数据可能也在其中用于其他报告。
有人可以指出可能是什么问题吗?如果它可以从多个 rdlc 报告中生成单个单词文件导出,我也愿意接受有关使用完全不同方法的建议。
【问题讨论】:
标签: c# asp.net .net rdlc export-to-word