cancel
Showing results for 
Search instead for 
Did you mean: 

Convert XLSX to CSV in frontend and send to backend.

agrawalaadhar8
Participant

Hi,

I am uploading an xlsx file to my file uploader. The file then goes to the backend through gateway.

Is there any way I can convert the file to csv in my controller and then send csv to backend?

Please Help

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

agrawalaadhar8
Participant

Mahesh's Answer worked for me.:

Thanks Mahesh 🙂

you need set the property for the file uploader:
useMultipart="false" // This needs to be false else the data is uploaded as multiform type instead of excel type
If you would have use uploadcollection it works by default.
PS: I've spent at least 2 hours to replicate and find this issue reason and at the end I found it is a very minor issue. Great learning for me as well!

Answers (1)

Answers (1)

maheshpalavalli
Active Contributor

Hi Shubh,

you can use opensource libraries to convert the XLSX file to CSV file.. one such popular library:

https://github.com/SheetJS/js-xlsx

Or you can do it in the backend itself:


// LV_Content should be xstring format
        DATA(lr_excel) = NEW cl_fdt_xl_spreadsheet( document_name = iv_file_name xdocument = lv_content ).

        IF lr_excel IS BOUND.

          lr_excel->if_fdt_doc_spreadsheet~get_worksheet_names( IMPORTING worksheet_names = DATA(lt_worksheets) ).

        ENDIF.



DATA(lr_worksheet_itab) = lr_excel->if_fdt_doc_spreadsheet~get_itab_from_worksheet( lo_worksheets->* ). // Pass worksheet name, will return dynamic data

      ASSIGN lr_worksheet_itab->* TO <ft_excel_data>.

BR,

Mahesh

agrawalaadhar8
Participant
0 Kudos

Hi I am trying the below code but it is giving dump on line 1 .Error=> "Invalid File Format".

is_media_resource-value has xstring value only.

Please Help

DATA(lr_excel) = NEW cl_fdt_xl_spreadsheet( document_name = iv_name xdocument = is_media_resource-value ).

      IF lr_excel is BOUND.
        lr_excel->if_fdt_doc_spreadsheet~get_worksheet_names( IMPORTING worksheet_names = DATA(lt_worksheets) ).
      ENDIF.
maheshpalavalli
Active Contributor
0 Kudos

It accepts the xstring format only.. so sure you are passing the xstring data to it.. You need to check what kind of data you are passing from the UI to the backend.

BR,

Mahesh

agrawalaadhar8
Participant
0 Kudos

I am passing XSTRING only.

Check Image

maheshpalavalli
Active Contributor
0 Kudos

Hi Shubh Agarwal,

you need set the property for the file uploader:

useMultipart="false" // This needs to be false else the data is uploaded as multiform type instead of excel type

If you would have use uploadcollection it works by default.

PS: I've spent at least 2 hours to replicate and find this issue reason and at the end I found it is a very minor issue. Great learning for me as well!

BR,

Mahesh