Quantcast
Channel: SCN : Popular Discussions - Enterprise Content Management (SAP ECM)
Viewing all articles
Browse latest Browse all 2566

Read Excel in web dynpro Java

$
0
0

Dear friends,

 

I am trying to read excel in my web dynpro projects and i refer this article http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/d0d2ac59-e58f-2c10-9fa8-b8e93ff8d975?QuickLink=index&overridelayout=true&45290430176540

 

But it wont works, i did all steps as wrote in the document above  and different from the article i used external liblary, There is no error while it works but upload and export to table buttons doesnt work,

 

 

The codes are like :

 

 

 

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

 

 

{

IPrivateNew1CompView.IContextElement element1 = wdContext.currentContextElement();

            IWDResource resource = element1.getResource();

           

           

           

            InputStream text = null;

           

                      int temp=0;

            

                                try

                                {

                                          File file = new File(wdContext.currentContextElement().getResource().toString());

            

                                          FileOutputStream op = new FileOutputStream(file);

            

                                          if(wdContext.currentContextElement().getResource()!=null)

            

                                          {

                                                    text=wdContext.currentContextElement().getResource().read(false);

            

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

                                                    {

                                                              op.write(temp);

                                                    }

            

                                                    op.flush();

                                                    op.close();

            

                                                    path = file.getAbsolutePath();

            

                                                    wdComponentAPI.getMessageManager().reportSuccess(path);

            

                                          }

                                }

            

                                          catch(Exception e)

            

                                          {

                                          e.printStackTrace();

                                          }

 

 

// and my read excel action is like:

 

 

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

  {

    //@@begin onActionExportTable(ServerEvent)

            try

            {

 

                      InputStream fls = wdContext.currentContextElement().getResource().read(true);

                     

                      Workbook wb = Workbook.getWorkbook(new File(path));

                     

                      Sheet sh = wb.getSheet(0);

                     

                      int columns = sh.getColumns();

                     

                      int rows = sh.getRows();

                     

                      String stringc1 = null;

                     

                      String stringc2 = null;

                     

                      String stringc3 = null;

                     

                      int i = 0 ;

                     

                      for(int j = 1; j<rows;j++)

                               

                      {

                                ele = wdContext.nodeTableData().createTableDataElement();

                               

                                Cell c1 = sh.getCell(i,j);

                               

                                ele.setFirstName(c1.getContents());

                               

                                Cell c2 = sh.getCell(i+1,j);

                                ele.setLastName(c2.getContents());

                               

                                Cell c3 = sh.getCell(i+2,j);

                                ele.setEmpId(c3.getContents());

                               

                               

                               

                               

                               

                                wdContext.nodeTableData().addElement(ele);

                      }

                     

                     

            }

           

            catch(Exception ex)

           

            {

                      wdComponentAPI.getMessageManager().reportSuccess(ex.toString());

                     

            }

 

 

// at the end i wrote

 

 

String path;

 

  IPrivateNew1CompView.ITableDataElement ele;


Viewing all articles
Browse latest Browse all 2566

Trending Articles