Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Issue with upload excel data to internal table in web dynpro

former_member383962
Participant
0 Likes
1,018

Hello Experts,

I tried to upload excel data to internal table in web dynpro.

But when i get data from the excel that first row which is header for the data is aslo comes along as a record.

Code which i tried:

* ---navigate from <CONTEXT> to <FILE_UPLOAD> via lead selection

  lo_nd_file_upload = wd_context->get_child_node( NAME = wd_this->wdctx_upload ).

* ---get element via lead selection

  lo_el_file_upload = lo_nd_file_upload->get_element( ).

* ---get all declared attributes

  lo_el_file_upload->get_static_attributes(
    IMPORTING
      static_attributes = ls_file_upload ).
  TRY.
*     Create object of class to read .xlsx file contents
      CREATE OBJECT lref_excel
        EXPORTING
          document_name = ls_file_upload-file_name
          xdocument     = ls_file_upload-file_content.

    CATCH cx_fdt_excel_core INTO lref_excel_core.
      CLEAR lv_msg.

*     Call method to get error message text

      CALL METHOD lref_excel_core->if_message~get_text
        RECEIVING
          RESULT = lv_msg.
*<< Display error message returned in lv_msg >>
      RETURN.
  ENDTRY.

* Call method to get list of worksheets in the .xlsx file

  lref_excel->if_fdt_doc_spreadsheet~get_worksheet_names(
      IMPORTING
        worksheet_names = lt_worksheets ).
* Condition to check whether .xlsx file has any active worksheets

  IF lt_worksheets IS NOT INITIAL.
*   Read active worksheet
    READ TABLE lt_worksheets INDEX 1 INTO lv_name.
  ELSE.
*<< Display error message >>
    RETURN.
  ENDIF.

* Get reference of .xlsx file contents in the active worksheet
  lref_data = lref_excel->if_fdt_doc_spreadsheet~get_itab_from_worksheet( lv_name ).
* Fetch all records in the active worksheet
  ASSIGN lref_data->* TO <fs_temp_tbl>.

so,i planned to delete the first record which is header. and tried to move to my destination <field_symbol_table> . but that the structure of <fs_temp_tbl> is different.so that i can't able to move the records to my destination table.

My actual destination structure:

In many blogs says use Fm:'HR_KR_XSTRING_TO_STRING'. but it wont works for me.. it dumps the records into something like special characters.

is there is any other ways to achieve it.

Thanks in advance.

Hello Experts,

I tried to upload excel data to internal table in web dynpro.

But when i get data from the excel that first row which is header for the data is aslo comes along as a record.

Code which i tried:

* ---navigate from <CONTEXT> to <FILE_UPLOAD> via lead selection

  lo_nd_file_upload = wd_context->get_child_node( NAME = wd_this->wdctx_upload ).

* ---get element via lead selection

  lo_el_file_upload = lo_nd_file_upload->get_element( ).

* ---get all declared attributes

  lo_el_file_upload->get_static_attributes(
    IMPORTING
      static_attributes = ls_file_upload ).
  TRY.
*     Create object of class to read .xlsx file contents
      CREATE OBJECT lref_excel
        EXPORTING
          document_name = ls_file_upload-file_name
          xdocument     = ls_file_upload-file_content.

    CATCH cx_fdt_excel_core INTO lref_excel_core.
      CLEAR lv_msg.

*     Call method to get error message text

      CALL METHOD lref_excel_core->if_message~get_text
        RECEIVING
          RESULT = lv_msg.
*<< Display error message returned in lv_msg >>
      RETURN.
  ENDTRY.

* Call method to get list of worksheets in the .xlsx file

  lref_excel->if_fdt_doc_spreadsheet~get_worksheet_names(
      IMPORTING
        worksheet_names = lt_worksheets ).
* Condition to check whether .xlsx file has any active worksheets

  IF lt_worksheets IS NOT INITIAL.
*   Read active worksheet
    READ TABLE lt_worksheets INDEX 1 INTO lv_name.
  ELSE.
*<< Display error message >>
    RETURN.
  ENDIF.

* Get reference of .xlsx file contents in the active worksheet
  lref_data = lref_excel->if_fdt_doc_spreadsheet~get_itab_from_worksheet( lv_name ).
* Fetch all records in the active worksheet
  ASSIGN lref_data->* TO <fs_temp_tbl>.

so,i planned to delete the first record which is header. and tried to move to my destination <field_symbol_table> . but that the structure of <fs_temp_tbl> is different.so that i can't able to move the records to my destination table.

My actual destination structure:

In many blogs says use Fm:'HR_KR_XSTRING_TO_STRING'. but it wont works for me.. it dumps the records into something like special characters.

is there is any other ways to achieve it.

Thanks in advance.

0 REPLIES 0