cancel
Showing results for 
Search instead for 
Did you mean: 

Uploading Excel File and Reading Data from that File

Former Member
0 Kudos

<b>Hi

Can anyone Please tell me how to upload an Excel File in to the Web Dynpro Application and After that i want to read the data from that uploaded excel file in the Web Dynpro Application to the Web Dynpro table.

Plz help me to solve this.......

Regards

Chandran</b>

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Chandran

See this thread

Regards

Fahad Hamsa

Former Member
0 Kudos

Hi,

Upload the file using this tutorial

https://www.sdn.sap.com/irj/sdn/webdynpro?rid=/library/uuid/49f2ea90-0201-0010-ce8e-de18b94aee2d#41

read the data from uploade excel

IWDResource resource = WDResourceFactory.createResource(wdContext.currentContextElement().getFileUploadUI().read(true),wdContext.currentContextElement().getFileUploadUI().getResourceName(), WDWebResourceType.XLS, true);

FileInputStream ss=(FileInputStream)wdContext.currentContextElement().getFileUploadUI().read(true);

Workbook workbook = Workbook.getWorkbook(ss);

// rest of the things you can done by http://jxl.sourceforge.net/javadoc/index.html

Regards,

Naga

Former Member
0 Kudos

Hi

Use the file upload to upload a file.

Regards

Ayyapparaj

Former Member
0 Kudos

hi

Check this link for reading excel files

Former Member
0 Kudos

<b>Hi

Thanks for the reply

But I can't find the link in your reply

Where is the link? plz provide that link

Regards

Chandran</b>

Former Member
0 Kudos

Sorry

arun_srinivasan
Contributor
0 Kudos

Hi,

Upload Excel file using File Upload UI

1)Add jxl jar folder in the lib folder of ur project.

2)Go to properties of ur project and add jar to ur project.

3)Using the File upload ui ,browse and upload the file.

4)Write the read file in to ur server location using fileoutput stream.

5)then using code u can read the excelfile from the server location itself.

Here is the code:

IWDAttributeInfo attInfo =wdContext.getNodeInfo().getAttribute("upload");

/** get the name of excel file and storing it in the server with the same name and extention****/

binaryType=IWDModifiableBinaryTypeattInfo.getModifiableSimpleType();

fileuploaded = binaryType.getFileName();

byte b[] = wdContext.currentContextElement().getUpload();

File filename =new File("

<Server name>
<folde name>
" + fileuploaded);

try {

FileOutputStream out = new FileOutputStream(filename);

out.write(b);

out.close();

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

/**Readind from the server**/

int iRows = 0;

try { Workbook wb = null;

Sheet sheet = null;

wb = Workbook.getWorkbook(filename);

sheet = wb.getSheet(0);

int iColumns = sheet.getColumns();

iRows = sheet.getRows();

int i = 0;

//get Cell contents by (COLUMN, ROW);

for (int r = 0; r < iRows; r++) {

for (int c = 0; c < iColumns; c++) {

Cell cell = sheet.getCell(c, r);

characterarray<i> = cell.getContents();

//wdComponentAPI.getMessageManager().reportSuccess("Row"r characterarray<i>);

i++;

}

}

wb.close();

Declare Globally

//@@begin others

String fileuploaded;

IWDModifiableBinaryType binaryType;

String characterarray[] = new String[1000];

//@@end

Also look at this blog too /people/perumal.kanthan/blog/2005/03/21/reading-excel-data-from-java-using-hssf-api

Thanks and Regards,

Arun

Former Member
0 Kudos

<b>Hi Arun

Thanks for your reply

According to your statement Copying the excel file to the server location and then accessing the file from the server.

Plz tell me whether this thing was possible or not. I want to read the data from the excel file which is in the local system.

Regards

Chandran</b>

Former Member
0 Kudos

Hi Chandran,

Hi,

First u should include jxl.jar API in ur classpath.

Create FileUpload UI and Upload button and bind an action.

Bind a Resource variable(type com.sap.ide.webdynpro.uielementdefinitions.Resource) to FileUpload UI. Then from the Fileupload UI, u can get the Sheet variable as

/****INSIDE ACTION OF UPLOAD************/

InputStream fis=wdContext.currentFileUploadElement().getResource().read(true);

Workbook wb=Workbook.getWorkbook(fis);

Sheet sh=wb.getSheet(0);

This can be easily read to a table by

for(int i=14;i<34;i++)

{

String bId=sh.getCell(2,i).getContents();

String cId=sh.getCell(3,i).getContents();

String subj=sh.getCell(4,i).getContents();

IPrivate<View>.I<Table>Element el=wdContext.node<Table>().create<Table>Element();

wdContext.node<Table>().addElement(el);

el.setBID(bid);

el.setCID(cid);

el.setSUB(subj);

}

This example reads the excel from row 13 to 32 and column 3 to 5 and uploaded to a table

Regards

Fahad Hamsa

arun_srinivasan
Contributor
0 Kudos

Hi chandran

I am copying the file from local file to server and i will read it from server

Yes my code will work, i am copying from local file system only. I used excel of .xls file

Thanks and Regards,

Arun