cancel
Showing results for 
Search instead for 
Did you mean: 

Upload .xls file in internal table in web dynpro abap

Former Member
0 Kudos

Hi everyone,

i want to upload .xls(excel file) into an internal table.....after lots of attempts i came to a conclusion that web dynpro only supports .CSV(another format of excel file) to be uploaded into internal table....i tried many ways....is there a way i can upload .xls file...kindly help me in the same. following is the code i m using

DATA LO_EL_CONTEXT TYPE REF TO IF_WD_CONTEXT_ELEMENT.

DATA LS_CONTEXT TYPE WD_THIS->ELEMENT_CONTEXT.

DATA ITEM_FILE TYPE WD_THIS->ELEMENT_CONTEXT-EXCEL_UPLOAD.

  • get element via lead selection

LO_EL_CONTEXT = WD_CONTEXT->GET_ELEMENT( ).

  • @TODO handle not set lead selection

IF LO_EL_CONTEXT IS INITIAL.

ENDIF.

  • get single attribute

LO_EL_CONTEXT->GET_ATTRIBUTE(

EXPORTING

NAME = `EXCEL_UPLOAD`

IMPORTING

VALUE = ITEM_FILE ). "xstring format

DATA S_CONT TYPE STRING.

DATA CONVT TYPE REF TO CL_ABAP_CONV_IN_CE.

DATA: FIELDS1 TYPE STRING_TABLE.

1st tried this code-> using "cl_abap_conv_in_ce"

CALL METHOD cl_abap_conv_in_ce=>create

EXPORTING

*encoding = c_encoding "optional

input = ITEM_FILE

RECEIVING

conv = CONVT.

CALL METHOD CONVT->read

IMPORTING

data = S_CONT.

when it didnt work out...then tried followin function module

CALL FUNCTION 'HR_KR_XSTRING_TO_STRING'

EXPORTING

IN_XSTRING = ITEM_FILE "xsrting

IMPORTING

OUT_STRING = S_CONT

.

TYPES: BEGIN OF TY_TAB,

NAME_CHAR TYPE STRING,

DESCR_CHAR TYPE STRING,

NUMBER_DIGITS TYPE STRING,

END OF TY_TAB.

DATA: FIELDS TYPE STRING_TABLE.

DATA: LV_FIELD TYPE STRING.

DATA: S_TABLE TYPE STRING_TABLE.

DATA: ITAB TYPE TABLE OF TY_TAB.

DATA: STR_ITAB TYPE TY_TAB.

*splits string based on new line

SPLIT S_CONT AT CL_ABAP_CHAR_UTILITIES=>CR_LF INTO TABLE S_TABLE.

FIELD-SYMBOLS: <WA_TABLE> LIKE LINE OF S_TABLE.

LOOP AT S_TABLE ASSIGNING <WA_TABLE>.

  • splits string on basis of tabs

SPLIT <WA_TABLE> AT ',' INTO

STR_ITAB-NAME_CHAR

STR_ITAB-DESCR_CHAR

STR_ITAB-NUMBER_DIGITS.

APPEND STR_ITAB TO ITAB.

ENDLOOP.

I am able to do the uploading if the file is in .CSV format and not .XLS format....

there are lots of forums on SDN for the same....but at the end there is no solution provided.....

experts kindly solve it this time...thanks in advance

Accepted Solutions (1)

Accepted Solutions (1)

gill367
Active Contributor
0 Kudos

Yeah that is true ...

If you search online you fill find lots of examples for uploading an tab limited file only.

XL file needs to be converted to .txt format for it to be read using the Xstring data type.

may be in the future relases we can have this functionality but right now its not possible easily.

i read some where about xml to do the conversion in for you and then you can upload file as xls.

Thanks

Sarbjeet Singh

Answers (3)

Answers (3)

sahai
Contributor
0 Kudos

hi,

the xl file cannot be uploaded directly it should be converted either to text or .csv format to get it uploaded.

thanks

sahai.s

Former Member
0 Kudos

@sarbjeet

i hav also read about XML conversion part....

bt are you aware how to use it?

did u ever try usin it?......kindly post here the procedure or code or process to follow the same...

former_member206441
Contributor
0 Kudos

Hi,

It is not possible to upload an xls file because it will be having some binary characters. better to go with .csv file format.

Refer this [link too|] it will explain you clearly.

Regards

Arun.P