cancel
Showing results for 
Search instead for 
Did you mean: 

Excel download... and upload?

Former Member
0 Kudos

Hello everyone,

I'm using the web dynpro binary cache, as explained in sap tutorials, to download the content of a UI table to an excel file. Is there any form of doing the opposite? I mean, i would like to upload several columns of data from an excel file to multiple value attributes of a context node.

Is this possible??

Other problem i'm having is that when i download the data to the excel file all columns appear on an order that i don't want. How can i control the order of the columns in the excel file, when downloading it from web dynpro?

thank you everyone,

Nuno

Accepted Solutions (1)

Accepted Solutions (1)

vijayakhanna_raman
Active Contributor
0 Kudos

Hi,

I can give solution to Upload Excel file.

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

Regards,

Vijayakhanna Raman

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Vijayakhanna,

I am working in NW04s . i tried the solution suggested by you:

for uploading the excel file and then tried to create this excel file on the server and reading data from excel sheet into context. But in NW04s, we have a to set property 'Resource' of type - context attribute(IWDResource) for FileUpload UI Element - Resource which is of the type IWDResouce.

Upload is successfull.

I created a object of FileOutputStream

FileOutputStream fo = new FileOutputStream(l_filename);

This file gets created successfully on the server.

Now, i am trying to write contents in this file using the following statement:

fo.write(wdContext.currentContextElement().getResource().toString().getBytes());

where Resource is a context attribute of type - IWDResource.

The problem is: file created on the server doesnot contain the data uploaded by the user. And hence, it gives an error while reading the file.

Can you help me in extracting the data from context attribute 'Resource' and then writing into the file???

Thanks for help.

Regards,

Rashmi

Former Member
0 Kudos

Hi ,

Foe excel upload use FileUpload control to upload file .And use POI API to read excel file.

Go through this blog.

/people/perumal.kanthan/blog/2005/03/21/reading-excel-data-from-java-using-hssf-api

Regards,

Rajeev

Former Member
0 Kudos

Hello Rajeev,

Thank you very much for your feedback. I'm still having a problem, though. I tried what is explained in the blog in a java project and it works fine. But when i try to do the same in the webdynpro, i get the message:

java.lang.NoClassDefFoundError: org/apache/poi/hssf/usermodel/HSSFWorkbook

I think it's because the server doesn't know the POI API. I added the jar's externally, as explained in the blog, but that doesn't seems to be enough. What else do i have to do ?

Thanks in advance,

Nuno

Former Member
0 Kudos

Hi,

1.You have to add this jar to lib folder under the root of your project.

2.right click on your project ,go to properties->Java build path -> Libraries ->add external jars add there the POI JARS.

Hope this will help you.

Regards,

Rajeev