cancel
Showing results for 
Search instead for 
Did you mean: 

Use Excel file as resource in Web Dynpro

former_member182374
Active Contributor
0 Kudos

Hi All,

I have a Web Dynpro project which reads from a constant excel file.

If I put the excel file somewhere in the server's file system I can read it without a problem.

However, I want the file to be embedded in the WD project.

Where do I need to put the file and how can I access it from Web Dynpro?

I try to put it in

<Project> -> src -> mimes -> Components -> <component name> -> <excel file>

but it didn't work

Thanks,

Omri

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

You have placed the file in the right location. In Webdynpro use:


InputStream templateInputStream = this.getClass().getClassLoader().getResourceAsStream("xyz.xls");

Regards

Sebastian

former_member182374
Active Contributor
0 Kudos

Hi Sebastian,

I tried using the following code:

<i>InputStream templateInputStream = this.getClass().getClassLoader().getResourceAsStream("myfile1213.csv");

InputStreamReader is = new InputStreamReader(templateInputStream,"windows-1255");

excelData = CSVParser.parse(is);</i>

and then print the content of the excelData.

I don't get an exception but the file isn't being parsed.

I found out that the location of the file is:

http://<server name>:<port>/webdynpro/resources/local/<project name>/Components/<component name>/<my file name>

How can I generate this URL in Web Dynpro?

Omri

Former Member
0 Kudos

Hi,

Your files should go here:

Project->src->mimes->Components-><your component>->file(say abc.csv).

You can do all this through the Navigator view of your NWDS.

Now you can read it as follows:


try{
String path = WDURLGenerator.getResourcePath(  wdComponentAPI.getDeployableObjectPart(),  "abc.csv");

FileReader f 		= new FileReader(path);
BufferedReader r	= new BufferedReader(f);
//Do further processing...
}
catch(WDAliasResolvingException e3){
}
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

Regards,

Satyajit.

Former Member
0 Kudos

Perhaps there is something wrong with the CSV parser. First of all try to print the file content without parsing it:


InputStream templateInputStream = this.getClass().getClassLoader().getResourceAsStream("xyz.csv");
ByteArrayOutputStream templateOutputStream = new ByteArrayOutputStream();
IOUtil.write(templateInputStream, templateOutputStream);
String test = new String(templateOutputStream.toByteArray());

// output the string in your application

Regards

Sebastian

former_member182374
Active Contributor
0 Kudos

Thanks Satyajit Chakraborty

Problem solved

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Omri,

As you mentioned in the first line "

If I put the excel file somewhere in the server's file system I can read it without a problem.".

My scenario is also like this only where in i am getting the path something like this .....usr\sap\server\....filename.doc.

I have placed this file there and now i want to read the whole contents of this into an internal table. Could you please provide me the sample code for this would be highly apreciable as i want to read this code into an internal table and send the same to the RFC at the backend.

Former Member
0 Kudos

Hi Cohen,

You can also use the Excel file by creating a Resource Bundle.

You can create a resource BUndle by performing the following.

1. Add a new directory resource to the directory src/packages/",

this.getClass().getClassLoader());

resourceHandlerForQuestions.get();

Thanks,

Pavan