cancel
Showing results for 
Search instead for 
Did you mean: 

Transfer XLS File Data into Dynpro table Using File Upload Element

Former Member
0 Kudos

Hello All,

I was trying to upload the XLS file using FILEUPLOAD Element and then transfer the data of File from XLS to Dynpro Table Element. Resource data type in not available in dictionary Type in my NWDS, I have bind the resource type property of FILEUPLOAD Element with Binary data type.

When I am geting the resource path like ".\temp\webdynpro\web\sap.com\usrupdt\Components\com.sap.UpdateUserRoles\TestFile.xls". When trying to read the file, it is giving me FILE NOT FOUNF exception.

WD INIT Method:

IWDAttributeInfo attInfo = wdContext.getNodeInfo().getAttribute(IPrivateUpdateUserRolesView.IContextElement.FILE_RESOURCE);

attInfo.getModifiableSimpleType();

FILE UPLOAD and READ Method:

boolean uploadStatus = true;

byte[] csvFileArray;

String CSVFilePath = null;

String CSVFileName = null;

IWDAttributeInfo attInfo = wdContext.getNodeInfo().getAttribute(IPrivateUpdateUserRolesView.IContextElement.FILE_RESOURCE);

IWDModifiableBinaryType FileResurceType = (IWDModifiableBinaryType) attInfo.getModifiableSimpleType();

IPrivateUpdateUserRolesView.IContextElement eleUpload = wdContext.currentContextElement();

try {

if (eleUpload.getFileResource() != null) {

String mimeType = FileResurceType.getMimeType().toString();

CSVFileName = FileResurceType.getFileName();

FileResurceType.setMimeType(WDWebResourceType.XLS);

FileResurceType.setFileName(CSVFileName);

CSVFilePath = WDURLGenerator.getResourcePath(wdComponentAPI.getDeployableObjectPart(), CSVFileName);

Workbook w = Workbook.getWorkbook(new File(CSVFilePath));

Sheet sh = w.getSheet(0);

int cols = sh.getColumns();

int rows = sh.getRows();

String s1 = null;

String s2 = null;

for (int i = 0; i < rows; i++) {

s1 = sh.getCell(0, i).getContents();

s2 = sh.getCell(1, i).getContents();

}

} else {

uploadStatus = false;

this.ConfirmationPopUp("Please Select File to Upload.");

}

} catch (Exception e) {

throw new WDRuntimeException(e);

} finally {

return uploadStatus;

}

My question is:

1) Is it possible to read file Data, when File is uploaded using Binary Data Type.

2) Is there any sample code available for that?

3) If It is only possible using Resource dictionary Type, then how to add this library in web dynpro project.

Accepted Solutions (0)

Answers (1)

Answers (1)

Qualiture
Active Contributor
0 Kudos

Hi,

Have a look at the blog at http://wiki.sdn.sap.com/wiki/display/WDJava/UploadingexcelfileusingWebDynproforJava

It has a pretty thorough step-by-step explanation on how to upload and read an Excel file.

Please note the above blog uses the JExcelApi (http://www.andykhan.com/jexcelapi/) but it seems from your code you already use it as well.

Hope this helps,

Robin van het Hof

Former Member
0 Kudos

Thanks Robin..For Your Reply.

In my NWDS environment, I do have Resource Type in Dictionary Simple Type.

Do you have Idea, How/Where to get the JAR file for this Dictionary Simple Type.

Many Thanks In Advance.

Regards,

Pankaj Singh

Qualiture
Active Contributor
0 Kudos

Hi,

I'm not sure if I understand correctly... if you need to include the jexcelapi jar files to you WD project, I would recommend creating a new External Library DC, which contains the jar files (see http://help.sap.com/saphelp_nw70/helpdata/en/5a/2e2f4234135433e10000000a155106/frameset.htm on how to create an External Library DC)

Then add the public part to your applications Used DC

Hope this explains

Robin

Former Member
0 Kudos

Thanks Robin for all your support.

I am able to use jexcelapi jar files by adding it as an External Library DC.

But My problem is lying with FILE UPLOAD Element. It has two properties.

1) Data ->> Should be binded with View Context Element of Type RESOURCE

2) FileName ->> Should be binded with View Context Element of STRING

But Type Resource is not available in list of com.sap.ide.webdynpro.uielementdefinitions in Local Dictionary.

So I have binded the Data property of FILE UPLOAD Element with View Context Element of Type BINARY.

Do you have any Idea, How to transfer the XLS File Data to dynpro table in this type of scenario.

Many Thanks In Advance.

Regards,

Pankaj Singh

Qualiture
Active Contributor
0 Kudos

Hi Pankaj,

I have checked myself, and I can see type 'Resource' listed under com.sap.ide.webdynpro.uielementdefinitions when defining a new Simple Type...

Which NWDS version are you using?

Best,

Robin

Former Member
0 Kudos

Hello Robin,

I am using the following version of NWDS.

Version: 2.0.19

Build id: 200610270428

JDK Version is : j2sdk1.4.2_18

Is it the right version Or I need to upgrade my support pack.

If It is the right version version. Then Do I need to add some additional DC from from sap.com_SAP_BUILDT_1 / sap.com_SAP-JEE_1 as used DC to get Resource datatype in UIELEMENT definition List.

Regards,

Pankaj Singh

Qualiture
Active Contributor
0 Kudos

Hi,

I did a quick search on SDN, and it seems a few more people are suffering from missing Resource type (or missing com.sap.webdynpro.uielementdefinitions from the list completely)

I couldn't find a suitable OSS note too, so I would suggest opening a message to SAP support

Former Member
0 Kudos

Hi all,

Resource type is part of javanative type not part of Dictionary simple type .

please search in Java native type.

Regards,

Govindu

Qualiture
Active Contributor
0 Kudos

Hi Govindu,

I'm afraid that's not true. See API for IWDResource at http://help.sap.com/javadocs/nwce/current/wdr/com.sap.wdr/com/sap/tc/webdynpro/services/sal/datatran... :

This interface represents a general resource with a name a MIME-type and binary data. Its binary representation is an InputStream that can be read. Each resource is available by a specific URL. This type can be bound to the property resource of the UI elements FileUpload and FileDownload.

Note that Web Dynpro does not hold a reference to the resource. The application is required to hold one itself. This is typically done via a context attribute with a predefined data type "com.sap.ide.webdynpro.uielementdefinitions.Resource".