C#Windows窗体中的ReportViewer呈现问题 [英] ReportViewer rendering problem in C# Windows Forms

查看:96
本文介绍了C#Windows窗体中的ReportViewer呈现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我要求自动将数据(包含1000行)导出为PDF文件。我们不应该使用像iTextSharp这样的第三方工具。所以我使用了Microsoft.Office.Interop.Word dll生成PDF文件,但导出1000行数据需要9分钟以上。



我更喜欢使用Microsoft.Reporting.WinForms。创建数据集,设计报告,并编写代码,但当我要将数据呈现给localreport时,我收到异常本地报告处理期间发生错误。在这行代码中





byte [] bytes = rv.LocalReport.Render(PDF, null,out mimeType,out encoding,out extension,out streamids,out warnings);



这是我的完整代码plz看看这个。



Hi,

I have a requirement to export the data(which is having the 1000 rows) into PDF file automatically. We are not supposed to use third party tools like iTextSharp. So I used the Microsoft.Office.Interop.Word dll to generate the PDF files but it is taking more than 9 mins to export 1000 rows of data.

I preferred to use Microsoft.Reporting.WinForms. Created Dataset, Designed the Report, and wrote the code but when I am going to render the data to localreport I am getting the exception "An error occurred during local report processing." at this line of code


byte[] bytes = rv.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamids, out warnings);

Here is my complete code plz look into this.

 LocalReport lr = new LocalReport();
                ReportViewer rv = new ReportViewer();
                
                DataSet1 expo = new DataSet1();
                ReportDataSource rds = new ReportDataSource();
                expo.Merge(fDS);
                rds.Name = "dataPointDS";
                rds.Value = expo.Tables["dataPointDS"];
                rv.LocalReport.DataSources.Clear();
                rv.ProcessingMode = ProcessingMode.Local;
                rv.LocalReport.ReportEmbeddedResource = rPath;
                rv.LocalReport.DataSources.Add(rds);
                rv.RefreshReport();
Warning[] warnings;
                string[] streamids;
                string mimeType = string.Empty;
                string encoding = string.Empty;
                string extension = string.Empty;
byte[] bytes = rv.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamids, out warnings);
                        FileStream fs = new FileStream(XLPath + "\\" + fileName.Replace("/", "_") + ".pdf", FileMode.Create, FileAccess.Write);
                        fs.Write(bytes, 0, bytes.Length);
                        fs.Close(); 







当我在Windows窗体上使用reportviewer控件时,它会显示数据。但是当我编写代码进行本地处理时,我得到了这个例外。



有些人可以帮忙吗。



提前致谢

Murali。




When I use reportviewer control on my windows form, it is showing the data. But when I wrote the code to process locally I am getting this exception.

Can some body help on this.

Thanks in advance
Murali.

推荐答案

找到解决方案。



对于Windows应用程序,我们必须使用流提供rdlc路径,然后只有报告查看器识别它。



必须使用流加载rdlc比
Found the solution for it.

For windows applications we have to provide the rdlc path using the streams then only report viewer recognize it.

Have to load the rdlc using stream rather than
rv.LocalReport.ReportEmbeddedResource = rPath;

Here is the working code

                LocalReport lr = new LocalReport();
                ReportViewer rv = new ReportViewer();
                DataSet1 expo = new DataSet1();
                ReportDataSource rds = new ReportDataSource();
                expo.Merge(fDS);
                rds.Name = "DataSet1";
                rds.Value = expo.Tables["dataPointDS"];
                rv.LocalReport.DataSources.Clear();
                rv.ProcessingMode = ProcessingMode.Local;                             
                using (StreamReader rdlcSR = new StreamReader(rPath))
                {
                    rv.LocalReport.LoadReportDefinition(rdlcSR);
                    rv.LocalReport.Refresh();
                }
                rv.LocalReport.DataSources.Add(rds);                           

                Warning[] warnings;
                string[] streamids;
                string mimeType = string.Empty;
                string encoding = string.Empty;
                string extension = string.Empty;
                byte[] bytes = rv.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension,  out streamids, out warnings);
                FileStream fs = new FileStream(XLPath + "\\" + fileName.Replace("/", "_") + ".pdf", FileMode.Create, FileAccess.Write);
                fs.Write(bytes, 0, bytes.Length);
                fs.Close();


优秀的样本!帮助了我很多!
EXCELLENT SAMPLE! HELPED ME A LOT!


需要帮助...我们可以从报告查看器中呈现html ..请尽快回复。
Need Help...Can we render html from report viewer..please reply as soon as possible.


这篇关于C#Windows窗体中的ReportViewer呈现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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