cancel
Showing results for 
Search instead for 
Did you mean: 

Insert the values from Excel sheet to Java webdynpro screen?

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

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

Former Member
0 Kudos

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

srinivas_sistu
Active Contributor
0 Kudos

Hi,

go through this blog...

/people/subramanian.venkateswaran2/blog/2006/10/02/enhanced-file-upload--uploading-and-processing-excel-sheets

Regards,

Srinivas

Former Member
0 Kudos

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

Former Member
0 Kudos

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