*----------------------------------------------------------------------* * DECLARATIONS * *----------------------------------------------------------------------* DATA gt_spfli TYPE STANDARD TABLE OF spfli. *----------------------------------------------------------------------* * LAYOUT * *----------------------------------------------------------------------* PARAMETERS: pa_file(255) TYPE c LOWER CASE. *----------------------------------------------------------------------* * PROGRAM BODY * *----------------------------------------------------------------------* START-OF-SELECTION. SELECT * FROM spfli INTO TABLE gt_spfli. END-OF-SELECTION. PERFORM export_xlsx. *----------------------------------------------------------------------* * FORM EXPORT_XLSX * *----------------------------------------------------------------------* FORM export_xlsx. *dichiarazioni DATA: lt_fcat TYPE lvc_t_fcat, lt_data TYPE REF TO data, lv_flavour TYPE string, lv_version TYPE string, lo_result_data TYPE REF TO cl_salv_ex_result_data_table, lo_columns TYPE REF TO cl_salv_columns_table, lo_aggreg TYPE REF TO cl_salv_aggregations, lo_salv_table TYPE REF TO cl_salv_table, lv_file_type TYPE salv_bs_constant, ls_layout TYPE lvc_s_layo, lt_sort TYPE lvc_t_sort, lt_filt TYPE lvc_t_filt, lv_xstring TYPE xstring, lv_size TYPE i, lt_bintab TYPE solix_tab, lv_path TYPE string. FIELD-SYMBOLS: <lf_tab> TYPE ANY TABLE. *alv semplice GET REFERENCE OF gt_spfli INTO lt_data. ASSIGN lt_data->* TO <lf_tab>. TRY . cl_salv_table=>factory( EXPORTING list_display = abap_false IMPORTING r_salv_table = lo_salv_table CHANGING t_table = <lf_tab> ). CATCH cx_salv_msg. ENDTRY. *colonne, aggregati e fieldcatalog lo_columns = lo_salv_table->get_columns( ). lo_aggreg = lo_salv_table->get_aggregations( ). lt_fcat = cl_salv_controller_metadata=>get_lvc_fieldcatalog( r_columns = lo_columns r_aggregations = lo_aggreg ). IF cl_salv_bs_a_xml_base=>get_version( ) = if_salv_bs_xml=>version_25 OR cl_salv_bs_a_xml_base=>get_version( ) = if_salv_bs_xml=>version_26. *genera i dati dal modello lo_result_data = cl_salv_ex_util=>factory_result_data_table( r_data = lt_data s_layout = ls_layout t_fieldcatalog = lt_fcat t_sort = lt_sort t_filter = lt_filt ). *impostazioni varie CASE cl_salv_bs_a_xml_base=>get_version( ). WHEN if_salv_bs_xml=>version_25. lv_version = if_salv_bs_xml=>version_25. WHEN if_salv_bs_xml=>version_26. lv_version = if_salv_bs_xml=>version_26. ENDCASE. lv_file_type = if_salv_bs_xml=>c_type_xlsx. lv_flavour = if_salv_bs_c_tt=>c_tt_xml_flavour_export. *trasformazione dei dati in Excel cl_salv_bs_tt_util=>if_salv_bs_tt_util~transform( EXPORTING xml_type = lv_file_type xml_version = lv_version r_result_data = lo_result_data xml_flavour = lv_flavour gui_type = if_salv_bs_xml=>c_gui_type_gui IMPORTING xml = lv_xstring ). ENDIF. IF lv_xstring IS NOT INITIAL. *conversione in binario CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' EXPORTING buffer = lv_xstring IMPORTING output_length = lv_size TABLES binary_tab = lt_bintab. *salvataggio del file xlsx OPEN DATASET pa_file FOR OUTPUT IN BINARY MODE. CHECK sy-subrc = 0. TRANSFER lv_xstring TO pa_file. CLOSE DATASET pa_file. ENDIF. ENDFORM. *----------------------------------------------------------------------*
martedì 5 settembre 2017
Salvare una tabella interna in un file XLSX in background
Iscriviti a:
Commenti sul post (Atom)
Nessun commento:
Posta un commento