on 05-13-2013 11:21 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
9 | |
9 | |
7 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.