SAP BO报表数据导出

来源:互联网 发布:甩棍和匕首 知乎 编辑:程序博客网 时间:2024/05/06 01:23

Check if the document has been refreshed

If there are mandatory prompts that are not answered, setPrompts() will not refresh document. If so we print error message.

if (doc.getMustFillPrompts()) { System.out.println("ERROR: Mandatory prompts has not been entered"); }

Also it is possible that there are multiple contexts and one need to be selected in order to run the document. In most cases the documents are designed to avoid prompting about contexts, so here we assume that there is no need to select one. But just in case, we check this also.

if (doc.getMustFillContexts()) { System.out.println("ERROR: Context has not been selected"); }

Export to PDF

We can export complete document, a report of the document, or data providers.

For instance to export the document to PDF, we can get view in the PDF format and write the contents to a file.

BinaryView binaryView2 = (BinaryView)doc.getView(OutputFormatType.PDF); String title = infoObject.getTitle(); writeBytes(binaryView2.getContent(), title + ".pdf");

Here we use an auxiliary function that writes byte array to a file.

public static void writeBytes(byte[] data, String filename) throws IOException { File file = newFile(filename); FileOutputStream fstream = new FileOutputStream(file); fstream.write(data); fstream.close(); }

Exp