如何以文本形式运行和下载BusinessObjects报表

时间:2012-11-02 22:21:49

标签: java api sap business-intelligence business-objects

我的问题:如何运行报告并将其下载到文本?在BuessinessObjects中,您可以将报告下载为纯文本文件。他们的API文档表明您可以下载各种格式的报告。这是如何完成的?

如何以PDF格式下载:在their documentation中,它们描述了如何将它们下载为PDF文件:

ViewSupport pdfViewSupport = new ViewSupport();
pdfViewSupport.setOutputFormat(OutputFormatType.PDF);
pdfViewSupport.setViewType(ViewType.BINARY);
pdfViewSupport.setViewMode(ViewModeType.DOCUMENT);

RetrieveBinaryView retBinView = new RetrieveBinaryView();
retBinView.setViewSupport(pdfViewSupport);

RetrieveData retBOData = new RetrieveData();
retBOData.setRetrieveView(retBinView);

DocumentInformation docInfo = boReportEngine.getDocumentInformation(struid, null, null, null, retBOData);
BinaryView myBOView = (BinaryView) boDocInfo.getView();
byte[] docContents = myBOView.getContent();

当我改变时:

pdfViewSupport.setOutputFormat(OutputFormatType.PDF);
pdfViewSupport.setViewType(ViewType.BINARY);
pdfViewSupport.setViewMode(ViewModeType.DOCUMENT);

pdfViewSupport.setOutputFormat(OutputFormatType.INT_HTML);
pdfViewSupport.setViewType(ViewType.INT_CHARACTER);
pdfViewSupport.setViewMode(ViewModeType.INT_REPORT_PAGE);

我收到以下错误:

org.apache.axis2.AxisFault: Binary view of such a document should be only requested with the use of ViewType.BINARY (WRE 01151)

有趣的是我将ViewType设置为INT_CHARACTER,而不是BINARY ......

它打破了界限:

DocumentInformation docInfo = boReportEngine.getDocumentInformation(struid, null, null, null, retBOData);

我正在尝试做什么:这真的很复杂,但我基本上想要一个报告,它返回一行并在报告上打印(没有别的),然后下载报告为文本,因为文本是我在另一个程序中使用的xml。

任何帮助都会很棒!


注意:我在3.2服务器上运行,但我们很快就会升级到4.0。因此,如果解决方案可以适用于这两个版本,那就太棒了,否则v4和v3.x解决方案也会很棒:)

1 个答案:

答案 0 :(得分:1)

这一行的问题:

RetrieveBinaryView retBinView = new RetrieveBinaryView();

所以我不知道这一切是如何运作的,但这就是你要找的东西:

ViewSupport viewSupport = ViewSupport.Factory.newInstance();
viewSupport.setOutputFormat(OutputFormatType.INT_XML);
viewSupport.setViewType(ViewType.INT_CHARACTER);
viewSupport.setViewMode(ViewModeType.INT_REPORT_PAGE);

RetrieveData retBOData = RetrieveData.Factory.newInstance();

RetrieveXMLView retXMLView = RetrieveXMLView.Factory.newInstance();
retXMLView.setViewSupport(viewSupport);
retBOData.setRetrieveView(retXMLView);
DocumentInformation boDocInfo = getDocInfo(actions, retBOData);
XMLView bView = (XMLView) boDocInfo.getView();
ByteArrayOutputStream out = new ByteArrayOutputStream(bView.getContentLength());
bView.getContent().save(out);
byte[] reportBytes = out.toByteArray();
String reportInString = new String(reportBytes);

但是,这里的reportInString是表示报告的XML。所以我所做的是用前缀和后缀封装我想要的报告。所以,例如,假设我用@#$ThisIsWhatYouWant--End$#@封装它,然后我会执行以下操作:

Pattern patt = Pattern.compile("(?i)@#$ThisIsWhatYouWant-(.*?)-End$#@", Pattern.DOTALL);
Matcher match = patt.matcher(reportInString);
if (match.find()) {
  return match.group(1);
}
return null;

P.S。这应该适用于3.x和4.0 BO服务器。