在运行时设计报告

发布于 2024-12-02 22:40:05 字数 683 浏览 2 评论 0原文

我正在开发一个 Windows 窗体应用程序,它有几个包含使用 vb.net 的 datagridviews 的窗口。客户最近提出了能够打印每个表的数据的愿望。

几个月前,我使用 Crystal Reports 成功设计并实现了我的第一份报告,我的第一反应是使用 Crystal Reports 来完成此任务。但是,因为我已经确切地知道我想要在第一份报告中呈现哪些列和数据,所以我可以在设计报告时考虑到这一点,所以这没有问题。

现在,挑战是我事先不知道要在报告中打印的确切列数,所以我担心我必须以编程方式设计报告,所以我的问题是;

  1. 是否有任何方法可以以编程方式设计报告?例如,我可以仅使用代码告诉水晶报表在详细信息部分中放置一个“表对象”,然后放置一个名为 X 的列和另一个名为 Y 的列吗?如果可能的话,有人可以向我指出一些关于如何执行此操作或类似操作的示例代码吗?

  2. 如果 1 在水晶报表中不可能,有人可以向我指出一些其他可以实现 1 的报表软件吗?如果可能的话,如何实现?

  3. 我是否合理地处理问题,或者是否有更好、更简单的方法可以实现客户的愿望?

顺便说一句,我已经提供了将表格导出到 Excel 的可能性,客户可以根据需要打印它们,但他们似乎更喜欢带有徽标和其他内容的更精美的报告,就像在水晶报告中可以实现的那样。

对于实现此功能的任何帮助,我将非常感激。

i am developing a windows forms application which has several windows containing datagridviews using vb.net. The client just recently came up with the desire to be able to print the data of each of these tables.

Having succesfully designed and implemented my first report using Crystal reports a few months ago, my first instinct was to do this using crystal reports. However, because I already knew exactly which columns and data I wanted to present in my first report, I could design the report taking this into account, so this was no problem.

Now, the challenge is that I do not know the exact number of columns to be printed in the report before hand, so I'm afraid I'd have to design the report programmatically, so my questions are;

  1. Is there any means of desgining a report programmatically? For example, can I, using only code, tell crystal reports to put a "table object" in the details section, then put a column named X, and another named Y? If possible, can someone point me to some sample code on how to do this or something similar?

  2. If 1 is not possible in crystal reports, can someone point me to some other reporting software in which I could achieve 1, and if possible, how?

  3. Am I approaching the problem reasonably or is there a much better and easier way in which I could achieve the clients desires?

By the way, I already provided the possibility to export the tables to excel, from which the client could print them as they wish, but it would appear they prefer fancier looking reports with logos and stuff as one could achieve in crystal reports.

I'll be extremely grateful with any help in implementing this functionality.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

牵你手 2024-12-09 22:40:05

你有两种方法可以做到这一点,一种是困难的,另一种是简单的。首先让我们把最困难的部分解决掉。 CR 拥有功能齐全的库,可让您几乎从头开始创建报告。它称为 RAS 库。但这非常复杂,对于刚接触 Crystal 的人来说并不是最好的选择。

下一个解决方案(也是最简单的)是创建一个包含您可能需要的所有可能字段的报告,然后使用 ReportObject 模型动态隐藏您不需要显示的字段。因此,如果您的报告中有 5 到 10 列,请在报告中创建所有 10 列。然后在您的应用程序中,如果您不需要第 10 列,请将其隐藏。像这样的东西:

CrystalDecisions.CrystalReports.Engine.ReportDocument myReport;
myReport.Load("..your file...");
CrystalDecisions.CrystalReports.Engine.TextObject myField;
myField =(CrystalDecisions.CrystalReports.Engine.TextObject)HealthRounds.ReportDefinition.ReportObjects["Field10"];
myField.ObjectFormat.EnableSuppress = true;
...

You have two ways of doing this, one is hard the other easy. First let's get the hard one out of the way. CR has a fully functional library which lets you create reports almost from scratch. It's called the RAS library. But it's very complex and not the best thing for someone new to Crystal to undertake.

The next solution, and the easiest, is to create a report that has all the possible fields you could ever need and then use the ReportObject model to dynamically hide the fields you don't need to show. Thus, if you could have between 5 to 10 columns on your report, create all ten of them in the report. Then in your app, if you don't need the 10th column, hide it. Something like this:

CrystalDecisions.CrystalReports.Engine.ReportDocument myReport;
myReport.Load("..your file...");
CrystalDecisions.CrystalReports.Engine.TextObject myField;
myField =(CrystalDecisions.CrystalReports.Engine.TextObject)HealthRounds.ReportDefinition.ReportObjects["Field10"];
myField.ObjectFormat.EnableSuppress = true;
...
我纯我任性 2024-12-09 22:40:05

如果您需要真正动态且可能更简单,请查看 list &标签
您需要做的事情的示例看起来有些简单:

Proj.Open( @“c:\Reports\artikel.lst” ,  LlDomFileMode .Create,
  LlDomAccessMode .ReadWrite, true );

ObjectReportContainer container= new
  ObjectReportContainer (Proj.Objects);

container.Position.Left = “0” ;
container.Position.Top = “0” ;
container.Position.Width = “150000” ;
container.Position.Height = “200000” ;

SubItemTable table = new SubItemTable
  (container.SubItems);
table.TableID = “Customers” ;

TableLineData dataLineNew = new
  TableLineData (table.Lines.Data);
dataLineNew.Name = “Created dynamically” ;

TableFieldText textCol = new
  TableFieldText (dataLineNew.Fields);
textCol.Contents = “Product.No” ;

TableFieldBarcode barcodeCol = new
  TableFieldBarcode (dataLineNew.Fields);
barcodeCol.Contents = “Barcode(Product.No, ‘PDF417’)” ;

Proj.Save();
Proj.Close (); 

更多详细信息在这里.. .

您至少需要“专业版”-版本才能使用此功能。
我用这个成熟的软件做了一些不错的程序。

if you need it really dynamical and perhaps easier, take a look into list & label.
the sample of what you need to do looks somewhat easy:

Proj.Open( @“c:\Reports\artikel.lst” ,  LlDomFileMode .Create,
  LlDomAccessMode .ReadWrite, true );

ObjectReportContainer container= new
  ObjectReportContainer (Proj.Objects);

container.Position.Left = “0” ;
container.Position.Top = “0” ;
container.Position.Width = “150000” ;
container.Position.Height = “200000” ;

SubItemTable table = new SubItemTable
  (container.SubItems);
table.TableID = “Customers” ;

TableLineData dataLineNew = new
  TableLineData (table.Lines.Data);
dataLineNew.Name = “Created dynamically” ;

TableFieldText textCol = new
  TableFieldText (dataLineNew.Fields);
textCol.Contents = “Product.No” ;

TableFieldBarcode barcodeCol = new
  TableFieldBarcode (dataLineNew.Fields);
barcodeCol.Contents = “Barcode(Product.No, ‘PDF417’)” ;

Proj.Save();
Proj.Close (); 

More Details here...

You need at least the "Professional"-Edition to use this feature.
i've done some nice programs with this mature software.

瑾夏年华 2024-12-09 22:40:05

这很容易做到,我只是想告诉您执行该操作的新方法,流程如下:

  1. 将要显示的数据放入适配器并将适配器数据放入数据集
  2. 在计算机驱动程序中生成 file.html 代码让 c
  3. 填充根据数据集中的单元格和数据集的标题将数据集中的数据发送到该文件,该数据集是动态列,
  4. 在用数据填充文件后要显示打开html文件

浏览器具有从文件打印预览打印页面内容的功能
这是动态报告,只需从 SQL 查询中获取所需的数据

This is very easy to do I just want to tell you for new methods to do that flow this steps:

  1. put your data that want to display to adapter and put adapter data to dataset
  2. generate file.html code in your computer driver let c
  3. populate the data which in dataset to that file according to cell that in dataset and header for dataset that is dynamic column which want to display
  4. after you populate the file with data open the html file

The browser have functionality to print the page content from file-print preview
this is dynamic report just get your data you want from SQL query

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文