*&---------------------------------------------------------------------* *& Report ZIFE_TEST_EXCEL *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT zdemo_excel4. DATA: lo_excel TYPE REF TO zcl_excel, lo_excel_writer TYPE REF TO zif_excel_writer, lo_worksheet TYPE REF TO zcl_excel_worksheet, lo_hyperlink TYPE REF TO zcl_excel_hyperlink. DATA: lv_file TYPE xstring, lv_bytecount TYPE i, lt_file_tab TYPE solix_tab. DATA: lv_file_name TYPE string, lv_file_path TYPE string, lv_full_path TYPE string, lv_workdir TYPE string, lv_file_separator TYPE c. CONSTANTS: lv_default_file_name TYPE string VALUE '04_Sheets.xlsx'. PARAMETERS: p_path TYPE string. AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path. cl_gui_frontend_services=>directory_browse( EXPORTING initial_folder = p_path CHANGING selected_folder = p_path ). INITIALIZATION. cl_gui_frontend_services=>get_sapgui_workdir( CHANGING sapworkdir = lv_workdir ). p_path = lv_workdir. START-OF-SELECTION. IF p_path IS INITIAL. p_path = lv_workdir. ENDIF. cl_gui_frontend_services=>get_file_separator( CHANGING file_separator = lv_file_separator ). CONCATENATE p_path lv_file_separator lv_default_file_name INTO p_path. " Creates active sheet CREATE OBJECT lo_excel. " Get active sheet lo_worksheet = lo_excel->get_active_worksheet( ). lo_worksheet->set_title( ip_title = 'Sheet1' ). lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = 'This is the first sheet' ). lo_hyperlink = zcl_excel_hyperlink=>create_internal_link( iv_location = 'Sheet2!B2' ). lo_worksheet->set_cell( ip_column = 'B' ip_row = 3 ip_value = 'This is link to second sheet' ip_hyperlink = lo_hyperlink ). lo_worksheet->sheet_setup->set_page_margins( ip_header = '1' ip_footer = '1' ip_unit = 'cm' ). lo_worksheet->sheet_setup->black_and_white = 'X'. lo_worksheet->sheet_setup->fit_to_page = 'X'. " you should turn this on to activate fit_to_height and fit_to_width lo_worksheet->sheet_setup->fit_to_height = 0. " used only if ip_fit_to_page = 'X' lo_worksheet->sheet_setup->fit_to_width = 2. " used only if ip_fit_to_page = 'X' lo_worksheet->sheet_setup->orientation = zcl_excel_sheet_setup=>c_orientation_landscape. lo_worksheet->sheet_setup->page_order = zcl_excel_sheet_setup=>c_ord_downthenover. lo_worksheet->sheet_setup->paper_size = zcl_excel_sheet_setup=>c_papersize_a4. lo_worksheet->sheet_setup->scale = 80. " used only if ip_fit_to_page = SPACE lo_worksheet = lo_excel->add_new_worksheet( ). lo_worksheet->set_title( ip_title = 'Sheet2' ). lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = 'This is the second sheet' ). lo_hyperlink = zcl_excel_hyperlink=>create_internal_link( iv_location = 'Sheet1!B2' ). lo_worksheet->set_cell( ip_column = 'B' ip_row = 3 ip_value = 'This is link to first sheet' ip_hyperlink = lo_hyperlink ). CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007. lv_file = lo_excel_writer->write_file( lo_excel ). * Convert to binary lt_file_tab = cl_bcs_convert=>xstring_to_solix( iv_xstring = lv_file ). lv_bytecount = XSTRLEN( lv_file ). " Save the file cl_gui_frontend_services=>gui_download( EXPORTING bin_filesize = lv_bytecount filename = p_path filetype = 'BIN' CHANGING data_tab = lt_file_tab ).