cancel
Showing results for 
Search instead for 
Did you mean: 

How to Upload data trough Excel File

Former Member
0 Kudos

Hi Friends,

I have one doubt in WDJ,

My Requirement is downloading in table data into Excel file and do modification Some fields in Excel File and upload excel file. That time in table data is updated.

1. I have to done download the data into excel file

2. Now I need upload excel file. When I upload excel file that time that modification data will update in table .

Can u tell meu2026.how to do this. If u have any documents pls share with me.

Regards

Vijay Kalluri

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi iVijay ,

You need to download the jxl.jar file. Create a library DC with this jar file.

Add this library DC as dependency to Web Dynpro DC

And write this code to access data from the excel file


Workbook workbook =Workbook.getWorkbook(new File(wdContext.currentContextElement().getFilePath())); 
		  Sheet sheet = workbook.getSheet(0); 
 
		  int columns = sheet.getColumns(); 
		  int rows = sheet.getRows(); 
		  int i=0; 
		  for(int j=1;j<rows;j++) 
		  { 
			  IEmployeeElement element=wdContext.nodeEmployee().createAndAddEmployeeElement(); 
			  Cell c1 = sheet.getCell(i,j); 
			  element.setFirstName(c1.getContents()); 
			  Cell c2 = sheet.getCell(i+1,j); 
			  element.setLastName(c2.getContents()); 
			  Cell c3 = sheet.getCell(i+2,j); 
			  element.setDesignation(c3.getContents());  
		  }

Regards,

Amol

Former Member
0 Kudos

Hi Friend,

I have to follow this steps,

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

{

//@@begin onActionExportToTable(ServerEvent)

try

{

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

Sheet sh = wb.getSheet(0);

int cloumns = sh.getColumns();

int row = sh.getRows();

int i = 0;

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

{

IPrivatePO_Details_ResultView.IPoDetails_OutTabElement ele = wdContext.nodePoDetails_OutTab().createPoDetails_OutTabElement();

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

ele.setPo_Number(c1.getContents());

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

ele.setPo_Item(c2.getContents());

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

ele.setMaterial(c3.getContents());

.......................

....................................

Cell c6 = sh.getCell(i+5,j);

ele.setQuantity(c6.getContents());

In Cell C6 i am getting error like this The method SetQuantity(BigDesimal) in the type IPrivatePo_Details_ResultView.

IPODetails_OutTabElement is not applicable for the arguments(String)

PODetails_OutTab--- This is for VallueNode. under this node all attribues avaliable.

Same as Date Filed Also

Cell c9 = sh.getCell(i+8,j);

ele.setDeliv_Date(c9.getContents());

In Cell C9 i am getting error like this The method setDeliv_Datey(Date) in the type IPrivatePo_Details_ResultView.

IPODetails_OutTabElement is not applicable for the arguments(String)

PODetails_OutTab--- This is for VallueNode. under this node all attribues avaliable.

wdContext.nodePoDetails_OutTab().addElement(ele);

}

}

catch(Exception Ex)

{

wdComponentAPI.getMessageManager().reportException("Hiiii",true);

}

//@@end

}

How to Solve this error my dear Friend

p330068
Active Contributor
0 Kudos

Hi Vijay ,

Please try this for Quantity field:-

BigDecimal dec = null;

Cell c6 = sh.getCell(i+5,j);

bdStr = new BigDecimal(c6.getContents());

ele.setQuantity(bdStr);

For Date :

SimpleDateFormat smDate = null;

Date dt = null;

smDate = new SimpleDateFormat("dd-MMM-yy");

Cell c9 = sh.getCell(i+8,j);

dt = (Date)smDate.parse(c9.getContents());

ele.setDeliv_Date(dt);

Hope it helps

Regards

Arun

Edited by: Arun Jaiswal on Apr 28, 2010 8:34 PM

Former Member
0 Kudos

Hi Friends,

I am working on pass the data to table by using excel file. Means data is available in excel file. Browse this file click on u201CExportToTableu201D that excel file data will moves to table.So I had wrote some codeing. But it is not working. Please check it any problem in codeing part.

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

{

//@@begin onActionExportToTable(ServerEvent)

try

{

//Workbook wb = Workbook.getWorkbook(new File("C:
POStatus.xls"));

//Workbook wb = Workbook.getWorkbook(new File("Path"));

Workbook wb = Workbook.getWorkbook(new File(wdContext.currentContextElement().getResource().getResourceName().toString()));

wdComponentAPI.getMessageManager().reportSuccess("wb");

Sheet sh = wb.getSheet(0);

int cloumns = sh.getColumns();

int row = sh.getRows();

int i = 0;

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

{

wdComponentAPI.getMessageManager().reportSuccess("Hi::");

IPrivatePO_Details_ResultView.IPoDetails_OutTabElement ele = wdContext.nodePoDetails_OutTab().createPoDetails_OutTabElement();

wdComponentAPI.getMessageManager().reportSuccess("Hi::"+ele);

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

ele.setPo_Number(c1.getContents());

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

ele.setPo_Item(c2.getContents());

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

ele.setVendor_Material(c3.getContents());

Cell c4 = sh.getCell(i+3,j);

ele.setMaterial(c4.getContents());

Cell c5 = sh.getCell(i+4,j);

ele.setMatl_Desc(c5.getContents());

Cell c6 = sh.getCell(i+5,j);

ele.setUom(c6.getContents());

BigDecimal bdStr = null;

Cell c7 = sh.getCell(i+6,j);

bdStr = new BigDecimal(c7.getContents());

ele.setQuantity(bdStr);

Cell c8 = sh.getCell(i+7,j);

bdStr = new BigDecimal(c8.getContents());

ele.setQuantity(bdStr);

Cell c9 = sh.getCell(i+8,j);

bdStr = new BigDecimal(c9.getContents());

ele.setQuantity(bdStr);

SimpleDateFormat smDate = null;

Date dt = null;

smDate = new SimpleDateFormat("dd.MM.yyyy");

Cell c10 = sh.getCell(i+9,j);

dt = (Date)smDate.parse(c10.getContents());

ele.setDeliv_Date(dt);

Cell c11 = sh.getCell(i+10,j);

dt = (Date)smDate.parse(c11.getContents());

ele.setDeliv_Date(dt);

Cell c12 = sh.getCell(i+11,j);

dt = (Date)smDate.parse(c12.getContents());

ele.setDeliv_Date(dt);

Cell c13 = sh.getCell(i+12,j);

dt = (Date)smDate.parse(c13.getContents());

ele.setDeliv_Date(dt);

Cell c14 = sh.getCell(i+13,j);

ele.setPo_Status(c14.getContents());

wdContext.nodePoDetails_OutTab().addElement(ele);

}

}

catch(Exception Ex) {

wdComponentAPI.getMessageManager().reportSuccess("Hi::Exception");

Ex.printStackTrace();

}

//@@end

}

*Here my Requirement is file browse from any location. when click on "ExportToExcel" Button. that data will display in Table. If any same data in Table it will be updated.*

Regards

Vijay Kalluri

Former Member
0 Kudos

Hi all,

I'm also getting one error regarding this, that is I have done all the things is there in blog. But at run time I'm getting 500 Internal server Exceptiom when im choosing deploy new archive and run (Directly showing that error even not showing layout for clicking Ui's in layout) and workbook class not found like, and I have added jxl.jar its showing in LIB directory any one help me on this.

Thanks

Polaka

Answers (1)

Answers (1)

Former Member
0 Kudos