Выгрузка в Excel через cl_fdt_xl_spreadsheet
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
TRY. SELECT * FROM sflight INTO TABLE @DATA(lt_sflight). IF sy-subrc = 0. DATA: it_columns TYPE if_fdt_doc_spreadsheet=>t_column. DATA: lv_head TYPE sflight. DATA(o_desc) = CAST cl_abap_structdescr( cl_abap_structdescr=>describe_by_data( lv_head ) ). LOOP AT o_desc->get_components( ) ASSIGNING FIELD-SYMBOL(<c>). IF <c> IS ASSIGNED. IF <c>-type->kind = cl_abap_typedescr=>kind_elem. APPEND VALUE #( id = sy-tabix name = <c>-name display_name = <c>-name is_result = abap_true type = <c>-type ) TO it_columns. ENDIF. ENDIF. ENDLOOP. DATA(lv_bin_data) = cl_fdt_xl_spreadsheet=>if_fdt_doc_spreadsheet~create_document( columns = it_columns " optional itab = REF #( lt_sflight ) iv_call_type = if_fdt_doc_spreadsheet=>gc_call_dec_table ). IF xstrlen( lv_bin_data ) > 0. DATA: lv_action TYPE i. DATA: lv_filename TYPE string. DATA: lv_fullpath TYPE string. DATA: lv_path TYPE string. cl_gui_frontend_services=>file_save_dialog( EXPORTING default_file_name = 'Excel.xlsx' default_extension = 'xlsx' file_filter = |Excel-Datei (*.xlsx)\|*.xlsx\|{ cl_gui_frontend_services=>filetype_all }| CHANGING filename = lv_filename path = lv_path fullpath = lv_fullpath user_action = lv_action ). IF lv_action EQ cl_gui_frontend_services=>action_ok. DATA(it_raw_data) = cl_bcs_convert=>xstring_to_solix( EXPORTING iv_xstring = lv_bin_data ). cl_gui_frontend_services=>gui_download( EXPORTING filename = lv_fullpath filetype = 'BIN' bin_filesize = xstrlen( lv_bin_data ) CHANGING data_tab = it_raw_data ). ENDIF. ENDIF. ENDIF. CATCH cx_root INTO DATA(e_text). MESSAGE e_text->get_text( ) TYPE 'I'. ENDTRY. |