如何在循环中生成报告并将其发送到单个pdf [英] How to generate reports in a loop and send it to single pdf

查看:77
本文介绍了如何在循环中生成报告并将其发送到单个pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试逐个生成10个报告,从数据库中获取数据,然后尝试将所有数据合并到一个输出pdf中。我有a.rdlc形式的设计。这是我的C#代码:

I am trying to generate 10 reports one by one taking data from database and then trying to merge all into one output pdf. I have a design in a.rdlc form. Here is my C# code:

var db = Database.Open("dbConnection");
    var data = db.QuerySingle("select name from customer_table where id = 2");            
  


    Microsoft.Reporting.WebForms.ReportViewer RptVr = new   Microsoft.Reporting.WebForms.ReportViewer();
    
        RptVr.LocalReport.ReportPath = "~/report/a.rdlc";
    
    RptVr.LocalReport.EnableExternalImages = true;

    Microsoft.Reporting.WebForms.ReportParameter[] x = new Microsoft.Reporting.WebForms.ReportParameter[1];
  
    var fname = "";
    
        fname = "inline; filename=reportCard" + a + ".pdf";
    x[0] = new Microsoft.Reporting.WebForms.ReportParameter("Name", data.name);  




    RptVr.LocalReport.SetParameters(x);
    string deviceInfo =
     "<DeviceInfo>" +
     "  <OutputFormat>EMF</OutputFormat>" +
     "  <PageWidth>11in</PageWidth>" +
     "  <PageHeight>8.5in</PageHeight>" +
     "  <MarginTop>0in</MarginTop>" +
     "  <MarginLeft>0in</MarginLeft>" +
     "  <MarginRight>0in</MarginRight>" +
     "  <MarginBottom>0in</MarginBottom>" +
     "</DeviceInfo>";

    Byte[] results =  RptVr.LocalReport.Render("PDF", deviceInfo);
 

    Response.ContentType = "Application/pdf";
    Response.AddHeader("content-disposition", fname);
    Response.OutputStream.Write(results, 0, results.Length);









这是有效但当我尝试循环如下时,我知道有什么不对。我试图在循环中生成报告并获得一个pdf输出文件。







this is working but when i try to loop like below, i know there is something wrong. I tried to generate the report in a loop and get one pdf output file.

var db = Database.Open("dbConnection");
    var data = db.Query("select name from customer_table");            
  
 for(i = 0; i<data.length;i++)
{

    Microsoft.Reporting.WebForms.ReportViewer RptVr = new   Microsoft.Reporting.WebForms.ReportViewer();
    
        RptVr.LocalReport.ReportPath = "~/report/a.rdlc";
    
    RptVr.LocalReport.EnableExternalImages = true;

    Microsoft.Reporting.WebForms.ReportParameter[] x = new Microsoft.Reporting.WebForms.ReportParameter[1];
  
    var fname = "";
    
        fname = "inline; filename=reportCard" + a + ".pdf";
    x[0] = new Microsoft.Reporting.WebForms.ReportParameter("Name", data.name);  




    RptVr.LocalReport.SetParameters(x);
    string deviceInfo =
     "<DeviceInfo>" +
     "  <OutputFormat>EMF</OutputFormat>" +
     "  <PageWidth>11in</PageWidth>" +
     "  <PageHeight>8.5in</PageHeight>" +
     "  <MarginTop>0in</MarginTop>" +
     "  <MarginLeft>0in</MarginLeft>" +
     "  <MarginRight>0in</MarginRight>" +
     "  <MarginBottom>0in</MarginBottom>" +
     "</DeviceInfo>";

    Byte[] results =  RptVr.LocalReport.Render("PDF", deviceInfo);


    Response.ContentType = "Application/pdf";
    Response.AddHeader("content-disposition", fname);
    Response.OutputStream.Write(results, 0, results.Length);
i++;
}





请帮我怎么做。



我尝试了什么:



我试图在循环中逐个动态生成报告并尝试将其放在一个pdf中file



Please help how do i do that.

What I have tried:

I tried to generate reports dynamically one by one in a loop and try to put that in one pdf file

推荐答案

一种解决方案是创建一个包含子报告的大型报告,然后打印大报告。



因此,基本上每个现有报告都将成为主报告的子报告。



您必须为主报告创建一个RDLC文件并添加每个子报告。如果可以重复相同的子报告,则可能需要循环子报告。



您必须向每个子报告发送适当的参数。而且你还必须正确调整布局以获得所需的最终结果。



毕竟,这是很多工作......我没有任何工作代码 因为它不是微不足道的,我无法访问我已经完成的代码。
One solution is to create a big report with subreports then print the big report.

So essentially each of you existing report would become a subreport of the main report.

You will have to create one RDLC file for the main report and add each subreport. You might need to "loop" subreport if same subreport can be repeated.

You will have to "send" appropriate parameters to each subreport. And you also have to properly adjust the layout to get the desired final result.

After all, it is a lot of work... I don't have any code as it is not trivial and I do not have access to code I have done.


这篇关于如何在循环中生成报告并将其发送到单个pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆