on 01-07-2009 12:33 PM
Hi Gurus,
I have requirement ,to provide the option to the user to Browse the Excel sheet which will have 1..n number of rows of values(some time 1 row .........sometimes 1000 rows) from the local system and they press the button INSERT which needs to insert the values of excel sheet into webdynpro screen table(which needs to be dynamically generated in webdynrpo screen) .
as anyone done this before.Give me the steps
Thanks in Advance,
Tom
Hi Tom,
Here you can take the values from the excel cell by cell assign where you want to assign.
for example. You just want to print the values from excel sheet. So what you can do is.
wdComponentAPI.getMessageManager().reportSuccess("Excel Values are" +cell.getNumericCellValue ());
wdComponentAPI.getMessageManager().reportSuccess("Excel Values are" +cell.getStringCellValue());
Regards
Narendra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Tom,
if(cell!=null){
//your code her
}
This is the place where you are getting the data from the excel sheet. This code has nothing to do with the webdynpro java. Its the code written in core java on the webdynpro platform. You can also get the same code when you will try to search it online.
Inside the condition brackets, you need to get the data and bind it to some attribute using which you can display the data from the excel to your webdynpro application.
Hope it helps.
Regards.
Rajat
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Tom,
You need to use file upload UI element to brouse the excel file and for getting the file path you can use the below steps.
1. create a context like filePath of type com.sap.ide.webdynpro.uielementdefinitions.Resource
2. Assign the context to the file upload childs resource properties.
3.Now you can use the below code to fetch the url.
String file = wdContext.currentContextElement().getFilePath().getUrl(0));
this will help you to retrieve file path.
For reading a excel file you can to use POI jar file.POI jar file you can download from internet, its totally free.
below is the straight forward code you can use to read the excel file you have uploaded.
try {
// Pass the uploaded file path.
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file));
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow row;
HSSFCell cell;
int rows; // No of rows
rows = sheet.getPhysicalNumberOfRows();
int cols = 0; // No of columns
int tmp = 0;
// This trick ensures that we get the data properly even if it doesn't start from first few rows
for(int i = 0; i < 10 || i < rows; i++) {
row = sheet.getRow(i);
if(row != null) {
tmp = sheet.getRow(i).getPhysicalNumberOfCells();
if(tmp > cols) cols = tmp;
}
}
for(int r = 0; r < rows; r++) {
row = sheet.getRow(r);
if(row != null) {
for(int c = 0; c < cols; c++) {
cell = row.getCell((short)c);
if(cell != null) {
// Your code here
}
}
}
}
} catch(Exception ioe) {
ioe.printStackTrace();
}
You can read the excel and insert the data into your table.
This can really solve your problem.
Regards
Narendra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Nagendra,
Thanks for your input.
Am new to Java WD can you please explain about this
What are referring in this block,If possible give me the code for this blog as well(some example sort of things to understand).
if(cell != null) {
// Your code here
}
}
}
}
} catch(Exception ioe) {
ioe.printStackTrace();
}
Tom
User | Count |
---|---|
81 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.