Tuesday, May 26, 2015

BI Publisher API Example – Creating EXCEL Report from XML/XSL-FO/RTF in Oracle Apps?













Oracle has shared us a set of BI Publisher Java Classes for performing various BI Publisher function like converting RTF to XSL-FO, generating PDF output from XSL-FO and XML etc.
In this post, we will generate an EXCEL report output from XML file and RTF Template using the standard Oracle BI Publisher API’s (Java based).

STEP1: Prepare and Convert RTF template to XSL-FO file

Oracle has provided a Java Class to generate PDF output based on XSL-FO file and XML input. Hence, first step is to generate the XSL-FO file based on RTF template. Details are available in another article,
Now, we should be having a XSL-FO file now.

STEP2: Prepare the Java wrapper Class for calling Standard class FOProcessor


import java.io.InputStream;
import java.io.OutputStream;
import oracle.apps.xdo.template.FOProcessor;
import oracle.apps.xdo.template.fo.util.FOUtility;
import java.io.*;
import oracle.apps.xdo.common.pdf.util.PDFDocMerger;
import oracle.apps.xdo.batch.DocumentProcessor;

public class convertxmltoexcel {

  public static void main(String[] args)
  {
    try
    {    
      FOProcessor processor = new FOProcessor();
      processor.setData(args[0]); //input XML
      processor.setTemplate(args[1]);  //input XSL template
      processor.setOutput(args[2]); // output Excel File
     
          // Set output format (for EXCEL generation)
      processor.setOutputFormat(FOProcessor.FORMAT_EXCEL);
      // Start processing
   
      processor.generate();
    }
    catch (Exception e)
    {
       e.printStackTrace();
       System.exit(1);
    }

    System.exit(0);
   
  }
}


STEP3: Compile the Java wrapper


javac -classpath $CLASSPATH convertxmltoexcel.java

Step 4: Copy the Wrapper Class to JAVA_TOP


cp convertxmltoexcel.class $JAVA_TOP

STEP5: Verify the Sample RTF template, XSL-FO file and XML File

Input XML:
clip_image001[4]
Actual RTF:
clip_image003[4]
Generated XSL-FO based on Step 1:
clip_image005[4]

Step6: Place the XSL-FO and Input XML file in Desired Directory and Call the Wrapper Java Class


java -classpath $CLASSPATH convertxmltoexcel ./INPUTDATAXML.xml ./RTFTEMPLATEEX.xsl ./RTFTEMPLATEEX.xls
clip_image007[4]

Output Excel Report:
clip_image008[4]
Now the Command given in the step6 can be called from HOST based concurrent program in Oracle Apps.

Happy Shairng !! Enjoy Learning!!

1 Responses to “BI Publisher API Example – Creating EXCEL Report from XML/XSL-FO/RTF in Oracle Apps?”

Anonymous said...
November 15, 2019 at 11:17 AM

even if I pass format as FOProcessor.FORMAT_EXCEL, file contains data in HTML format. Any suggestions.


Post a Comment

Disclaimer

The ideas, thoughts and concepts expressed here are my own. They, in no way reflect those of my employer or any other organization/client that I am associated. The articles presented doesn't imply to any particular organization or client and are meant only for knowledge Sharing purpose. The articles can't be reproduced or copied without the Owner's knowledge or permission.