From b0b4abea7638fe873e916f5758c027f7242f01ff Mon Sep 17 00:00:00 2001 From: Rene Turnheim Date: Sat, 17 Mar 2012 16:46:49 +0000 Subject: [PATCH] Demo convert for #143; Changed DEMO32 and included two examples; bind alv and converter export git-svn-id: https://subversion.assembla.com/svn/abap2xlsx/trunk@267 b7d68dce-7c3c-4a99-8ce0-9ea847f5d049 --- ZA2X/PROG/ZDEMO_EXCEL32.slnk | 113 +++++++++++++++++++++++------------ 1 file changed, 76 insertions(+), 37 deletions(-) diff --git a/ZA2X/PROG/ZDEMO_EXCEL32.slnk b/ZA2X/PROG/ZDEMO_EXCEL32.slnk index 816260e..56ce3c1 100644 --- a/ZA2X/PROG/ZDEMO_EXCEL32.slnk +++ b/ZA2X/PROG/ZDEMO_EXCEL32.slnk @@ -1,8 +1,8 @@ - + - + @@ -66,6 +66,9 @@ + + + @@ -164,14 +167,15 @@ - - - - - - - - + + + + + + + + + @@ -179,8 +183,9 @@ - + + @@ -290,6 +295,9 @@ + + + @@ -324,11 +332,11 @@ - + *--------------------------------------------------------------------* * REPORT ZDEMO_EXCEL32 -* Demo for method zcl_excel_worksheet-bind_object: +* Demo for export options from ALV GRID: * export data from ALV (CL_GUI_ALV_GRID) object or cl_salv_table object * to Excel. *--------------------------------------------------------------------* @@ -373,7 +381,7 @@ DATA: l_path TYPE string, " local dir lv_file_separator TYPE c. CONSTANTS: - lv_default_file_name TYPE string VALUE '90_Bind_Object.xlsx'. + lv_default_file_name TYPE string VALUE '32_Export_ALV.xlsx'. *--------------------------------------------------------------------* *START-OF-SELECTION *--------------------------------------------------------------------* @@ -386,7 +394,7 @@ START-OF-SELECTION. SELECT * INTO TABLE gt_sbook[] FROM sbook "#EC CI_NOWHERE - UP TO 10 ROWS. + UP TO 100 ROWS. * Display ALV * ------------------------------------------ @@ -424,43 +432,74 @@ START-OF-SELECTION. * ALV user command *--------------------------------------------------------------------* FORM user_command . - IF sy-ucomm = 'EXCEL'. * get save file path - cl_gui_frontend_services=>get_sapgui_workdir( CHANGING sapworkdir = l_path ). - cl_gui_cfw=>flush( ). - cl_gui_frontend_services=>directory_browse( - EXPORTING initial_folder = l_path - CHANGING selected_folder = l_path ). + cl_gui_frontend_services=>get_sapgui_workdir( CHANGING sapworkdir = l_path ). + cl_gui_cfw=>flush( ). + cl_gui_frontend_services=>directory_browse( + EXPORTING initial_folder = l_path + CHANGING selected_folder = l_path ). - IF l_path IS INITIAL. - cl_gui_frontend_services=>get_sapgui_workdir( - CHANGING sapworkdir = lv_workdir ). - l_path = lv_workdir. - ENDIF. + IF l_path IS INITIAL. + cl_gui_frontend_services=>get_sapgui_workdir( + CHANGING sapworkdir = lv_workdir ). + l_path = lv_workdir. + ENDIF. - cl_gui_frontend_services=>get_file_separator( - CHANGING file_separator = lv_file_separator ). + cl_gui_frontend_services=>get_file_separator( + CHANGING file_separator = lv_file_separator ). - CONCATENATE l_path lv_file_separator lv_default_file_name - INTO l_path. + CONCATENATE l_path lv_file_separator lv_default_file_name + INTO l_path. + + CASE sy-ucomm. + WHEN 'EXCELBIND'. * export file to save file path - PERFORM export_to_excel. + PERFORM export_to_excel_bind. - ENDIF. + WHEN 'EXCELCONV'. + + PERFORM export_to_excel_conv. + + ENDCASE. ENDFORM. " USER_COMMAND - *--------------------------------------------------------------------* -* FORM EXPORT_TO_EXCEL +* FORM EXPORT_TO_EXCEL_CONV *--------------------------------------------------------------------* * This subroutine is principal demo session *--------------------------------------------------------------------* -FORM export_to_excel. +FORM export_to_excel_conv. DATA: lo_converter TYPE REF TO zcl_excel_converter. -* create zcl_excel_worksheet object + CREATE OBJECT lo_converter. +*TRY. + lo_converter->convert( + EXPORTING + io_alv = lo_salv + it_table = gt_sbook + i_row_int = 2 + i_column_int = 2 +* i_table = +* i_style_table = +* io_worksheet = +* CHANGING +* co_excel = + ). +* CATCH zcx_excel . +*ENDTRY. + lo_converter->write_file( i_path = l_path ). + +ENDFORM. "EXPORT_TO_EXCEL_CONV + +*--------------------------------------------------------------------* +* FORM EXPORT_TO_EXCEL_BIND +*--------------------------------------------------------------------* +* This subroutine is principal demo session +*--------------------------------------------------------------------* +FORM export_to_excel_bind. +* create zcl_excel_worksheet object CREATE OBJECT lo_excel. lo_worksheet = lo_excel->get_active_worksheet( ). lo_worksheet->set_title( ip_title = 'Sheet1' ). @@ -479,7 +518,7 @@ FORM export_to_excel. PERFORM write_file. -ENDFORM. "EXPORT_TO_EXCEL +ENDFORM. "EXPORT_TO_EXCEL_BIND *&---------------------------------------------------------------------* *& Form WRITE_FILE *&---------------------------------------------------------------------*