cancel
Showing results for 
Search instead for 
Did you mean: 

Getting URL of uploaded excel file in server

Former Member
0 Kudos

Hi,

     I am new to Webdynpro Java. I have uploaded an excel file using FileUpload UI element. I am also able to get the URL of the uploaded file.  Even i The retrieved URL is

../../sap.com/basfpocproj1/Quizapp/~wd_key24_1368439187146/Quiz.xls?sap-wd-download=1&sap-wd-cltwndid=d3a49004bbb311e2b5cc000001fcbede&sap-wd-secure-id=d3a4b4f9bbb311e2c376000001fcbede6723243191&sap-wd-appwndid=d3a49005bbb311e2b4f5000001fcbede&sap-wd-norefresh=X

But after that I am not able to retrieve data from excel file.

The following is th ecode that I have written:

//To get the url of uploaded file

path=wdContext.currentContextElement().getFile_Resource().getUrl(0);

                              wdComponentAPI.getMessageManager().reportSuccess(path);

//To get data from excel

InputStream fis=null;

 

          List sheetData=new ArrayList();

try{

                    File file=new File("\""+path+"\"");

                    fis=new FileInputStream(file);

                    POIFSFileSystem fsPOI = new POIFSFileSystem(new BufferedInputStream(fis));

                    HSSFWorkbook wb=new HSSFWorkbook(fis);

                    HSSFSheet sheet=wb.getSheetAt(0);

                                           Iterator rows = sheet.rowIterator();

                                           while (rows.hasNext()) {

                                                                                  HSSFRow row = (HSSFRow) rows.next();

                                                                                  Iterator cells = row.cellIterator();

                                                                                  List data = new ArrayList();

                                                                                  while (cells.hasNext()) {

                                                                                  

                                                                                            HSSFCell cell = (HSSFCell) cells.next();

                                                                                            data.add(cell);

                                                                                  }

                                                     sheetData.add(data);

                                           }

                     

 

             }

             catch(IOException e){

                       e.printStackTrace();

             }

//To display data in a table

for(int i=0;i<sheetData.size();i++){

                               List list=(List)sheetdata.get(0);

           ITABLEElement element=wdContext.createTABLEElement();

                               for(int j=0;j<list.size();j++){

                                         HSSFCell cell=(HSSFCell) list.get(j);

                                        

                                        switch(j){

                                                    case 0:

                                                   element.setSNO(cell.getRichStringCellValue().getString());

                                                   break;

                                                   case 1:

                                                   element.setQUESTION(cell.getRichStringCellValue().getString());

                                                   break;

                                                   case 2:

                                                   element.setOPTION1(cell.getRichStringCellValue().getString());

                                                   break;

                                                   case 3:

                                                   element.setOPTION2(cell.getRichStringCellValue().getString());

                                                   break;

                                                   case 4:

                                                   element.setOPTION3(cell.getRichStringCellValue().getString());

                                                   break;

                                                   case 5:

                                                   element.setOPTION4(cell.getRichStringCellValue().getString());

                                                   break;

                                                   case 6:

                                                   element.setANSWER(cell.getRichStringCellValue().getString());

                                                   break;

                                         }

                                         File file=new File("");

 

                               }

           wdContext.nodeTABLE().addElement(element);

 

  }

Please help me out with this. Thanks in advance

Accepted Solutions (0)

Answers (1)

Answers (1)

junwu
Active Contributor
0 Kudos

if you want to retrieve it later using code, you have to store it somewhere.

if you want to extract the data from the file directly after upload, you can get binary data from context

Former Member
0 Kudos

Hi Jun Wu,

Can you please elaborate on this? How to get  binary data from context?

Former Member
0 Kudos

I AM GETTING ERROR EXACTLY IN THIS LINE

HSSFWorkbook wb=new HSSFWorkbook(fis);

Can you please help me out in this?


junwu
Active Contributor
0 Kudos

google some basic tutorial regarding upload....it is tooo basic...

Former Member
0 Kudos

Sure i will do it....