Approach for Uploading CSV and Excel (Xlsx extensions)  to tables in Webdynpro Java

                         

                                                                                                                                 

1.    Objective

The objective of this document is to provide an approach on how to upload data from CSV and Excel template to the table nodes in WDJ View

2.    Business Scenario

Some times a project requirement involves templates where in the user is provided with an option to download the standard template and after the filling the data in the same, upload it to the view. On clicking the upload button, a pop up is raised for browsing the file and on click of OK button ,the data of the selected file is uploaded to the nodes of the tables on the UI view.

3.    Approach

1.1. Design Workflow for Uploading files

  1. Use following structure of UI’s for Uploading the Files:-Home View

Fig1.1.png               

  Fig 1.1On click of upload  button

/wp-content/uploads/2014/07/upload_500933.png

File Upload View

/wp-content/uploads/2014/07/fig1_2_500935.png

Fig 1.2

2.When User selects any document and click on Ok its corresponding data will be uploaded to the respective data nodes.

Note:- After clicking on OK, the if the file is not selected then the error message will be shown as ‘No file selected .Also these data are stored onto the backend on the click of Save/Submit and they are not stored in KM repository.

3.When user clicks on close icon the pop up will be closed.

  1. 2. Adding Dependency of KMC-CM, in your WebDynpro

  1.  First of all make sure your Software Component has the dependency of the KMC-CM,

For e.g., to use KMC-CM in a tpa module the SC should have the dependency of KMC-CM so that we can add the dependency to the WebDynpro dc.

2. Now go to your WebDynpro DC, component properties -> Under Dependency type->Add “tc/km/frwk” dc under

          the KMC-CM.

/wp-content/uploads/2014/07/fig1_3_500948.png

3.Create a context attribute in the component  controller:

Context.png


  Where

      CTX_VA_PopUpInstance -Data-IWDWindow
      CTX _VA _Resource  -Datatype-Resource

3. Required jars for Excel upload to be added in an External Library project:

There are certain jar files required for implementing Excel sheet upload for Xlsx file extensions.

Concluding the Apache POI 3.5 should be used as it caters to the extension upload; the jar files are being used  for Excel jar files upload are as follows

1.xmlbeans-2.3.0.jar  2.poi-ooxml-3.5-FINAL.jar 3.poi-3.5-FINAL.jar 4.ooxml-schemas-1.0.jar 5.dom4j-1.6.1.jar

Note:

It is recommended that these jar files should be put onto an external library project and the project should be added as a dependency to the project which needs to implement upload functionality. These files can be downloaded from Internet.

4. Uploading Document data to the view

1.    Create a view named FileUpload and Window named FileUploadWin.

2.    Create a context Attribute  in FileUploadWin of type IWDView  and name it  CTX_VA_View

3.    In the view File Upload ,insert the following UI elements:

UI element

Properties

Page Header

Id:pghHeader

Title:FileUpload

Transparent container

Id: trc_fileUpload

Layout:Matrixlayout

Layout Data:Matrix HeadData

Label

Id: lbl_fileupload

Layoutdata:MatrixHeadData

Text: Click on Browse to upload the file

FileUploadUI

Id: flu_fileupl

Layoutdata:MatrixData

Resource:CTX_VA_FileName(Type:Resource)

The FileUpload View will look as follows:

Fileupload.JPG

3.In FileUploadWin Window, Create the following methods and event handlers

Name of the method /Event handler

Type

Return type

Description

M_getPath

Method

String

Used to get the path of the file selected and returns the extension of the file

M_uploadCsv

Method

Void

To set the values of the data from the CSV file uploaded to the table nodes on the View

m_uploadExcelsx

Method

Void

To set the values of the data from the Excel file(.xlsx) uploaded to the table nodes on the view

OK

Event handler

Void

On the click of event handler OK,depending on the extension of the file selected ,the corresponding upload functions are called so that the data can be stored on to the table nodes on the Home Page View

Technical Methods Definition:

M_getpath():

publicjava.lang.String m_getPath( )  {

    //@@begin m_getPath()

        InputStream text=null;

        String  file_ext;

        int temp=0;

        try {

              if(wdThis.wdGetAdmincongCompController().wdGetContext().currentCTX_VN_Form7Element().getCTX_VA_FileName()!=null)

{                 

String filename=wdThis.wdGetAdmincongCompController().wdGetContext().currentCTX_VN_Form7Element().getCTX_VA_FileName().getResourceName();

            intcut = filename.lastIndexOf(“.”);

            file_ext=filename.substring(cut+1, filename.length());

            File file=new File(wdThis.wdGetAdmincongCompController().wdGetContext().currentCTX_VN_Form7Element().getCTX_VA_FileName().getResourceName().toString());

            FileOutputStream op=newFileOutputStream(file);

              text=wdThis.wdGetAdmincongCompController().wdGetContext().currentCTX_VN_Form7Element().getCTX_VA_FileName().read(false);

              while((temp=text.read())!=-1)

              {

                    op.write(temp);

              }

          op.flush();

          op.close();

          path=file.getAbsolutePath();

 

          return file_ext;

              }

              else

              {

                    wdComponentAPI.getMessageManager().reportException(“No file selected!”);

                    return null;

              }

   

   

      } catch (Exception e) {

            // TODO Auto-generated catch block

            e.printStackTrace();

            return null;

  }

M_uploadCSV

  public void m_uploadcsv( )  {

    //@@begin m_uploadcsv()

              try {

              List<String> mylist=newArrayList<String>();

              List<String> dirlist=newArrayList<String>();

              List<String> ceoList=newArrayList<String>();

              if(wdThis.wdGetAdmincongCompController().wdGetContext().currentCTX_VN_Form7Element().getCTX_VA_FileName()!=null)

              {

              IWDResource csvFile =wdThis.wdGetAdmincongCompController().wdGetContext().currentCTX_VN_Form7Element().getCTX_VA_FileName();

              //create BufferedReader to read csv file

   

              java.io.InputStream stream = csvFile.read(true);

              BufferedReader br = newBufferedReader(newInputStreamReader(stream));

              String[]dataArray = null;

              String[]dirArray=null;

              String []ceoArray=null;

              String []caoArray=null;

              String []audArray=null;

              IPublicAdmincongComp.ICTX_VN_DirectorsDtlsElement dir=null;

              IPublicAdmincongComp.ICTX_VN_CEO_dtlsElement ceo=null;

              IPublicAdmincongComp.ICTX_VN_CAO_dtlsElement cao=null;

              IPublicAdmincongComp.ICTX_VN_Auditors_dtlsElement aud=null;

              DateFormat frmt = newSimpleDateFormat(“dd-MM-yyyy”);

              int row = 0;     

              intcol = 0;

              inti=0;

              //read each line of text file 

     

     

              String line = br.readLine(); 

              dataArray=line.split(“,”);

              Collections.addAll(mylist,dataArray);

              if(mylist.contains(“Name of Director”) && mylist.contains(“Date of joining as director”))

              {

                    line=br.readLine();

                    while(line!=null)

                    {

               

                          dirArray=line.split(“,”);

                          dir=wdThis.wdGetAdmincongCompController().wdGetContext().nodeCTX_VN_DirectorsDtls().createAndAddCTX_VN_DirectorsDtlsElement();

                          if(!“CEO/CAO”.equals(dirArray[0]) && (dirArray[0]!=null || !(“”.equals(dirArray[0]))))

                          {

                          dir.setCTX_VA_DirectorsName(dirArray[0]);

                          }

                          else

                          {

                                dir.setCTX_VA_DirectorsName(null);

                          }

                          if(!“Name of CEO/CAO”.equals(dirArray[1]) && (dirArray[1]!=null || !(“”.equals(dirArray[1]))))

                          {

                          dir.setCTX_VA_Age(Integer.parseInt(dirArray[1]));

                          }

                          else

                          {

                                dir.setCTX_VA_Age(0);

                          }

                 

                          if(!“Age”.equals(dirArray[2]) && (dirArray[2]!=null || !(“”.equals(dirArray[2]))))

                          {

                          dir.setCTX_VA_Address(dirArray[2]);

                          }

                          else

                          {

                                dir.setCTX_VA_Address(null);

                          }

                          if(!“Date of joining as director”.equals(dirArray[3])&& (dirArray[3]!=null|| !(“”.equals(dirArray[3]))))

                          {

                          String l_str_StDate=dirArray[3].replace(‘/’, ‘-‘);

                          java.util.Date parsedUtilDate = frmt.parse(l_str_StDate); 

                          java.sql.Date sqltDate= newjava.sql.Date(parsedUtilDate.getTime());

                          dir.setCTX_VA_Date_Joiinng(sqltDate);

                          }

                          else

                          {

                                dir.setCTX_VA_Date_Joiinng(null);

                          }

                          if(!“Other Directorship”.equals(dirArray[4]) && (dirArray[4]!=null || !(“”.equals(dirArray[4]))))

                          {

                          dir.setCTX_VA_OtherDirectorship(dirArray[4]);

                          }

                          else

                          {

                                dir.setCTX_VA_OtherDirectorship(null);

                          }

                          if(dirArray[5]==null || “”.equals(dirArray[5]))

                          {

                                dir.setCTX_Date_Exit(null);

                          }

                          else

                          {

                                String l_str_StDate1=dirArray[5].replace(‘/’, ‘-‘);

                                java.util.Date parsedUtilDate1 = frmt.parse(l_str_StDate1); 

                                java.sql.Date sqltDate1= newjava.sql.Date(parsedUtilDate1.getTime());

                                dir.setCTX_Date_Exit(sqltDate1);

                          }

                          if(dirArray[6]!=null || !(“”.equals(dirArray[6])))

                          {

                          dir.setCTX_VA_TelephoneNo(dirArray[6]);

                          }

                          else

                          {

                                dir.setCTX_VA_TelephoneNo(null);

                          }

                          if(dirArray[7]!=null || !(“”.equals(dirArray[7])))

                          {

                          dir.setCTX_VA_Email(dirArray[7]);

                          }

                          else

                          {

                                dir.setCTX_VA_Email(null);

                          }

                          line = br.readLine();

                          if(line.startsWith(“CEO/CAO”) && line.endsWith(“e-mail”))

                          {

                     

                                row=line.indexOf(“CEO/CAO”);

                     

                            line=br.readLine();

                            while(line!=null)

                            {

                              ceoArray=line.split(“,”);

                              ceo=wdThis.wdGetAdmincongCompController().wdGetContext().nodeCTX_VN_CEO_dtls().createAndAddCTX_VN_CEO_dtlsElement();

                              cao=wdThis.wdGetAdmincongCompController().wdGetContext().nodeCTX_VN_CAO_dtls().createAndAddCTX_VN_CAO_dtlsElement();

                              if(line.startsWith(“CEO”))

                             

                              {

                                    wdThis.wdGetAdmincongCompController().wdGetContext().nodeCTX_VN_Visibility().currentCTX_VN_VisibilityElement().setCTX_VA_tblCao(WDVisibility.NONE);

                                    if(!“internal/Statutory”.equals(ceoArray[1])&& !“Name of Auditor”.equals(ceoArray[1]) &&( ceoArray[1]!=null || !(“”.equals(ceoArray[1]))))

                                    {

                                    ceo.setCTX_VA_CEO_CAO_Name(ceoArray[1]);

                                    }

                                    else

                                    {

                                          ceo.setCTX_VA_CEO_CAO_Name(null);

                                    }

                                    if(!“Address”.equals(ceoArray[2])&& (ceoArray[2]!=null ||  !(“”.equals(ceoArray[2]))))

                                    {

                                    ceo.setCTX_VA_Age(Integer.parseInt(ceoArray[2]));

                                    }

                                    else

                                    {

                                   

                                    }

                                    if(!“Date of joining”.equals(ceoArray[3]) && (ceoArray[3]!=null || !(“”.equals(ceoArray[3]))))

                                    {

                                    ceo.setCTX_VA_Address(ceoArray[3]);

                                    }

                                    else

                                    {

                                          ceo.setCTX_VA_Address(null);

                                    }

                                    if(ceoArray[4]!=null || !(“”.equals(ceoArray[4])))

                                    {

                                    String l_str_SDate=ceoArray[4].replace(‘/’, ‘-‘);

                                          java.util.Date pUtilDate = frmt.parse(l_str_SDate); 

                                          java.sql.Date sqlDte= newjava.sql.Date(pUtilDate.getTime());

                                    ceo.setCTX_VA_Date_Joiinng(sqlDte);

                                    }

                                    else

                                    {

                                          ceo.setCTX_VA_Date_Joiinng(null);

                                   

                                    }

                                    if(ceoArray[5]!=null || !(“”.equals(ceoArray[5])))

                                    {

                                    ceo.setCTX_VA_Qual(ceoArray[5]);

                                    }

                                    else

                                    {

                                          ceo.setCTX_VA_Qual(null);

                                    }

                                      if(ceoArray[6]==null || “”.equals(ceoArray[6]))

                                            {

                                                  ceo.setCTX_Date_Exit(null);

                                            }

                                            else

                                            {

                                                  String l_str_Dte=ceoArray[6].replace(‘/’, ‘-‘);

                                                  java.util.Date pUtilDte = frmt.parse(l_str_Dte); 

                                                  java.sql.Date sDte= newjava.sql.Date(pUtilDte.getTime());

                                                  ceo.setCTX_Date_Exit(sDte);

                                            }

                                    if(ceoArray[7]!=null || !(“”.equals(ceoArray[7])))

                                    {

                                    ceo.setCTX_VA_TelephoneNo(ceoArray[7]);

                                    }

                                    else

                                    {

                                          ceo.setCTX_VA_TelephoneNo(null);

                                    }

                                    if(ceoArray[8]!=null || !(“”.equals(ceoArray[8])))

                                    {

                                    ceo.setCTX_VA_Email(ceoArray[8]);

                                    }

                                    else

                                    {

                                          ceo.setCTX_VA_Email(null);

                                    }

                           

                              }

                     

                     

                              line=br.readLine();

               

                              if(line.startsWith(“internal/Statutory”))

                                      {

                                    line=br.readLine();

                                    while(line!=null)

                                        {

                                          audArray=line.split(“,”);

                                   

                                        aud=wdThis.wdGetAdmincongCompController().wdGetContext().nodeCTX_VN_Auditors_dtls().createAndAddCTX_VN_Auditors_dtlsElement();

                                        if(audArray[0]!=null || !(“”.equals(audArray[0])))

                                        {

                                        aud.setCTX_VA_Particulars(audArray[0]);

                                        }

                                        else

                                        {

                                          aud.setCTX_VA_Particulars(null);

                                        }

                                        if(audArray[1]!=null|| !(“”.equals(audArray[1])))

                                        {

                                        aud.setCTX_VA_Name_Auditor(audArray[1]);

                                        }

                                        else

                                        {

                                          aud.setCTX_VA_Name_Auditor(null);

                                        }

                                        if(audArray[2]!=null || !(“”.equals(audArray[2])))

                                        {

                                        aud.setCTX_VA_Address(audArray[2]);

                                        }

                                        else

                                        {

                                          aud.setCTX_VA_Address(null);

                                        }

                                        if(audArray[3]!=null || !(“”.equals(audArray[3])))

                                        {

                                        String l_str_SDate=audArray[3].replace(‘/’, ‘-‘);

                                          java.util.Date pUtilDate = frmt.parse(l_str_SDate); 

                                          java.sql.Date sqlDte= newjava.sql.Date(pUtilDate.getTime());

                                          aud.setCTX_VA_Date_Appointment(sqlDte);

                                        }

                                        else

                                        {

                                          aud.setCTX_VA_Date_Appointment(null);

                                        }

                                        if(audArray[4]!=null || !(“”.equals(audArray[4])))

                                        {

                                        aud.setCTX_VA_Remarks(audArray[4]);

                                        }

                                        else

                                        {

                                          aud.setCTX_VA_Remarks(null);

                                        }

                                        if(audArray[5]!=null || !(“”.equals(audArray[5])))

                                        {

                                        aud.setCTX_VA_TelephoneNo(audArray[5]);

                                        }

                                        else

                                        {

                                          aud.setCTX_VA_TelephoneNo(null);

                                        }

                                        if(audArray[6]!=null || !(“”.equals(audArray[6])))

                                        {

                                        aud.setCTX_VA_Email(audArray[6]);

                                        }

                                        else

                                        {

                                          aud.setCTX_VA_Email(null);

                                        }

                                        line=br.readLine();

                                        }

                                      }

                       

                       

                            }

                             

                          }

                          else

                          {

                              //

                          }

                    }               

           

              }

              }

              else

              {

                    wdComponentAPI.getMessageManager().reportException(“File not selected!”);

              }

            }

M_uploadXlsx():

public voidm_uploadExcelsx( )  {

    //@@begin m_uploadExcelsx()

            m_getPath();

            try {

                  FileInputStream fis= new FileInputStream(path);

                  Workbook wb= new XSSFWorkbook(fis);

Sheet sheet = wb.getSheetAt(0);

// access the 1st sheet of the uploaded excel to get the data for the 1st table

                  Row row;

                  Row cxo_row;

                  Row aud_row;

                  Cell cell;

                  Cell c_cell;

                  Cell a_cell;

                  int rows; // No of rows

                  intc_rows;

                  int a_rows;

                  rows = sheet.getPhysicalNumberOfRows();

                  int cols = 0;

                  intcxo_col = 0;

                  intaud_col = 0;

                  intc = 0; // No of columns

                  int tmp = 0;

                  DateFormat frmt= new SimpleDateFormat(“dd-MM-yyyy“);

                  // This trick ensures that we get the data properly even if it

                  // doesn’t start from first few rows

                 

                  for (intr = 1; r <= rows; r++) {

                        row = sheet.getRow(r);

                        if (row != null) {

                              // Your code here

                              dir= wdContext.nodeCTX_VN_DirectorsDtls()

                                          .createCTX_VN_DirectorsDtlsElement();

                              cell = row.getCell(c);

                              if (cell != null) {

                                    dir.setCTX_VA_DirectorsName(cell

                                                .getRichStringCellValue().toString());

                              } else {

                                    dir.setCTX_VA_DirectorsName(null);

                              }

                              Cell cell1 = row.getCell(c + 1);

                              if (cell1 != null) {

                                    int value = (int) cell1.getNumericCellValue();

                                    dir.setCTX_VA_Age(value);

                              } else {

                                    dir.setCTX_VA_Age(0);

                              }

                              Cell cell2 = row.getCell(c + 2);

                              if (cell2 != null) {

                                    dir.setCTX_VA_Address(cell2.getRichStringCellValue()

                                                .toString());

                              } else {

                                    dir.setCTX_VA_Address(null);

                              }

                              Cell cell3 = row.getCell(c + 3);

                              if (cell3 != null) {

                                    String l_str_StDate = cell3.getStringCellValue()

                                                .replace(‘/’, ‘-‘);

                                    java.util.Date parsedUtilDate;

                                    parsedUtilDate = frmt.parse(l_str_StDate);

                                    java.sql.Date sqltDate = new java.sql.Date(

                                                parsedUtilDate.getTime());

                                    dir.setCTX_VA_Date_Joiinng(sqltDate);

                              } else {

                                    dir.setCTX_VA_Date_Joiinng(null);

                              }

                              Cell cell4 = row.getCell(c + 4);

                              if (cell4 != null) {

                                    dir.setCTX_VA_OtherDirectorship(cell4

                                                .getRichStringCellValue().toString());

                              } else {

                                    dir.setCTX_VA_OtherDirectorship(null);

                              }

                              Cell cell5 = row.getCell(c + 5);

                              if (cell5 != null) {

                                    String l_str_StDate = cell5.getStringCellValue()

                                                .replace(‘/’, ‘-‘);

                                    java.util.Date parsedUtilDate;

                                    parsedUtilDate = frmt.parse(l_str_StDate);

                                    java.sql.Date sqltDate = new java.sql.Date(

                                                parsedUtilDate.getTime());

                                    dir.setCTX_Date_Exit(sqltDate);

                              } else {

                                    dir.setCTX_Date_Exit(null);

                              }

                              Cell cell6 = row.getCell(c + 6);

                              if (cell6 != null) {

                                    long value1 = (long) cell6.getNumericCellValue();

                                    dir.setCTX_VA_TelephoneNo(String.valueOf(value1));

                              } else {

                                    dir.setCTX_VA_TelephoneNo(null);

                              }

                              Cell cell7 = row.getCell(c + 7);

                              if (cell7 != null) {

                                    dir.setCTX_VA_Email(cell7.getRichStringCellValue()

                                                .toString());

                              } else {

                                    dir.setCTX_VA_Email(null);

                              }

                              // Cell cell2=row.getCell(c+2);

                              // wdComponentAPI.getMessageManager().reportSuccess(“Director Name 3″+cell2.getRichStringCellValue());

                              // dir.setCTX_VA_Address(cell.getRichStringCellValue().toString());

                              // dir.setCTX_VA_Date_Joiinng(Date.valueOf(cell.getRichStringCellValue().toString()));

                              wdContext.nodeCTX_VN_DirectorsDtls().addElement(dir);

                        }

                  }

                  // for CXO table

// access the 2nd sheet of the uploaded excel to get the data for the 2nd table

                  Sheet cxo_sheet = wb.getSheetAt(1);

                  c_rows = cxo_sheet.getPhysicalNumberOfRows();

                  for (intj = 1; j <= c_rows; j++) {

                        cxo_row = cxo_sheet.getRow(j);

                        if (cxo_row != null) {

                              // Your code here

                              c_cell = cxo_row.getCell(cxo_col);

                              if (c_cell.getStringCellValue().contains(“CEO”)) {

                                    ceo= wdContext.nodeCTX_VN_CEO_dtls()

                                                .createCTX_VN_CEO_dtlsElement();

                                    Cell c_cell1 = cxo_row.getCell(cxo_col + 1);

                                    if (c_cell1 != null) {

                                          ceo.setCTX_VA_CEO_CAO_Name(c_cell1

                                                      .getRichStringCellValue().toString());

                                    } else {

                                          ceo.setCTX_VA_CEO_CAO_Name(null);

                                    }

                                    Cell c_cell2 = cxo_row.getCell(cxo_col + 2);

                                    if (c_cell2 != null) {

                                          int value = (int) c_cell2.getNumericCellValue();

                                          ceo.setCTX_VA_Age(value);

                                    } else {

                                          ceo.setCTX_VA_Age(0);

                                    }

                                    Cell c_cell3 = cxo_row.getCell(cxo_col + 3);

                                    if (c_cell3 != null) {

                                          ceo.setCTX_VA_Address(c_cell3

                                                      .getRichStringCellValue().toString());

                                    } else {

                                          ceo.setCTX_VA_Address(null);

                                    }

                                    Cell c_cell4 = cxo_row.getCell(cxo_col + 4);

                                    if (c_cell4 != null) {

                                          String l_str_StDate = c_cell4.getStringCellValue()

                                                      .replace(‘/’, ‘-‘);

                                          java.util.Date parsedUtilDate;

                                          parsedUtilDate = frmt.parse(l_str_StDate);

                                          java.sql.Date sqltDate = new java.sql.Date(

                                                      parsedUtilDate.getTime());

                                          ceo.setCTX_VA_Date_Joiinng(sqltDate);

                                    } else {

                                          ceo.setCTX_VA_Date_Joiinng(null);

                                    }

                                    Cell c_cell5 = cxo_row.getCell(cxo_col + 5);

                                    if (c_cell5 != null) {

                                          ceo.setCTX_VA_Qual(c_cell5.getRichStringCellValue()

                                                      .toString());

                                    } else {

                                          ceo.setCTX_VA_Qual(null);

                                    }

                                    Cell c_cell6 = cxo_row.getCell(cxo_col + 6);

                                    if (c_cell6 != null) {

                                          String l_str_StDate = c_cell6.getStringCellValue()

                                                      .replace(‘/’, ‘-‘);

                                          java.util.Date parsedUtilDate;

                                          parsedUtilDate = frmt.parse(l_str_StDate);

                                          java.sql.Date sqltDate = new java.sql.Date(

                                                      parsedUtilDate.getTime());

                                          ceo.setCTX_Date_Exit(sqltDate);

                                    } else {

                                          ceo.setCTX_Date_Exit(null);

                                    }

                                    Cell c_cell7 = cxo_row.getCell(cxo_col + 7);

                                    if (c_cell7 != null) {

                                          long value1 = (long) c_cell7.getNumericCellValue();

                                          ceo.setCTX_VA_TelephoneNo(String.valueOf(value1));

                                    } else {

                                          ceo.setCTX_VA_TelephoneNo(null);

                                    }

                                    Cell c_cell8 = cxo_row.getCell(cxo_col + 8);

                                    if (c_cell8 != null) {

                                          ceo.setCTX_VA_Email(c_cell8

                                                      .getRichStringCellValue().toString());

                                    } else {

                                          ceo.setCTX_VA_Email(null);

                                    }

                                    // Cell cell2=row.getCell(c+2);

                                    // wdComponentAPI.getMessageManager().reportSuccess(“Director Name 3″+cell2.getRichStringCellValue());

                                    // dir.setCTX_VA_Address(cell.getRichStringCellValue().toString());

                                    // dir.setCTX_VA_Date_Joiinng(Date.valueOf(cell.getRichStringCellValue().toString()));

                                    wdContext.nodeCTX_VN_CEO_dtls().addElement(ceo);

}                     

}

                 

}

                  // for auditor’s table

// access the 3rd  sheet of the uploaded excel to get the data for the 3rd table

                  Sheet aud_sheet = wb.getSheetAt(2);

                  a_rows = aud_sheet.getPhysicalNumberOfRows();

                  for (int x = 1; x <= a_rows; x++) {

                        aud_row = aud_sheet.getRow(x);

                        if (aud_row != null) {

                              // Your code here

                              aud= wdContext.nodeCTX_VN_Auditors_dtls()

                                          .createCTX_VN_Auditors_dtlsElement();

                              a_cell = aud_row.getCell(aud_col);

                              if (a_cell != null) {

                                    aud.setCTX_VA_Particulars(a_cell

                                                .getRichStringCellValue().toString());

                              } else {

                                    aud.setCTX_VA_Particulars(null);

                              }

                              Cell a_cell1 = aud_row.getCell(aud_col + 1);

                              if (a_cell1 != null) {

                                    aud.setCTX_VA_Name_Auditor(a_cell1

                                                .getRichStringCellValue().toString());

                              } else {

                                    aud.setCTX_VA_Name_Auditor(null);

                              }

                              Cell a_cell2 = aud_row.getCell(aud_col + 2);

                              if (a_cell2 != null) {

                                    aud.setCTX_VA_Address(a_cell2.getRichStringCellValue()

                                                .toString());

                              } else {

                                    aud.setCTX_VA_Address(null);

                              }

                              Cell a_cell4 = aud_row.getCell(aud_col + 3);

                              if (a_cell4 != null) {

                                    String l_str_StDate = a_cell4.getStringCellValue()

                                                .replace(‘/’, ‘-‘);

                                    java.util.Date parsedUtilDate;

                                    parsedUtilDate = frmt.parse(l_str_StDate);

                                    java.sql.Date sqltDate = new java.sql.Date(

                                                parsedUtilDate.getTime());

                                    aud.setCTX_VA_Date_Appointment(sqltDate);

                              } else {

                                    aud.setCTX_VA_Date_Appointment(null);

                              }

                              Cell a_cell5 = aud_row.getCell(aud_col + 4);

                              if (a_cell5 != null) {

                                    aud.setCTX_VA_Remarks(a_cell5.getRichStringCellValue()

                                                .toString());

                              } else {

                                    aud.setCTX_VA_Remarks(null);

                              }

                              Cell a_cell6 = aud_row.getCell(aud_col + 5);

                              if (a_cell6 != null) {

                                    long value1 = (long) a_cell6.getNumericCellValue();

                                    aud.setCTX_VA_TelephoneNo(String.valueOf(value1));

                              } else {

                                    aud.setCTX_VA_TelephoneNo(null);

                              }

                              Cell a_cell7 = aud_row.getCell(aud_col + 6);

                              if (a_cell7 != null) {

                                    aud.setCTX_VA_Email(a_cell7.getRichStringCellValue()

                                                .toString());

                              } else {

                                    aud.setCTX_VA_Email(null);

                              }

                              // Cell cell2=row.getCell(c+2);

                              // wdComponentAPI.getMessageManager().reportSuccess(“Director Name 3″+cell2.getRichStringCellValue());

                              // dir.setCTX_VA_Address(cell.getRichStringCellValue().toString());

                              // dir.setCTX_VA_Date_Joiinng(Date.valueOf(cell.getRichStringCellValue().toString()));

                              wdContext.nodeCTX_VN_Auditors_dtls().addElement(aud);

                        }

                  }

            } catch (ParseException e) {

                  // TODO Auto-generated catch block

                  e.printStackTrace();

                  wdComponentAPI.getMessageManager().reportException(

                              “Technical Error!” + e.getLocalizedMessage());

            } catch (FileNotFoundException e) {

                  // TODO Auto-generated catch block

                  e.printStackTrace();

                  wdComponentAPI.getMessageManager().reportException(

                              “Technical Error!” + e.getLocalizedMessage());

            } catch (IOException e) {

                  // TODO Auto-generated catch block

                  e.printStackTrace();

                  wdComponentAPI.getMessageManager().reportException(

                              “Technical Error!” + e.getLocalizedMessage());

            }

    //@@end

  }

Code for OK Event Handler:

public voidOk(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

  {

String l_rt_file_ext = m_getPath();// get the file extension and store in l_rt_file_ext

if(l_rt_file_ext.equals(“csv”))

{

      // calling Csv  upload function

      m_uploadcsv();

}

else if(l_rt_file_ext.equals(“xlsx”))

{

      // calling xlsx upload function

      M_uploadXlsx();

}

else {

  1. wdComponentAPI.getMessageManager().reportSuccess(“Invalid File format !”);

}

}

  1. 3.On the Home  View (as mentioned in fig 1.1) ,when the upload button is clicked, a pop up window should be displayed with the file upload UI

Code on OK  Button :

IWDWindowInfo windowinfo = wdComponentAPI.getComponentInfo().findInWindows(“FileUploadWin“);

IWDWindow window =    wdComponentAPI.getWindowManager().createModalWindow(windowinfo);

  1. wdThis.wdGetAdmincongCompController().wdGetContext().                    currentCTX_VN_Form7Element().setCTX_VA_PopUpInstance(window);

      window.show();

4.    Assumptions

The following are the assumptions made before running this application.

1.)    Your SAP J2EE Engine is up and running.

2.)    Your deployment completed successfully.

3.)    Added KMC-CM-“tc/km/frwk” dependency to your application.

4.)    Ensure that the apache POI 3.5 jars mentioned above are available in an external library file project and that project is added as a dependency to the project implementing upload functionality.

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply