diff --git a/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk b/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk index ff79e98..1cb1294 100644 --- a/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk +++ b/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk @@ -1,8 +1,8 @@ - - - + + + class ZCL_EXCEL_WORKSHEET definition public final @@ -596,8 +596,13 @@ endclass. *"* use this source file for any macro definitions you need *"* in the implementation part of the class + + + + + @@ -2862,38 +2867,51 @@ endmethod. METHOD bind_table. - - DATA: - lv_row_int TYPE zexcel_cell_row, - lv_first_row TYPE zexcel_cell_row, - lv_last_row TYPE zexcel_cell_row, - lv_column_int TYPE zexcel_cell_column, - lv_column_alpha TYPE zexcel_cell_column_alpha, - lt_field_catalog TYPE zexcel_t_fieldcatalog, - lv_id TYPE i, - lv_rows TYPE i, - lv_formula TYPE string, - ls_settings TYPE zexcel_s_table_settings, - lo_table TYPE REF TO zcl_excel_table, - lt_column_name_buffer TYPE SORTED TABLE OF string WITH UNIQUE KEY table_line, - lv_value TYPE string, - lv_syindex TYPE char3. - - DATA lv_columns TYPE i. - DATA lt_columns TYPE zexcel_t_fieldcatalog. - DATA lv_maxcol TYPE i. - DATA lv_maxrow TYPE i. - DATA lo_iterator TYPE REF TO cl_object_collection_iterator. - DATA lo_curtable TYPE REF TO zcl_excel_table. +*--------------------------------------------------------------------* +* issue #230 - Pimp my Code +* - Stefan Schmöcker, (wi p) 2012-12-01 +* - ... +* aligning code +* message made to support multilinguality +*--------------------------------------------------------------------* +* issue #237 - Check if overlapping areas exist +* - Alessandro Iannacci 2012-12-01 +* changes: - Added raise if overlaps are detected +*--------------------------------------------------------------------* CONSTANTS: - lc_top_left_column TYPE zexcel_cell_column_alpha VALUE 'B', - lc_top_left_row TYPE zexcel_cell_row VALUE '3'. + lc_top_left_column TYPE zexcel_cell_column_alpha VALUE 'B', + lc_top_left_row TYPE zexcel_cell_row VALUE '3'. - FIELD-SYMBOLS: <ls_field_catalog> TYPE zexcel_s_fieldcatalog, - <ls_field_catalog_custom> TYPE zexcel_s_fieldcatalog, - <fs_table_line> TYPE any, - <fs_fldval> TYPE any. + DATA: + lv_row_int TYPE zexcel_cell_row, + lv_first_row TYPE zexcel_cell_row, + lv_last_row TYPE zexcel_cell_row, + lv_column_int TYPE zexcel_cell_column, + lv_column_alpha TYPE zexcel_cell_column_alpha, + lt_field_catalog TYPE zexcel_t_fieldcatalog, + lv_id TYPE i, + lv_rows TYPE i, + lv_formula TYPE string, + ls_settings TYPE zexcel_s_table_settings, + lo_table TYPE REF TO zcl_excel_table, + lt_column_name_buffer TYPE SORTED TABLE OF string WITH UNIQUE KEY table_line, + lv_value TYPE string, + lv_syindex TYPE char3, + lv_errormessage TYPE string, "ins issue #237 + + lv_columns TYPE i, + lt_columns TYPE zexcel_t_fieldcatalog, + lv_maxcol TYPE i, + lv_maxrow TYPE i, + lo_iterator TYPE REF TO cl_object_collection_iterator, + lo_curtable TYPE REF TO zcl_excel_table. + + FIELD-SYMBOLS: + <ls_field_catalog> TYPE zexcel_s_fieldcatalog, + <ls_field_catalog_custom> TYPE zexcel_s_fieldcatalog, + <fs_table_line> TYPE ANY, + <fs_fldval> TYPE ANY. ls_settings = is_table_settings. @@ -2917,6 +2935,9 @@ endmethod. SORT lt_field_catalog BY position. +*--------------------------------------------------------------------* +* issue #237 Check if overlapping areas exist Start +*--------------------------------------------------------------------* "Get the number of columns for the current table lt_columns = lt_field_catalog. DELETE lt_columns WHERE dynpfld NE abap_true. @@ -2930,26 +2951,36 @@ endmethod. DESCRIBE TABLE ip_table LINES lv_rows. "Calculate the bottom right row for the current table - lv_maxcol = lv_column_int + lv_columns - 1. - lv_maxrow = lv_row_int + lv_rows - 1. + lv_maxcol = lv_column_int + lv_columns - 1. + lv_maxrow = lv_row_int + lv_rows - 1. ls_settings-bottom_right_column = zcl_excel_common=>convert_column2alpha( lv_maxcol ). ls_settings-bottom_right_row = lv_maxrow. - lv_column_int = zcl_excel_common=>convert_column2int( ls_settings-top_left_column ). + lv_column_int = zcl_excel_common=>convert_column2int( ls_settings-top_left_column ). - "Check if overlapping areas exist lo_iterator = me->tables->if_object_collection~get_iterator( ). WHILE lo_iterator->if_object_collection_iterator~has_next( ) EQ abap_true. + lo_curtable ?= lo_iterator->if_object_collection_iterator~get_next( ). - IF ( ls_settings-top_left_row GE lo_curtable->settings-top_left_row AND ls_settings-top_left_row LE lo_curtable->settings-bottom_right_row - OR ls_settings-bottom_right_row GE lo_curtable->settings-top_left_row AND ls_settings-bottom_right_row LE lo_curtable->settings-bottom_right_row ) - and ( lv_column_int GE zcl_excel_common=>convert_column2int( lo_curtable->settings-top_left_column ) AND lv_column_int LE zcl_excel_common=>convert_column2int( lo_curtable->settings-bottom_right_column ) - OR lv_maxcol GE zcl_excel_common=>convert_column2int( lo_curtable->settings-top_left_column ) AND lv_maxcol LE zcl_excel_common=>convert_column2int( lo_curtable->settings-bottom_right_column ) ). + IF ( ( ls_settings-top_left_row GE lo_curtable->settings-top_left_row AND ls_settings-top_left_row LE lo_curtable->settings-bottom_right_row ) + OR + ( ls_settings-bottom_right_row GE lo_curtable->settings-top_left_row AND ls_settings-bottom_right_row LE lo_curtable->settings-bottom_right_row ) + ) + AND + ( ( lv_column_int GE zcl_excel_common=>convert_column2int( lo_curtable->settings-top_left_column ) AND lv_column_int LE zcl_excel_common=>convert_column2int( lo_curtable->settings-bottom_right_column ) ) + OR + ( lv_maxcol GE zcl_excel_common=>convert_column2int( lo_curtable->settings-top_left_column ) AND lv_maxcol LE zcl_excel_common=>convert_column2int( lo_curtable->settings-bottom_right_column ) ) + ). + lv_errormessage = 'Table overlaps with previously bound table and will not be added to worksheet.'(400). RAISE EXCEPTION TYPE zcx_excel EXPORTING - error = 'It is not possible to bind two tables to an excelsheet with overlapping areas.'. + error = lv_errormessage. ENDIF. + ENDWHILE. +*--------------------------------------------------------------------* +* issue #237 Check if overlapping areas exist End +*--------------------------------------------------------------------* CREATE OBJECT lo_table. lo_table->settings = ls_settings. @@ -2982,6 +3013,7 @@ endmethod. <ls_field_catalog>-scrtext_l = lv_value. ENDIF. WHILE 1 = 1. + READ TABLE lt_column_name_buffer TRANSPORTING NO FIELDS WITH KEY table_line = lv_value BINARY SEARCH. IF sy-subrc <> 0. <ls_field_catalog>-scrtext_l = lv_value. @@ -2991,6 +3023,7 @@ endmethod. lv_syindex = sy-index. CONCATENATE <ls_field_catalog>-scrtext_l lv_syindex INTO lv_value. ENDIF. + ENDWHILE. " First of all write column header IF <ls_field_catalog>-style_header IS NOT INITIAL. @@ -3006,6 +3039,7 @@ endmethod. ADD 1 TO lv_row_int. LOOP AT ip_table ASSIGNING <fs_table_line>. + ASSIGN COMPONENT <ls_field_catalog>-fieldname OF STRUCTURE <fs_table_line> TO <fs_fldval>. IF <ls_field_catalog>-style IS NOT INITIAL. me->set_cell( ip_column = lv_column_alpha @@ -3018,6 +3052,7 @@ endmethod. ip_value = <fs_fldval> ). ENDIF. ADD 1 TO lv_row_int. + ENDLOOP. IF sy-subrc <> 0. "create empty row if table has no data me->set_cell( ip_column = lv_column_alpha @@ -3026,7 +3061,9 @@ endmethod. ADD 1 TO lv_row_int. ENDIF. +*--------------------------------------------------------------------* " totals +*--------------------------------------------------------------------* IF <ls_field_catalog>-totals_function IS NOT INITIAL. lv_formula = lo_table->get_totals_formula( ip_column = <ls_field_catalog>-scrtext_l ip_function = <ls_field_catalog>-totals_function ). IF <ls_field_catalog>-style_total IS NOT INITIAL. @@ -3044,7 +3081,9 @@ endmethod. lv_row_int = ls_settings-top_left_row. ADD 1 TO lv_column_int. +*--------------------------------------------------------------------* " conditional formatting +*--------------------------------------------------------------------* IF <ls_field_catalog>-cond_style IS NOT INITIAL. lv_first_row = ls_settings-top_left_row + 1. " +1 to exclude header lv_last_row = ls_settings-top_left_row + lv_rows. @@ -3053,9 +3092,12 @@ endmethod. ip_stop_column = lv_column_alpha ip_stop_row = lv_last_row ). ENDIF. + ENDLOOP. +*--------------------------------------------------------------------* " Set field catalog +*--------------------------------------------------------------------* lo_table->fieldcat = lt_field_catalog[]. es_table_settings = ls_settings. diff --git a/ZA2X/PROG/ZERROR_A2X_BIND_TABLE_OVERLAP.slnk b/ZA2X/PROG/ZERROR_A2X_BIND_TABLE_OVERLAP.slnk deleted file mode 100644 index 562d760..0000000 --- a/ZA2X/PROG/ZERROR_A2X_BIND_TABLE_OVERLAP.slnk +++ /dev/null @@ -1,64 +0,0 @@ - - - - - - - - - - REPORT zerror_a2x_bind_table_overlap. - -TYPE-POOLS: abap. - -DATA: lo_excel TYPE REF TO zcl_excel, - lo_worksheet TYPE REF TO zcl_excel_worksheet, - column_dimension TYPE REF TO zcl_excel_worksheet_columndime. - -DATA: ls_table_settings TYPE zexcel_s_table_settings. - - -DATA: lv_title TYPE zexcel_sheet_title, - lt_carr TYPE TABLE OF scarr, - row TYPE zexcel_cell_row VALUE 2, - lo_range TYPE REF TO zcl_excel_range. -DATA: lo_data_validation TYPE REF TO zcl_excel_data_validation. -FIELD-SYMBOLS: <carr> LIKE LINE OF lt_carr. - -CONSTANTS: c_airlines TYPE string VALUE 'Airlines'. - - -CONSTANTS: gc_save_file_name TYPE string VALUE '03_iTab.xlsx'. -INCLUDE zdemo_excel_outputopt_incl. - -START-OF-SELECTION. - " Creates active sheet - CREATE OBJECT lo_excel. - - " Get active sheet - lo_worksheet = lo_excel->get_active_worksheet( ). - lo_worksheet->set_title( ip_title = 'Internal table'). - - DATA lt_test TYPE TABLE OF sflight. - - SELECT * FROM sflight INTO TABLE lt_test. "#EC CI_NOWHERE - -* First table - A:M - - ls_table_settings-table_style = zcl_excel_table=>builtinstyle_medium2. - ls_table_settings-show_row_stripes = abap_true. - ls_table_settings-top_left_column = 'A'. - - lo_worksheet->bind_table( ip_table = lt_test - is_table_settings = ls_table_settings ). - -* Second (overlapping) table: K:T - - ls_table_settings-top_left_column = 'K'. - - lo_worksheet->bind_table( ip_table = lt_test - is_table_settings = ls_table_settings ). - -*** Create output - lcl_output=>output( lo_excel ). -