Skip to Content

Convert XLSX to CSV in frontend and send to backend.

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

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • Best Answer
    Jan 10 at 09:45 AM

    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!
    
    Add comment
    10|10000 characters needed characters exceeded

  • Dec 06, 2018 at 11:06 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • 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