简体   繁体   English

C#以编程方式创建报告

[英]C# create report programmatically

I want to create a report, using either Crystal reports or RDLC, doesn't really matter which. 我想使用Crystal报表或RDLC来创建报表,哪一个都不重要。 I can get all the data sources together as a series of dynamically generated textboxes etc, but how do I add that to a report? 我可以将所有数据源收集为一系列动态生成的文本框等,但是如何将其添加到报表中呢?

Eg I want customer name and all of their ordered items in a report. 例如,我想在报告中提供客户名称及其所有订购商品。 Now I can get all of the information in an array... how would I then place that into a Crystal Report? 现在,我可以将所有信息存储在一个数组中……然后如何将其放入Crystal Report中?

Any good introductions that cover non-wizards for Crystal Reports would be amazing. 任何涵盖Crystal Reports非向导的良好介绍都将是惊人的。

Every datasource of your report has a name (menu report->datasources, It can be not exact because my vs is not in English). 报告的每个数据源都有一个名称(菜单report-> datasources,由于我的vs不是英语,所以可能不准确)。

Supose that one of your datasources name is prj_folder_classSample, and classSample is a class of your project. 假设您的数据源名称之一是prj_folder_classSample,而classSample是您的项目的类。 Then you need to add a List to the report. 然后,您需要在报告中添加一个列表。

Let's do it. 我们开始做吧。

List<classSanple> lst = new List<classSample>
lst.Add(...) //Add various instances of classSample
BindingSource thisIsABindingSource = new BindingSource();
thisIsABindingSource.DataSource = lst;
reportDataSource rds = new ReportDataSource("prj_folder_classSample", thisIsABindingSource);

ReportViewer1.ProcessingMode = ProcessingMode.Local;
ReportViewer1.LocalReport.EnableExternalImages = true;
ReportViewer1.LocalReport.ReportEmbeddedResource = "YourProject.Folder.reportName.rdlc";
ReportViewer1.LocalReport.DataSources.Add(rds)

I do it in this way. 我是这样做的。 Hope It helps you. 希望对您有帮助。

Look at this link http://msdn.microsoft.com/en-us/library/cc281022.aspx#RDCE if you want to dynamically change your report. 如果要动态更改报告,请查看此链接http://msdn.microsoft.com/zh-cn/library/cc281022.aspx#RDCE This extension is called just before the report is rendered. 此扩展名在报表呈现之前被调用。 Microsoft has created a RDL Object Model. Microsoft已创建一个RDL对象模型。 With this one you can customize your whole report. 有了这个,您可以自定义整个报告。 But maybe you don't need this extension. 但也许您不需要此扩展。 Just try first your stuff in the Report Designer. 只需先在报表设计器中尝试一下即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM