diff --git a/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk b/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk index 1cb1294..5cd9091 100644 --- a/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk +++ b/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk @@ -1,5 +1,6 @@ + @@ -8,15 +9,29 @@ final create public . -public section. *"* public components of class ZCL_EXCEL_WORKSHEET *"* do not include other source files here!!! +public section. type-pools ABAP . + interfaces ZIF_EXCEL_SHEET_PRINTSETTINGS . interfaces ZIF_EXCEL_SHEET_PROPERTIES . interfaces ZIF_EXCEL_SHEET_PROTECTION . interfaces ZIF_EXCEL_SHEET_VBA_PROJECT . + aliases CLEAR_PRINT_REPEAT_COLUMNS + for ZIF_EXCEL_SHEET_PRINTSETTINGS~CLEAR_PRINT_REPEAT_COLUMNS . + aliases CLEAR_PRINT_REPEAT_ROWS + for ZIF_EXCEL_SHEET_PRINTSETTINGS~CLEAR_PRINT_REPEAT_ROWS . + aliases GET_PRINT_REPEAT_COLUMNS + for ZIF_EXCEL_SHEET_PRINTSETTINGS~GET_PRINT_REPEAT_COLUMNS . + aliases GET_PRINT_REPEAT_ROWS + for ZIF_EXCEL_SHEET_PRINTSETTINGS~GET_PRINT_REPEAT_ROWS . + aliases SET_PRINT_REPEAT_COLUMNS + for ZIF_EXCEL_SHEET_PRINTSETTINGS~SET_PRINT_REPEAT_COLUMNS . + aliases SET_PRINT_REPEAT_ROWS + for ZIF_EXCEL_SHEET_PRINTSETTINGS~SET_PRINT_REPEAT_ROWS . + constants C_BREAK_COLUMN type ZEXCEL_BREAK value 2. "#EC NOTEXT constants C_BREAK_NONE type ZEXCEL_BREAK value 0. "#EC NOTEXT constants C_BREAK_ROW type ZEXCEL_BREAK value 1. "#EC NOTEXT @@ -396,9 +411,9 @@ public section. *"* protected components of class ZCL_EXCEL_WORKSHEET *"* do not include other source files here!!! protected section. - private section. -*"* private components of class ZCL_EXCEL_WORKSHEET + *"* private components of class ZCL_EXCEL_WORKSHEET *"* do not include other source files here!!! +private section. data ACTIVE_CELL type ZEXCEL_S_CELL_DATA . data CHARTS type ref to ZCL_EXCEL_DRAWINGS . @@ -420,6 +435,10 @@ protected section. data TABLES type ref to CL_OBJECT_COLLECTION . data TITLE type ZEXCEL_SHEET_TITLE value 'Worksheet'. "#EC NOTEXT . data UPPER_CELL type ZEXCEL_S_CELL_DATA . + data PRINT_TITLE_COL_FROM type ZEXCEL_CELL_COLUMN_ALPHA . + data PRINT_TITLE_COL_TO type ZEXCEL_CELL_COLUMN_ALPHA . + data PRINT_TITLE_ROW_FROM type ZEXCEL_CELL_ROW . + data PRINT_TITLE_ROW_TO type ZEXCEL_CELL_ROW . methods CALCULATE_CELL_WIDTH importing @@ -440,7 +459,8 @@ protected section. !EP_VALUE_TYPE type ABAP_TYPEKIND . methods UPDATE_DIMENSION_RANGE raising - ZCX_EXCEL . + ZCX_EXCEL . + methods PRINT_TITLE_SET_RANGE . *"* local class implementation for public class *"* use this source file for the implementation part of *"* local helper classes @@ -599,10 +619,12 @@ endclass. + + @@ -631,6 +653,10 @@ endclass. + + + + @@ -643,6 +669,145 @@ endclass. + + METHOD zif_excel_sheet_printsettings~clear_print_repeat_columns. + +*--------------------------------------------------------------------* +* adjust internal representation +*--------------------------------------------------------------------* + clear: me->print_title_col_from, + me->print_title_col_to . + + +*--------------------------------------------------------------------* +* adjust corresponding range +*--------------------------------------------------------------------* + me->print_title_set_range( ). + + +ENDMETHOD. + + + METHOD zif_excel_sheet_printsettings~clear_print_repeat_rows. + +*--------------------------------------------------------------------* +* adjust internal representation +*--------------------------------------------------------------------* + clear: me->print_title_row_from, + me->print_title_row_to . + + +*--------------------------------------------------------------------* +* adjust corresponding range +*--------------------------------------------------------------------* + me->print_title_set_range( ). + + +ENDMETHOD. + + + METHOD zif_excel_sheet_printsettings~get_print_repeat_columns. +ENDMETHOD. + + + METHOD zif_excel_sheet_printsettings~get_print_repeat_rows. +ENDMETHOD. + + + METHOD zif_excel_sheet_printsettings~set_print_repeat_columns. +*--------------------------------------------------------------------* +* issue#235 - repeat rows/columns +* - Stefan Schmöcker, 2012-12-02 +*--------------------------------------------------------------------* + + DATA: lv_col_from_int TYPE i, + lv_col_to_int TYPE i, + lv_errormessage TYPE string. + + DATA: lo_range_iterator TYPE REF TO cl_object_collection_iterator, + lo_range TYPE REF TO zcl_excel_range. + + + lv_col_from_int = zcl_excel_common=>convert_column2int( iv_columns_from ). + lv_col_to_int = zcl_excel_common=>convert_column2int( iv_columns_to ). + +*--------------------------------------------------------------------* +* Check if valid range is supplied +*--------------------------------------------------------------------* + IF lv_col_from_int < 1. + lv_errormessage = 'Invalid range supplied for print-title repeatable columns'(401). + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = lv_errormessage. + ENDIF. + + IF lv_col_from_int > lv_col_to_int. + lv_errormessage = 'Invalid range supplied for print-title repeatable columns'(401). + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = lv_errormessage. + ENDIF. + +*--------------------------------------------------------------------* +* adjust internal representation +*--------------------------------------------------------------------* + me->print_title_col_from = iv_columns_from. + me->print_title_col_to = iv_columns_to. + + +*--------------------------------------------------------------------* +* adjust corresponding range +*--------------------------------------------------------------------* + me->print_title_set_range( ). + +ENDMETHOD. + + + METHOD zif_excel_sheet_printsettings~set_print_repeat_rows. +*--------------------------------------------------------------------* +* issue#235 - repeat rows/columns +* - Stefan Schmöcker, 2012-12-02 +*--------------------------------------------------------------------* + + DATA: lv_errormessage TYPE string. + + DATA: lo_range_iterator TYPE REF TO cl_object_collection_iterator, + lo_range TYPE REF TO zcl_excel_range. + + + +*--------------------------------------------------------------------* +* Check if valid range is supplied +*--------------------------------------------------------------------* + IF iv_rows_from < 1. + lv_errormessage = 'Invalid range supplied for print-title repeatable rowumns'(401). + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = lv_errormessage. + ENDIF. + + IF iv_rows_from > iv_rows_to. + lv_errormessage = 'Invalid range supplied for print-title repeatable rowumns'(401). + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = lv_errormessage. + ENDIF. + +*--------------------------------------------------------------------* +* adjust internal representation +*--------------------------------------------------------------------* + me->print_title_row_from = iv_rows_from. + me->print_title_row_to = iv_rows_to. + + +*--------------------------------------------------------------------* +* adjust corresponding range +*--------------------------------------------------------------------* + me->print_title_set_range( ). + + +ENDMETHOD. + method ZIF_EXCEL_SHEET_PROPERTIES~GET_STYLE. IF zif_excel_sheet_properties~style IS NOT INITIAL. @@ -3614,6 +3779,8 @@ endmethod. endmethod. + + @@ -4114,6 +4281,14 @@ endmethod. endmethod. + + + + + + + + method GET_RANGES_ITERATOR. @@ -4237,6 +4412,105 @@ endmethod. ENDIF. endmethod. + + + METHOD print_title_set_range. +*--------------------------------------------------------------------* +* issue#235 - repeat rows/columns +* - Stefan Schmöcker, 2012-12-02 +*--------------------------------------------------------------------* + + + DATA: lo_range_iterator TYPE REF TO cl_object_collection_iterator, + lo_range TYPE REF TO zcl_excel_range, + lv_repeat_range_sheetname TYPE string, + lv_repeat_range_col TYPE string, + lv_row_char_from TYPE char10, + lv_row_char_to TYPE char10, + lv_repeat_range_row TYPE string, + lv_repeat_range TYPE string. + + +*--------------------------------------------------------------------* +* Get range that represents printarea +* if non-existant, create it +*--------------------------------------------------------------------* + lo_range_iterator = me->get_ranges_iterator( ). + WHILE lo_range_iterator->has_next( ) = abap_true. + + lo_range ?= lo_range_iterator->get_next( ). + IF lo_range->name = zif_excel_sheet_printsettings=>gcv_print_title_name. + EXIT. " Found it + ENDIF. + CLEAR lo_range. + + ENDWHILE. + + + IF me->print_title_col_from IS INITIAL AND + me->print_title_row_from IS INITIAL. +*--------------------------------------------------------------------* +* No print titles are present, +*--------------------------------------------------------------------* + IF lo_range IS BOUND. + me->ranges->remove( lo_range ). + ENDIF. + ELSE. +*--------------------------------------------------------------------* +* Print titles are present, +*--------------------------------------------------------------------* + IF lo_range IS NOT BOUND. + lo_range = me->add_new_range( ). + lo_range->name = zif_excel_sheet_printsettings=>gcv_print_title_name. + ENDIF. + + lv_repeat_range_sheetname = me->get_title( ). + lv_repeat_range_sheetname = zcl_excel_common=>escape_string( lv_repeat_range_sheetname ). + +*--------------------------------------------------------------------* +* Repeat-columns +*--------------------------------------------------------------------* + IF me->print_title_col_from IS NOT INITIAL. + CONCATENATE lv_repeat_range_sheetname + '!$' me->print_title_col_from + ':$' me->print_title_col_to + INTO lv_repeat_range_col. + ENDIF. + +*--------------------------------------------------------------------* +* Repeat-rows +*--------------------------------------------------------------------* + IF me->print_title_row_from IS NOT INITIAL. + lv_row_char_from = me->print_title_row_from. + lv_row_char_to = me->print_title_row_to. + CONCATENATE '!$' lv_row_char_from + ':$' lv_row_char_to + INTO lv_repeat_range_row. + CONDENSE lv_repeat_range_row NO-GAPS. + CONCATENATE lv_repeat_range_sheetname + lv_repeat_range_row + INTO lv_repeat_range_row. + ENDIF. + +*--------------------------------------------------------------------* +* Concatenate repeat-rows and columns +*--------------------------------------------------------------------* + IF lv_repeat_range_col IS INITIAL. + lv_repeat_range = lv_repeat_range_row. + ELSEIF lv_repeat_range_row IS INITIAL. + lv_repeat_range = lv_repeat_range_col. + ELSE. + CONCATENATE lv_repeat_range_col lv_repeat_range_row + INTO lv_repeat_range SEPARATED BY ','. + ENDIF. + + + lo_range->set_range_value( lv_repeat_range ). + ENDIF. + + + +ENDMETHOD. @@ -4593,6 +4867,14 @@ endmethod. me->print_gridlines = i_print_gridlines. endmethod. + + + + + + + + diff --git a/ZA2X/INTF/ZIF_EXCEL_SHEET_PRINTSETTINGS.slnk b/ZA2X/INTF/ZIF_EXCEL_SHEET_PRINTSETTINGS.slnk new file mode 100644 index 0000000..d65a7a3 --- /dev/null +++ b/ZA2X/INTF/ZIF_EXCEL_SHEET_PRINTSETTINGS.slnk @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ZA2X/PROG/ZDEMO_EXCEL40.slnk b/ZA2X/PROG/ZDEMO_EXCEL40.slnk new file mode 100644 index 0000000..788ec5e --- /dev/null +++ b/ZA2X/PROG/ZDEMO_EXCEL40.slnk @@ -0,0 +1,92 @@ + + + + + + + + + REPORT. + + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_worksheet TYPE REF TO zcl_excel_worksheet. + +DATA: lv_row TYPE zexcel_cell_row, + lv_col TYPE i, + lv_row_char TYPE char10, + lv_value TYPE string, + ls_fontcolor TYPE zexcel_style_color_argb. + +CONSTANTS: gc_save_file_name TYPE string VALUE '40_Printsettings.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 = 'Demo Printsettings' ). + +*--------------------------------------------------------------------* +* Prepare sheet with trivial data +* - first 4 columns will have fontocolor set +* - first 3 rows will have fontcolor set +* These marked cells will be used for repeatable rows/columns on printpages +*--------------------------------------------------------------------* + DO 100 TIMES. " Rows + + lv_row = sy-index . + WRITE lv_row TO lv_row_char. + + DO 20 TIMES. + + lv_col = sy-index - 1. + CONCATENATE sy-abcde+lv_col(1) lv_row_char INTO lv_value. + lv_col = sy-index. + lo_worksheet->set_cell( ip_row = lv_row + ip_column = lv_col + ip_value = lv_value ). + + TRY. + IF lv_row <= 3. + lo_worksheet->change_cell_style( ip_column = lv_col + ip_row = lv_row + ip_fill_filltype = zcl_excel_style_fill=>c_fill_solid + ip_fill_fgcolor_rgb = zcl_excel_style_color=>c_yellow ). + ENDIF. + IF lv_col <= 4. + lo_worksheet->change_cell_style( ip_column = lv_col + ip_row = lv_row + ip_font_color_rgb = zcl_excel_style_color=>c_red ). + ENDIF. + CATCH zcx_excel . + ENDTRY. + + ENDDO. + + + + ENDDO. + + +*--------------------------------------------------------------------* +* Printsettings +*--------------------------------------------------------------------* + TRY. + lo_worksheet->zif_excel_sheet_printsettings~set_print_repeat_columns( iv_columns_from = 'A' + iv_columns_to = 'D' ). + lo_worksheet->zif_excel_sheet_printsettings~set_print_repeat_rows( iv_rows_from = 1 + iv_rows_to = 3 ). + CATCH zcx_excel . + ENDTRY. + + + + +*** Create output + lcl_output=>output( lo_excel ). +