简体   繁体   English

在不使用子报表的情况下以编程方式附加 Crystal Reports

[英]Programmatically append Crystal Reports without using subreports

My task is to create an "app" that will allow the following: given a list of Crystal Reports on the server, the user can select any number of them to combine into one long report (just appended together).我的任务是创建一个“应用程序”,它将允许以下内容:给定服务器上的 Crystal Reports 列表,用户可以选择任意数量的它们组合成一个长报告(只是附加在一起)。 They must be able to set the parameters for each report.他们必须能够为每个报告设置参数。

I've gathered that the usual method would be to generate a main report that includes all of the individual reports as subreports, but I don't believe this is an option here, because some of the individual reports may already contain their own subreports (and you can't have nested subreports).我收集到,通常的方法是生成一个主报告,其中包含所有单独的报告作为子报告,但我不认为这是一个选项,因为一些单独的报告可能已经包含它们自己的子报告(并且您不能有嵌套的子报表)。

The reports were created with Crystal Reports for Enterprise XI 4.0.这些报告是使用 Crystal Reports for Enterprise XI 4.0 创建的。 I'm trying to do this as a set of JSP pages using the BusinessObjects Java SDK.我正在尝试使用 BusinessObjects Java SDK 作为一组 JSP 页面来执行此操作。 Preferably the output type would be flexible, but if necessary, just generating a PDF would be acceptable.输出类型最好是灵活的,但如果有必要,只生成一个 PDF 是可以接受的。

What would be the best way to go about this?解决这个问题的最佳方法是什么?

UPDATE: I should also note that, when attempting to export a single report to PDF (I was considering just making PDFs of every report and then concatenating them somehow), the following code fails:更新:我还应该注意,当尝试将单个报告导出为 PDF 时(我正在考虑只制作每个报告的 PDF,然后以某种方式连接它们),以下代码失败:

// Get the ID of the current working report.
int reportID = Integer.parseInt(request.getParameter("ReportID"));

// Retrieve the BOE Session and InfoStore objects
IEnterpriseSession eSession = (IEnterpriseSession)session.getAttribute("EnterpriseSession");
IInfoStore iStore = (IInfoStore)eSession.getService("InfoStore",ServiceNames.OCA_I_IINFO_STORE);

// Query to get the report document
String infoStoreQuery = "select SI_NAME,SI_PARENTID from CI_INFOOBJECTS where SI_ID=" + reportID;
IInfoObjects infoObjects = iStore.query(infoStoreQuery);
IInfoObject report = (IInfoObject)infoObjects.get(0);

IReportAppFactory reportAppFactory = (IReportAppFactory)eSession.getService("RASReportFactory");
ReportClientDocument clientDoc = reportAppFactory.openDocument(report, OpenReportOptions._openAsReadOnly, java.util.Locale.CANADA);

//Use the report document's PrintOutputController to export the report to a ByteArrayInputStream
ByteArrayInputStream byteIS = (ByteArrayInputStream)clientDoc.getPrintOutputController().export(ReportExportFormat.PDF);
clientDoc.close();

//Create a byte[] that is the same size as the exported ByteArrayInputStream
byte[] buf = new byte[2000 * 1024];
int nRead = 0;
//Set response headers
response.reset();
response.setHeader("content-disposition", "inline;filename=untitled.pdf");
response.setContentType("application/pdf");
//Send the Byte Array to the Client
while ((nRead = byteIS.read(buf)) != -1) {
  response.getOutputStream().write(buf, 0, nRead);
}
//Flush the output stream
response.getOutputStream().flush();
//Close the output stream
response.getOutputStream().close();

On the "reportAppFactory.openDocument" line, with this error:在“reportAppFactory.openDocument”行上,出现以下错误:

javax.servlet.ServletException: com.crystaldecisions.sdk.occa.managedreports.ras.internal.ManagedRASException: Cannot open report document. --- This release does not support opening SAP Crystal Reports for Enterprise reports.

So if you don't have a better solution to the overall problem, I would still appreciate some help on even exporting one report to PDF.因此,如果您对整个问题没有更好的解决方案,即使将一份报告导出为 PDF,我仍然希望得到一些帮助。

I'll limit my answer to what seems to be the hardest part of your question - combining the output into one file.我会将我的答案限制在您问题中最难的部分——将输出合并到一个文件中。

What you're describing doesn't sound possible through Crystal Reports unless you create a 'master' report and append each report as a subreport.除非您创建“主”报告并将每个报告附加为子报告,否则您所描述的内容通过 Crystal Reports 听起来是不可能的。 This would indeed have the drawback you mention of losing any already embedded subreports.这确实具有您提到的丢失任何已经嵌入的子报告的缺点。

The reason it would be required to do it like this is due to the following properties of a Crystal Report:之所以需要这样做是由于 Crystal Report 的以下属性:

  1. a report can have a single datasource;一个报告可以有一个单一的数据源; different datasources must be encapsulated inside subreports不同的数据源必须封装在子报表中
  2. a report is made up of report-header, page-header, group-headers, details, group-footers, report-footer, page-footer - always in that order.报告由报告页眉、页眉、组页眉、详细信息、组页脚、报告页脚、页脚组成 - 始终按此顺序排列。

A report that consisted of appending multiple reports together would most likely break #1 (if they have different datasources), and would definitely break #2.由将多个报告附加在一起组成的报告很可能会破坏 #1(如果它们具有不同的数据源),并且肯定会破坏 #2。

Now, you're not without options - you can export reports to various formats, and programmatically append them in that exported format: MS Excel/Word, PDF, and manipulate them in that format.现在,您并非没有选择——您可以将报告导出为各种格式,并以编程方式将它们附加到导出的格式:MS Excel/Word、PDF,并以该格式操作它们。 There are a few free pdf writers that let you print out a single document to PDF (so you don't even need to rely on CR's export feature);有一些免费的 pdf 编写器可以让您将单个文档打印为 PDF(因此您甚至不需要依赖 CR 的导出功能); there are some tools that can merge multiple pdfs together try the options from this google search , or this SO answer .有一些工具可以将多个 pdf 合并在一起,试试这个谷歌搜索中的选项,或者这个 SO 答案

Edit - on the error you're getting ( This release does not support opening SAP Crystal Reports for Enterprise reports. ) - it sounds like you're trying to open a newer versioned report in an older SDK.编辑- 关于您收到的错误( This release does not support opening SAP Crystal Reports for Enterprise reports. ) - 听起来您正在尝试在旧版 SDK 中打开更新版本的报告。 Make sure the SDK you're using supports the version of reports you're trying to use it with (perhaps it was installed incorrectly, or there are multiple versions conflicting?)确保您使用的 SDK 支持您尝试使用它的报告版本(也许它安装不正确,或者有多个版本冲突?)

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

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