cancel
Showing results for 
Search instead for 
Did you mean: 

<htmlb:fileUpload>

Former Member
0 Kudos

Hi,

Iam uploading an Excel file from the local PC using the <htmlb:fileUpload>

I wanted to read this uploaded file and create a document with the data in the cells on the excel. When iam trying to read i get the data in numbers.

any ideas to read the uploaded file.

Thanks,

Shailaja

Accepted Solutions (1)

Accepted Solutions (1)

athavanraja
Active Contributor
0 Kudos

when you upload document using htmlb:fileUpload the uploaded content is in xstring format. convert the same to string format using FM

ECATT_CONV_XSTRING_TO_STRING

and then parse the string to get the desired result.

Regards

Raja

athavanraja
Active Contributor
0 Kudos

for a three column , text tab delimited excel file the oninputprocessing code would look like below.

DATA: fileupload TYPE REF TO cl_htmlb_fileupload.
data: content_length	TYPE	STRING,
file_content	TYPE	XSTRING ,
file_length	TYPE	STRING ,
file_mime_type	TYPE	STRING ,
file_name	TYPE	STRING .
DATA: content TYPE string.
DATA: conv TYPE REF TO cl_abap_conv_in_ce.
DATA: len TYPE i.
data: wa_text type string .
data: text_tab1 type standard table of string .
types: begin of excel_tab ,
       c1 type string ,
       c2 type string ,
       c3 type string ,
       end of excel_tab .
data: excel type standard table of excel_tab .
data: wa_excel like line of excel.

fileupload ?= cl_htmlb_manager=>get_data(
                       request = request
                       id      = 'myUpload'
                       name    = 'fileUpload' ).

file_name      = fileupload->file_name.
file_mime_type = fileupload->file_content_type.
file_length    = fileupload->file_length.
file_content   = fileupload->file_content.

conv = cl_abap_conv_in_ce=>create( input = file_content ).
conv->read( IMPORTING data = content len = len ).
split content at cl_abap_char_utilities=>cr_lf into table text_tab1 .

clear wa_text .
loop at text_tab1 into wa_text .
split wa_text at cl_abap_char_utilities=>HORIZONTAL_TAB into wa_excel-c1 wa_excel-c2 wa_excel-c3 .
append wa_excel to excel .

endloop .

Regards

Raja

Former Member
0 Kudos

Hi Raja,

Thanks for your response. I tried to use this FM but says it doesnot exists. And to your code, i still get different string values (might b XSTRING).

Any help would be appreciated.

Thanks,

Shailaja

athavanraja
Active Contributor
0 Kudos

the code sample i have provided is for a <b>Text Tab Delimited Excel file</b>.

did you try it with text tab delimited excel file? i have tested it before posting the code.

Regards

Raja

Former Member
0 Kudos

Thanks Raja,

I didnt tried with the Tab delimites excel file. It works thanks again.

Regards,

Shailaja

Former Member
0 Kudos

Hi Durai,

Nice to contact you again.

i am approching the same way and but my file is in .xls

format.(initially my customers download PO Data into

excel file(.xls) and if needs they will change some

data in the download file and again they will upload

the data.

here while uploading data from excel using <htmlb:fileupload> i am getting all junk data...

how can i overcome from this..

Thanks,

Leo

athavanraja
Active Contributor
0 Kudos

what do you want to do with the uploaded excel content,

a) store it as a file - no problem

b) parse it to read cell values and populate, then your option is to go only for csv or text tab delimited file

Regards

Raja

Former Member
0 Kudos

Assume that i have my data in Excel sheet on my local PC

Purchase Order data

Order Item Supplier Material

ORD100 10 S222 Mat100

ORD101 20 S223 Mat101

ORD102 30 S224 Mat102

ORD103 40 S225 Mat103

Now i want to upload the above file using <htmlb:fileupload>

a) store it as a file - no problem

For that i am doing as below but i am getting junk data

IF event->id = 'subButton' AND event->event_type = 'click'.

data ?= CL_HTMLB_MANAGER=>GET_DATA( request = runtime->server->request

name = 'fileUpload'

id = 'fileUp' ).

IF data IS NOT INITIAL.

lv_name = data->file_name.

lv_content = data->file_content.

lv_length = data->file_length.

lv_contype = data->file_content_type.

The below two stmts are not working if the file extension is .XLS

  • conv = cl_abap_conv_in_ce=>create( input = v_content ).

  • conv->read( IMPORTING data = lv_str ).

ENDIF.

Now i have my content in XTRING Format and i am converting

XTRING TO BINARY

IF NOT lv_content IS INITIAL.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

EXPORTING

BUFFER = lv_content

APPEND_TO_TABLE = 'X'

IMPORTING

OUTPUT_LENGTH = file_len

TABLES

BINARY_TAB = lt_tabbin .

CLEAR lv_file.

lv_file = 'test.xls'.

CONCATENATE sy-uname '_' lv_file INTO lv_file.

TRANSLATE lv_file TO LOWER CASE.

OPEN DATASET lv_file FOR OUTPUT IN BINARY MODE.

LOOP AT lt_tabbin INTO ls_tabbin.

TRANSFER ls_tabbin TO lv_file.

ENDLOOP.

CLOSE DATASET lv_file.

When i check my file in AL11 Transaction

###?##################>#####################################################

#8#######X#@###########"#######################1################X##A#r#i#a#l

######Sheet3################"##################Purchase Order data###Order##

##########a##

###########

###########

###########

###########

###########

##########~#

b) parse it to read cell values and populate, then your option is to go only for csv or text tab delimited file

Suppose this is the case and if i want to store data with csv or text tab delimited as you told

what should i do next..?

IF event->id = 'subButton' AND event->event_type = 'click'.

data ?= CL_HTMLB_MANAGER=>GET_DATA( request = runtime->server->request

name = 'fileUpload'

id = 'fileUp' ).

IF data IS NOT INITIAL.

lv_name = data->file_name.

lv_content = data->file_content.

lv_length = data->file_length.

lv_contype = data->file_content_type.

(after getting xtring how can i parse them to read cell values and store it them as csv or text tab)

if you fell free give some example code...

Thanks Durai,

Leo

Answers (0)