diff --git a/ZA2X/PROG/ZDEMO_EXCEL.slnk b/ZA2X/PROG/ZDEMO_EXCEL.slnk index 47afa2f..358ec43 100644 --- a/ZA2X/PROG/ZDEMO_EXCEL.slnk +++ b/ZA2X/PROG/ZDEMO_EXCEL.slnk @@ -1,5 +1,5 @@ - + @@ -61,5 +61,7 @@ START-OF-SELECTION. SUBMIT zdemo_excel22 WITH p_path = p_path AND RETURN. " Bind table with field catalog & sheet style SUBMIT zdemo_excel23 WITH p_path = p_path AND RETURN. " abap2xlsx Demo: Multiple sheets with and w/o grid lines, print options SUBMIT zdemo_excel24 WITH p_path = p_path AND RETURN. " abap2xlsx Demo: Multiple sheets with different default date formats - SUBMIT zdemo_excel25 AND RETURN. " abap2xlsx Demo: Create and xlsx on Application Server (could be executed in batch mode) + SUBMIT zdemo_excel25 AND RETURN. " abap2xlsx Demo: Create and xlsx on Application Server (could be executed in batch mode) + SUBMIT zdemo_excel26 WITH p_path = p_path WITH p_reader = abap_true AND RETURN. " abap2xlsx Demo: Read cell format + SUBMIT zdemo_excel27 WITH p_path = p_path WITH p_reader = abap_true AND RETURN. " abap2xlsx Demo: Read style format diff --git a/ZA2X/PROG/ZDEMO_EXCEL1.slnk b/ZA2X/PROG/ZDEMO_EXCEL1.slnk index 9f6de52..41cf417 100644 --- a/ZA2X/PROG/ZDEMO_EXCEL1.slnk +++ b/ZA2X/PROG/ZDEMO_EXCEL1.slnk @@ -1,10 +1,9 @@ - + - - + *&---------------------------------------------------------------------* @@ -19,7 +18,6 @@ REPORT zdemo_excel1. DATA: lo_excel TYPE REF TO zcl_excel, lo_excel_writer TYPE REF TO zif_excel_writer, - lo_excel_reader TYPE REF TO zif_excel_reader, lo_worksheet TYPE REF TO zcl_excel_worksheet, lo_hyperlink TYPE REF TO zcl_excel_hyperlink, column_dimension TYPE REF TO zcl_excel_worksheet_columndime. @@ -34,8 +32,7 @@ DATA: lv_full_path TYPE string, CONSTANTS: lv_default_file_name TYPE string VALUE '01_HelloWorld.xlsx'. -PARAMETERS: p_path TYPE zexcel_export_dir, - p_reader TYPE abap_bool AS CHECKBOX. +PARAMETERS: p_path TYPE zexcel_export_dir. AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path. lv_workdir = p_path. @@ -90,28 +87,5 @@ START-OF-SELECTION. cl_gui_frontend_services=>gui_download( EXPORTING bin_filesize = lv_bytecount filename = lv_full_path filetype = 'BIN' - CHANGING data_tab = lt_file_tab ). - - IF p_reader = abap_true. - CREATE OBJECT lo_excel_reader TYPE zcl_excel_reader_2007. - CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007. - lo_excel = lo_excel_reader->load_file( lv_full_path ). - lv_file = lo_excel_writer->write_file( lo_excel ). - REPLACE '.xlsx' IN lv_full_path WITH 'FromReader.xlsx'. - - " Convert to binary - CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' - EXPORTING - buffer = lv_file - IMPORTING - output_length = lv_bytecount - TABLES - binary_tab = lt_file_tab. - - " Save the file - cl_gui_frontend_services=>gui_download( EXPORTING bin_filesize = lv_bytecount - filename = lv_full_path - filetype = 'BIN' - CHANGING data_tab = lt_file_tab ). - ENDIF. + CHANGING data_tab = lt_file_tab ). diff --git a/ZA2X/PROG/ZDEMO_EXCEL2.slnk b/ZA2X/PROG/ZDEMO_EXCEL2.slnk index e2c63ea..c069801 100644 --- a/ZA2X/PROG/ZDEMO_EXCEL2.slnk +++ b/ZA2X/PROG/ZDEMO_EXCEL2.slnk @@ -1,10 +1,9 @@ - + - - - + + *&---------------------------------------------------------------------* @@ -19,7 +18,6 @@ REPORT zdemo_excel2. DATA: lo_excel TYPE REF TO zcl_excel, lo_excel_writer TYPE REF TO zif_excel_writer, - lo_excel_reader TYPE REF TO zif_excel_reader, lo_worksheet TYPE REF TO zcl_excel_worksheet, lo_style_bold TYPE REF TO zcl_excel_style, lo_style_underline TYPE REF TO zcl_excel_style, @@ -46,8 +44,7 @@ DATA: lv_full_path TYPE string, CONSTANTS: lv_default_file_name TYPE string VALUE '02_Styles.xlsx'. -PARAMETERS: p_path TYPE zexcel_export_dir, - p_reader TYPE abap_bool AS CHECKBOX. +PARAMETERS: p_path TYPE zexcel_export_dir. AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path. lv_workdir = p_path. @@ -148,28 +145,5 @@ START-OF-SELECTION. cl_gui_frontend_services=>gui_download( EXPORTING bin_filesize = lv_bytecount filename = lv_full_path filetype = 'BIN' - CHANGING data_tab = lt_file_tab ). - - IF p_reader = abap_true. - CREATE OBJECT lo_excel_reader TYPE zcl_excel_reader_2007. - CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007. - lo_excel = lo_excel_reader->load_file( lv_full_path ). - lv_file = lo_excel_writer->write_file( lo_excel ). - REPLACE '.xlsx' IN lv_full_path WITH 'FromReader.xlsx'. - - " Convert to binary - CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' - EXPORTING - buffer = lv_file - IMPORTING - output_length = lv_bytecount - TABLES - binary_tab = lt_file_tab. - - " Save the file - cl_gui_frontend_services=>gui_download( EXPORTING bin_filesize = lv_bytecount - filename = lv_full_path - filetype = 'BIN' - CHANGING data_tab = lt_file_tab ). - ENDIF. + CHANGING data_tab = lt_file_tab ). diff --git a/ZA2X/PROG/ZDEMO_EXCEL26.slnk b/ZA2X/PROG/ZDEMO_EXCEL26.slnk new file mode 100644 index 0000000..8bd3983 --- /dev/null +++ b/ZA2X/PROG/ZDEMO_EXCEL26.slnk @@ -0,0 +1,117 @@ + + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL26 +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_excel26. + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_excel_writer TYPE REF TO zif_excel_writer, + lo_excel_reader TYPE REF TO zif_excel_reader, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + lo_hyperlink TYPE REF TO zcl_excel_hyperlink, + column_dimension TYPE REF TO zcl_excel_worksheet_columndime. + +DATA: lv_file TYPE xstring, + lv_bytecount TYPE i, + lt_file_tab TYPE solix_tab. + +DATA: lv_full_path TYPE string, + lv_workdir TYPE string, + lv_file_separator TYPE c. + +CONSTANTS: lv_default_file_name TYPE string VALUE '26_HelloWorld.xlsx'. + +PARAMETERS: p_path TYPE zexcel_export_dir, + p_reader TYPE abap_bool AS CHECKBOX. + +AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path. + lv_workdir = p_path. + cl_gui_frontend_services=>directory_browse( EXPORTING initial_folder = lv_workdir + CHANGING selected_folder = lv_workdir ). + p_path = lv_workdir. + +INITIALIZATION. + cl_gui_frontend_services=>get_sapgui_workdir( CHANGING sapworkdir = lv_workdir ). + cl_gui_cfw=>flush( ). + 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 lv_full_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 = 'Hello world' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 3 ip_value = sy-datum ). + lo_worksheet->set_cell( ip_column = 'C' ip_row = 3 ip_value = sy-uzeit ). + lo_hyperlink = zcl_excel_hyperlink=>create_external_link( iv_url = 'https://cw.sdn.sap.com/cw/groups/abap2xlsx' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 4 ip_value = 'Click here to visit abap2xlsx homepage' ip_hyperlink = lo_hyperlink ). + + column_dimension = lo_worksheet->get_column_dimension( ip_column = 'B' ). + column_dimension->set_width( ip_width = 11 ). + + CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007. + lv_file = lo_excel_writer->write_file( lo_excel ). + + " Convert to binary + CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' + EXPORTING + buffer = lv_file + IMPORTING + output_length = lv_bytecount + TABLES + binary_tab = lt_file_tab. +* " This method is only available on AS ABAP > 6.40 +* 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 = lv_full_path + filetype = 'BIN' + CHANGING data_tab = lt_file_tab ). + + IF p_reader = abap_true. + CREATE OBJECT lo_excel_reader TYPE zcl_excel_reader_2007. + CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007. + lo_excel = lo_excel_reader->load_file( lv_full_path ). + lv_file = lo_excel_writer->write_file( lo_excel ). + REPLACE '.xlsx' IN lv_full_path WITH 'FromReader.xlsx'. + + " Convert to binary + CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' + EXPORTING + buffer = lv_file + IMPORTING + output_length = lv_bytecount + TABLES + binary_tab = lt_file_tab. + + " Save the file + cl_gui_frontend_services=>gui_download( EXPORTING bin_filesize = lv_bytecount + filename = lv_full_path + filetype = 'BIN' + CHANGING data_tab = lt_file_tab ). + ENDIF. + diff --git a/ZA2X/PROG/ZDEMO_EXCEL27.slnk b/ZA2X/PROG/ZDEMO_EXCEL27.slnk new file mode 100644 index 0000000..bca04a5 --- /dev/null +++ b/ZA2X/PROG/ZDEMO_EXCEL27.slnk @@ -0,0 +1,175 @@ + + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL27 +*& Test Styles for ABAP2XLSX +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_excel27. + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_excel_writer TYPE REF TO zif_excel_writer, + lo_excel_reader TYPE REF TO zif_excel_reader, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + lo_style_bold TYPE REF TO zcl_excel_style, + lo_style_underline TYPE REF TO zcl_excel_style, + lo_style_filled TYPE REF TO zcl_excel_style, + lo_style_border TYPE REF TO zcl_excel_style, + lo_style_button TYPE REF TO zcl_excel_style, + lo_border_dark TYPE REF TO zcl_excel_style_border, + lo_border_light TYPE REF TO zcl_excel_style_border. + +DATA: lv_style_bold_guid TYPE zexcel_cell_style, + lv_style_underline_guid TYPE zexcel_cell_style, + lv_style_filled_guid TYPE zexcel_cell_style, + lv_style_filled_green_guid TYPE zexcel_cell_style, + lv_style_border_guid TYPE zexcel_cell_style, + lv_style_button_guid TYPE zexcel_cell_style. + +DATA: lv_file TYPE xstring, + lv_bytecount TYPE i, + lt_file_tab TYPE solix_tab. + +DATA: lv_full_path TYPE string, + lv_workdir TYPE string, + lv_file_separator TYPE c. + +CONSTANTS: lv_default_file_name TYPE string VALUE '27_Styles.xlsx'. + +PARAMETERS: p_path TYPE zexcel_export_dir, + p_reader TYPE abap_bool AS CHECKBOX. + +AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path. + lv_workdir = p_path. + cl_gui_frontend_services=>directory_browse( EXPORTING initial_folder = lv_workdir + CHANGING selected_folder = lv_workdir ). + p_path = lv_workdir. + +INITIALIZATION. + cl_gui_frontend_services=>get_sapgui_workdir( CHANGING sapworkdir = lv_workdir ). + cl_gui_cfw=>flush( ). + 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 lv_full_path. + + " Creates active sheet + CREATE OBJECT lo_excel. + + " Create border object + CREATE OBJECT lo_border_dark. + lo_border_dark->border_color = zcl_excel_style_color=>c_black. + lo_border_dark->border_style = zcl_excel_style_border=>c_border_thin. + CREATE OBJECT lo_border_light. + lo_border_light->border_color = zcl_excel_style_color=>c_gray. + lo_border_light->border_style = zcl_excel_style_border=>c_border_thin. + " Create a bold / italic style + lo_style_bold = lo_excel->add_new_style( ). + lo_style_bold->font->bold = abap_true. + lo_style_bold->font->italic = abap_true. + lo_style_bold->font->color = zcl_excel_style_color=>c_red. + lv_style_bold_guid = lo_style_bold->get_guid( ). + " Create an underline double style + lo_style_underline = lo_excel->add_new_style( ). + lo_style_underline->font->underline = abap_true. + lo_style_underline->font->underline_mode = zcl_excel_style_font=>c_underline_double. + lv_style_underline_guid = lo_style_underline->get_guid( ). + " Create filled style yellow + lo_style_filled = lo_excel->add_new_style( ). + lo_style_filled->fill->filltype = zcl_excel_style_fill=>c_fill_solid. + lo_style_filled->fill->fgcolor = zcl_excel_style_color=>c_yellow. + lv_style_filled_guid = lo_style_filled->get_guid( ). + " Create border with button effects + lo_style_button = lo_excel->add_new_style( ). + lo_style_button->borders->right = lo_border_dark. + lo_style_button->borders->down = lo_border_dark. + lo_style_button->borders->left = lo_border_light. + lo_style_button->borders->top = lo_border_light. + lv_style_button_guid = lo_style_button->get_guid( ). + "Create style with border + lo_style_border = lo_excel->add_new_style( ). + lo_style_border->borders->allborders = lo_border_dark. + lv_style_border_guid = lo_style_border->get_guid( ). + " Create filled style green + lo_style_filled = lo_excel->add_new_style( ). + lo_style_filled->fill->filltype = zcl_excel_style_fill=>c_fill_solid. + lo_style_filled->fill->fgcolor = zcl_excel_style_color=>c_green. + lv_style_filled_green_guid = lo_style_filled->get_guid( ). + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( ip_title = 'Styles' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = 'Hello world' ). + lo_worksheet->set_cell( ip_column = 'C' ip_row = 3 ip_value = 'Bold text' ip_style = lv_style_bold_guid ). + lo_worksheet->set_cell( ip_column = 'D' ip_row = 4 ip_value = 'Underlined text' ip_style = lv_style_underline_guid ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 5 ip_value = 'Filled text' ip_style = lv_style_filled_guid ). + lo_worksheet->set_cell( ip_column = 'C' ip_row = 6 ip_value = 'Borders' ip_style = lv_style_border_guid ). + lo_worksheet->set_cell( ip_column = 'D' ip_row = 7 ip_value = 'I''m not a button :)' ip_style = lv_style_button_guid ). + " Fill the cell and apply one style + lo_worksheet->set_cell( ip_column = 'B' ip_row = 6 ip_value = 'Filled text' ip_style = lv_style_filled_guid ). + " Change the style + lo_worksheet->set_cell_style( ip_column = 'B' ip_row = 6 ip_style = lv_style_filled_green_guid ). + " Add Style to an empty cell to test Fix for Issue + "#44 Exception ZCX_EXCEL thrown when style is set for an empty cell + " https://code.sdn.sap.com/spaces/abap2xlsx/tickets/44-exception-zcx_excel-thrown-when-style-is-set-for-an-empty-cell + lo_worksheet->set_cell_style( ip_column = 'E' ip_row = 6 ip_style = lv_style_filled_green_guid ). + + CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007. + lv_file = lo_excel_writer->write_file( lo_excel ). + + " Convert to binary + CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' + EXPORTING + buffer = lv_file + IMPORTING + output_length = lv_bytecount + TABLES + binary_tab = lt_file_tab. +* " This method is only available on AS ABAP > 6.40 +* 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 = lv_full_path + filetype = 'BIN' + CHANGING data_tab = lt_file_tab ). + + IF p_reader = abap_true. + CREATE OBJECT lo_excel_reader TYPE zcl_excel_reader_2007. + CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007. + lo_excel = lo_excel_reader->load_file( lv_full_path ). + lv_file = lo_excel_writer->write_file( lo_excel ). + REPLACE '.xlsx' IN lv_full_path WITH 'FromReader.xlsx'. + + " Convert to binary + CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' + EXPORTING + buffer = lv_file + IMPORTING + output_length = lv_bytecount + TABLES + binary_tab = lt_file_tab. + + " Save the file + cl_gui_frontend_services=>gui_download( EXPORTING bin_filesize = lv_bytecount + filename = lv_full_path + filetype = 'BIN' + CHANGING data_tab = lt_file_tab ). + ENDIF. +