From 70e0659f821a7888df0b2026106b2db7565deb81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Schm=C3=B6cker?= Date: Sat, 8 Dec 2012 13:11:29 +0000 Subject: [PATCH] ZCL_EXCEL_WORKSHEET=>SET_TITLE #243 : ' not allowed as first character in title of worksheet #230 : pimp my code also readded implementing code of interface printsettings since it seems to have been eradicated when removing the aliases git-svn-id: https://subversion.assembla.com/svn/abap2xlsx/trunk@399 b7d68dce-7c3c-4a99-8ce0-9ea847f5d049 --- ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk | 231 ++++++++++++++++++++++++++--- 1 file changed, 212 insertions(+), 19 deletions(-) diff --git a/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk b/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk index 5a92791..481c0af 100644 --- a/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk +++ b/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk @@ -1,9 +1,9 @@ - - - - + + + + class ZCL_EXCEL_WORKSHEET definition public final @@ -607,11 +607,15 @@ endclass. + + + + @@ -719,6 +723,149 @@ endmethod. method ZIF_EXCEL_SHEET_VBA_PROJECT~SET_CODENAME_PR. me->zif_excel_sheet_vba_project~codename_pr = ip_codename_pr. endmethod. + + + 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. + ev_columns_from = me->print_title_col_from. + ev_columns_to = me->print_title_col_to. +ENDMETHOD. + + + METHOD zif_excel_sheet_printsettings~get_print_repeat_rows. + ev_rows_from = me->print_title_row_from. + ev_rows_to = me->print_title_row_to. +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. @@ -4841,29 +4988,63 @@ endmethod. - method SET_TITLE. - DATA: lo_worksheets_iterator TYPE REF TO cl_object_collection_iterator, - lo_worksheet TYPE REF TO zcl_excel_worksheet, - errormessage TYPE string, - lv_rangesheetname_old TYPE string, - lv_rangesheetname_new TYPE string, - lo_ranges_iterator TYPE REF TO cl_object_collection_iterator, - lo_range TYPE REF TO zcl_excel_range, - lv_range_value TYPE zexcel_range_value. + METHOD set_title. +*--------------------------------------------------------------------* +* ToDos: +* 2do§1 The current coding for replacing a named ranges name +* after renaming a sheet should be checked if it is +* really working if sheetname should be escaped +*--------------------------------------------------------------------* + +*--------------------------------------------------------------------* +* issue #230 - Pimp my Code +* - Stefan Schmöcker, (wip ) 2012-12-08 +* - ... +* changes: aligning code +* message made to support multilinguality +*--------------------------------------------------------------------* +* issue#243 - ' is not allowed as first character in sheet title +* - Stefan Schmöcker, 2012-12-02 +* changes: added additional check for ' as first character +*--------------------------------------------------------------------* + DATA: lo_worksheets_iterator TYPE REF TO cl_object_collection_iterator, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + errormessage TYPE string, + lv_rangesheetname_old TYPE string, + lv_rangesheetname_new TYPE string, + lo_ranges_iterator TYPE REF TO cl_object_collection_iterator, + lo_range TYPE REF TO zcl_excel_range, + lv_range_value TYPE zexcel_range_value, + lv_errormessage TYPE string. " Can't pass '...'(abc) to exception-class +*--------------------------------------------------------------------* * Check whether title consists only of allowed characters * Illegal characters are: / \ [ ] * ? : --> http://msdn.microsoft.com/en-us/library/ff837411.aspx +* Illegal characters not in documentation: ' as first character +*--------------------------------------------------------------------* IF ip_title CA '/\[]*?:'. + lv_errormessage = 'Found illegal character in sheetname. List of forbidden characters: /\[]*?:'(402). RAISE EXCEPTION TYPE zcx_excel EXPORTING - error = 'Found illegal character in sheetname. List of forbidden characters: /\[]*?: '. + error = lv_errormessage. + ENDIF. + + IF ip_title IS NOT INITIAL AND ip_title(1) = `'`. + lv_errormessage = 'Sheetname may not start with &'(403). " & used instead of ' to allow fallbacklanguage + REPLACE '&' IN lv_errormessage WITH `'`. + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = lv_errormessage. ENDIF. -* Check whether title is unique in worksheet +*--------------------------------------------------------------------* +* Check whether title is unique in workbook +*--------------------------------------------------------------------* lo_worksheets_iterator = me->excel->get_worksheets_iterator( ). WHILE lo_worksheets_iterator->has_next( ) = 'X'. + lo_worksheet ?= lo_worksheets_iterator->get_next( ). CHECK me->guid <> lo_worksheet->get_guid( ). " Don't check against itself IF ip_title = lo_worksheet->get_title( ). " Not unique --> raise exception @@ -4873,18 +5054,28 @@ endmethod. EXPORTING error = errormessage. ENDIF. + ENDWHILE. +*--------------------------------------------------------------------* +* Remember old sheetname and rename sheet to desired name +*--------------------------------------------------------------------* CONCATENATE me->title '!' INTO lv_rangesheetname_old. - me->title = ip_title. -* After changing this worksheets title we have to adjust -* all ranges that are referring to this worksheet. +*--------------------------------------------------------------------* +* After changing this worksheet's title we have to adjust +* all ranges that are referring to this worksheet. +*--------------------------------------------------------------------* +* 2do§1 - Check if the following quickfix is solid +* I fear it isn't - but this implementation is better then +* nothing at all since it handles a supposed majority of cases +*--------------------------------------------------------------------* CONCATENATE me->title '!' INTO lv_rangesheetname_new. lo_ranges_iterator = me->excel->get_ranges_iterator( ). WHILE lo_ranges_iterator->has_next( ) = 'X'. + lo_range ?= lo_ranges_iterator->get_next( ). lv_range_value = lo_range->get_value( ). REPLACE ALL OCCURRENCES OF lv_rangesheetname_old IN lv_range_value WITH lv_rangesheetname_new. @@ -4893,7 +5084,9 @@ endmethod. ENDIF. ENDWHILE. -endmethod. + + +ENDMETHOD.