Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

uploading excel to table

hi..,

i created on webdynpro project for upload excel .i created external library project, in this i created 2 puplic parts.i addes this project into my project component properties. for excel upload i used this code

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

{

//@@begin onActionUpload(ServerEvent)

IPrivateExcelUploadView.IContextElement element1 = wdContext.currentContextElement();

IWDResource resource = element1.getResource();

element1.setFileName(resource.getResourceName());

element1.setFileExtension(resource.getResourceType().getFileExtension());

wdComponentAPI.getMessageManager().reportSuccess("Resource Name: "+element1.getResource());

wdComponentAPI.getMessageManager().reportSuccess("File Extension:" +element1.getFileExtension());

text=null;

int temp=0;

try

{

File file = new File(wdContext.currentContextElement().getResource().getResourceName().toString());

FileOutputStream op = new FileOutputStream(file);

if(wdContext.currentContextElement().getResource()!=null)

{

text=wdContext.currentContextElement().getResource().read(false);

while((temp=text.read())!=-1)

{

op.write(temp);

}

}

op.flush();

op.close();

path = file.getAbsolutePath();

wdComponentAPI.getMessageManager().reportSuccess(path);

}

catch(Exception e)

{

e.printStackTrace();

}

//@@end

}

For getting data into excel i used this code:

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

{

//@@begin onActionUploadIntoTab(ServerEvent)

try

{

wdComponentAPI.getMessageManager().reportSuccess("Path:" +path);

wdComponentAPI.getMessageManager().reportSuccess("Uploading data");

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

Sheet sh = wb.getSheet(0);

wdComponentAPI.getMessageManager().reportSuccess("Columns = "+sh.getColumns());

wdComponentAPI.getMessageManager().reportSuccess("Rows = "+sh.getRows());

int columns = sh.getColumns();

int rows = sh.getRows();

int i=0;

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

{

ele=wdContext.nodeTable1().createTable1Element();

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

ele.setName(c1.getContents());

wdContext.nodeTable1().addElement(ele);

wdComponentAPI.getMessageManager().reportSuccess("Element Inserted");

}

wb.close();

}

catch(Exception ex)

{

wdComponentAPI.getMessageManager().reportSuccess(ex.toString());

wdComponentAPI.getMessageManager().reportSuccess(ex.getMessage());

wdComponentAPI.getMessageManager().reportException(""+ex.getCause());

}

//@@end

}

bt i got ouput as

Path:D:\usr\sap\CE1\J00\j2ee\cluster\server0\NA_ExportCustomer_Information_Form_example.xls

Uploading data

jxl.read.biff.BiffException: Unable to recognize OLE stream

Unable to recognize OLE stream

null

Former Member
Not what you were looking for? View more on this topic or Ask a question