Data import thru Excel in OAF

Data import thru Excel in OAF


--==================================================================
CREATE TABLE XX_DATA_INSERT_THRU_EXCEL_TL
(    col1                 VARCHAR2(100),
     col2                 VARCHAR2(100),
     col3                 VARCHAR2(100),
     col4                 VARCHAR2(100),
     col5                 VARCHAR2(100),
     last_update_date   DATE         NOT NULL,
     last_updated_by    NUMBER   NOT NULL,
     creation_date         DATE         NOT NULL,
     created_by             NUMBER    NOT NULL,
     last_update_login  NUMBER
)


select * from XX_DATA_INSERT_THRU_EXCEL_TL

--===================================================================
Link For JAR Files:-

http://www.java2s.com/Code/Jar/j/Downloadjxl266sourcesjar.htm



--===============================  CO --==============================
import java.io.Serializable;
import oracle.apps.fnd.common.VersionInfo;
import oracle.apps.fnd.framework.OAApplicationModule;
import oracle.apps.fnd.framework.OAException;
import oracle.apps.fnd.framework.webui.OAControllerImpl;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;
import oracle.cabo.ui.data.DataObject;
import oracle.jbo.domain.BlobDomain;
//import oracle.cabo.share.data.DataObject;


   public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
   {
    super.processFormRequest(pageContext, webBean);

    if (pageContext.getParameter("Go") != null)
    {
     DataObject fileUploadData = (DataObject)pageContext.getNamedDataObject("MessageFileUpload");
    //oracle.cabo.ui.data.DataObject fileUploadData = (oracle.cabo.ui.data.DataObject)pageContext.getNamedDataObject("MessageFileUpload");
      String fileName = null;
             
     try
     {
      fileName = (String)fileUploadData.selectValue(null, "UPLOAD_FILE_NAME");
     }
     catch(NullPointerException ex)
     {
      throw new OAException("Please Select a File to Upload", OAException.ERROR);
     }

     BlobDomain uploadedByteStream = (BlobDomain)fileUploadData.selectValue(null, fileName);
     try
     {
      OAApplicationModule oaapplicationmodule = pageContext.getRootApplicationModule();
      Serializable aserializable2[] = {uploadedByteStream};
      Class aclass2[] = {BlobDomain.class };
      oaapplicationmodule.invokeMethod("ReadExcelFile", aserializable2,aclass2);
     }
     catch (Exception ex)
     {
      throw new OAException(ex.toString(), OAException.ERROR);
     }
    }
   }
 
 
--====================================== AM ========================

import java.io.IOException;
import jxl.Cell;
import jxl.CellType;
import jxl.read.biff.BiffException;
import jxl.Sheet;
import jxl.Workbook;
import oracle.apps.fnd.framework.OAViewObject;
import oracle.apps.fnd.framework.server.OAApplicationModuleImpl;
import oracle.jbo.domain.BlobDomain;
import oracle.jbo.Row;
//import org.omg.CORBA.portable.InputStream;
 import java.io.InputStream;


// --------------------------  For Record Create in to the table based on VO ----------------------- //

    public void createNewRecord(String[] excel_data)
    {
     OAViewObject vo = (OAViewObject)getDataInsertFromExcel_EOVO1();
     if (!vo.isPreparedForExecution())
     {
      vo.executeQuery(); 
      } 
                 
     Row row = vo.createRow();   
     try
     {
      for (int i=0; i < excel_data.length; i++)
      {
       row.setAttribute("Col" +(i+1) ,excel_data[i]);
      }
     }
     catch(Exception e)
     {
      System.out.println(e.getMessage());
      }

     vo.insertRow(row);
     getTransaction().commit();
    }

    // --------------------------  For Read Excel from Local System ----------------------- //
 
    public void ReadExcelFile(BlobDomain fileData) throws IOException
    {
     String[] excel_data  = new String[5];     
     InputStream inputWorkbook = (InputStream)fileData.getInputStream();
     //java.io.InputStream inputWorkbook = (java.io.InputStream)fileData.getInputStream();
           
      Workbook w;     
     try
     {
      w = Workbook.getWorkbook(inputWorkbook);
                     
      // Get the first sheet
      Sheet sheet = w.getSheet(0);
   
        System.out.println("Row count"+sheet.getRows());
        System.out.println("Column count"+sheet.getColumns());
     
      for (int i = 0; i < sheet.getRows(); i++)
      {
       for (int j = 0; j < sheet.getColumns(); j++)
       {
        Cell cell = sheet.getCell(j, i);
        CellType type = cell.getType();
        if (cell.getType() == CellType.LABEL)
        {
         System.out.println("I got a label " + cell.getContents());
         excel_data[j] = cell.getContents();
        }
        else if (cell.getType() == CellType.NUMBER)
        {
         System.out.println("I got a number " + cell.getContents());
         excel_data[j] = cell.getContents();
        }

        else
        {
         excel_data[j] = "";
        } 

      }
       createNewRecord(excel_data);       
      }
     }
             
     catch (BiffException e)
     {
      e.printStackTrace();
     }
    }
 

--===========================================================

Comments

  1. How to migrate this jxl-2.6.3.jar in Oracle EBS 12.2.4

    When I deploy the page I get below error

    oracle.apps.fnd.framework.OAException: Could not load application module 'test.oracle.apps.po.prupload.server.TestAM'
    oracle.jbo.JboException: JBO-29000: Unexpected exception caught: oracle.jbo.JboException, msg=JBO-29000: Unexpected exception caught: java.lang.NoClassDefFoundError, msg=jxl/read/biff/BiffException

    ReplyDelete

Post a Comment

Popular posts from this blog

E-Text Report In Fusion | Types of E-Text reports

Supplier API's

How to pass default Parameter in cursor