diff --git a/ZA2X/CLAS/ZCL_EXCEL.slnk b/ZA2X/CLAS/ZCL_EXCEL.slnk index 91cdea3..1d026d5 100644 --- a/ZA2X/CLAS/ZCL_EXCEL.slnk +++ b/ZA2X/CLAS/ZCL_EXCEL.slnk @@ -1,16 +1,16 @@ - - - - - + + + + + class ZCL_EXCEL definition public final create public . -public section. *"* public components of class ZCL_EXCEL *"* do not include other source files here!!! +public section. interfaces ZIF_EXCEL_BOOK_PROPERTIES . interfaces ZIF_EXCEL_BOOK_PROTECTION . @@ -41,7 +41,9 @@ public section. importing !IP_TITLE type ZEXCEL_SHEET_TITLE optional returning - value(EO_WORKSHEET) type ref to ZCL_EXCEL_WORKSHEET . + value(EO_WORKSHEET) type ref to ZCL_EXCEL_WORKSHEET + raising + ZCX_EXCEL . methods ADD_STATIC_STYLES . methods CONSTRUCTOR . methods GET_ACTIVE_SHEET_INDEX @@ -121,15 +123,15 @@ protected section. *"* implementation or private method's signature *"* use this source file for any macro definitions you need *"* in the implementation part of the class - - - - - - - - - + + + + + + + + + method ZIF_EXCEL_BOOK_PROPERTIES~INITIALIZE. DATA: lv_timestamp TYPE timestampl. @@ -169,17 +171,17 @@ endmethod. me->zif_excel_book_vba_project~vbaproject = ip_vbaproject. endmethod. - - - + + + method ADD_NEW_AUTOFILTER. * Check for autofilter reference: new or overwrite; only one per sheet ro_autofilter = autofilters->add( io_sheet = io_sheet ) . endmethod. - - - + + + method ADD_NEW_DRAWING. DATA: lv_guid TYPE guid_16. * Create default blank worksheet @@ -189,18 +191,18 @@ endmethod. drawings->add( eo_drawing ). endmethod. - - + + method ADD_NEW_RANGE. * Create default blank range CREATE OBJECT eo_range. ranges->add( eo_range ). endmethod. - - - - METHOD add_new_style. + + + + method ADD_NEW_STYLE. * Start of deletion # issue 139 - Dateretention of cellstyles * CREATE OBJECT eo_style. * styles->add( eo_style ). @@ -219,11 +221,12 @@ endmethod. INSERT style2 INTO TABLE t_stylemapping2. * End of insertion # issue 139 - Dateretention of cellstyles -ENDMETHOD. +endmethod. - - - + + + + method ADD_NEW_WORKSHEET. DATA: lv_guid TYPE guid_16. * Create default blank worksheet @@ -235,14 +238,14 @@ ENDMETHOD. worksheets->active_worksheet = worksheets->size( ). endmethod. - - METHOD add_static_styles. + + method ADD_STATIC_STYLES. " # issue 139 -* später hier noch die Worksheets abklappern, welche Styles überhaupt noch benötigt werden -* und nur diese dann auch hier zur Verfügung stellen +* sp#ƒÂ¤ter hier noch die Worksheets abklappern, welche Styles #ƒÂ#berhaupt noch ben#ƒÂ#tigt werden +* und nur diese dann auch hier zur Verf#ƒÂ#gung stellen * Da muss ich noch mal nachfragen, ob die beiden ersten Styles, die scheinbar immer mit dem -* EXCEL-Objekt erzeugt werden evtl. immer benötigt werden, egal ob verwendet oder nicht -* Aber als Start fange ich mal an einfach alle static styles der Reihe nach hinzuzufügen +* EXCEL-Objekt erzeugt werden evtl. immer ben#ƒÂ#tigt werden, egal ob verwendet oder nicht +* Aber als Start fange ich mal an einfach alle static styles der Reihe nach hinzuzuf#ƒÂ#gen FIELD-SYMBOLS: <style1> LIKE LINE OF t_stylemapping1, <style2> LIKE LINE OF t_stylemapping2. DATA: style TYPE REF TO zcl_excel_style. @@ -258,9 +261,9 @@ endmethod. CHANGING e_target = style ). ENDLOOP. -ENDMETHOD. +endmethod. - + method CONSTRUCTOR. DATA: lo_worksheet TYPE REF TO zcl_excel_worksheet, lo_style TYPE REF TO zcl_excel_style. @@ -284,38 +287,38 @@ ENDMETHOD. endmethod. - - + + method GET_ACTIVE_SHEET_INDEX. r_active_worksheet = me->worksheets->active_worksheet. endmethod. - - + + method GET_ACTIVE_WORKSHEET. eo_worksheet = me->worksheets->get( me->worksheets->active_worksheet ). endmethod. - - + + method GET_AUTOFILTERS_REFERENCE. ro_autofilters = autofilters. endmethod. - - + + method GET_DRAWINGS_ITERATOR. eo_iterator = me->drawings->get_iterator( ). endmethod. - - + + method GET_NEXT_TABLE_ID. DATA: lo_worksheet TYPE REF TO zcl_excel_worksheet, lo_iterator TYPE REF TO cl_object_collection_iterator, @@ -334,18 +337,18 @@ endmethod. endmethod. - - + + method GET_RANGES_ITERATOR. eo_iterator = me->ranges->get_iterator( ). endmethod. - - - - + + + + method GET_STATIC_CELLSTYLE_GUID. " # issue 139 DATA: style LIKE LINE OF me->t_stylemapping1. @@ -368,19 +371,19 @@ endmethod. ep_guid = style-guid. endmethod. - - + + method GET_STYLES_ITERATOR. eo_iterator = me->styles->get_iterator( ). endmethod. - - - - - METHOD get_style_to_guid. + + + + + method GET_STYLE_TO_GUID. " # issue 139 READ TABLE me->t_stylemapping2 INTO ep_stylemapping WITH TABLE KEY guid = ip_guid. @@ -397,40 +400,40 @@ endmethod. ENDIF. -ENDMETHOD. +endmethod. - - + + method GET_WORKSHEETS_ITERATOR. eo_iterator = me->worksheets->get_iterator( ). endmethod. - - + + method GET_WORKSHEETS_NAME. ep_name = me->worksheets->name. endmethod. - - + + method GET_WORKSHEETS_SIZE. ep_size = me->worksheets->size( ). endmethod. - - + + method SET_ACTIVE_SHEET_INDEX. me->worksheets->active_worksheet = i_active_worksheet. endmethod. - - + + method SET_ACTIVE_SHEET_INDEX_BY_NAME. DATA: ws_it TYPE REF TO cl_object_collection_iterator, @@ -452,9 +455,9 @@ endmethod. endmethod. - - - + + + method STYLEMAPPING_DYNAMIC_STYLE. " # issue 139 eo_style2-dynamic_style_guid = ip_style->get_guid( ). diff --git a/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk b/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk index 4c7153d..2e1a6b7 100644 --- a/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk +++ b/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk @@ -85,7 +85,9 @@ public section. methods CONSTRUCTOR importing !IP_EXCEL type ref to ZCL_EXCEL - !IP_TITLE type ZEXCEL_SHEET_TITLE optional . + !IP_TITLE type ZEXCEL_SHEET_TITLE optional + raising + ZCX_EXCEL . methods DELETE_MERGE . methods FREEZE_PANES importing @@ -225,7 +227,9 @@ public section. !IP_TOP_LEFT_ROW type ZEXCEL_CELL_ROW default 3 . methods SET_TITLE importing - !IP_TITLE type ZEXCEL_SHEET_TITLE . + !IP_TITLE type ZEXCEL_SHEET_TITLE + raising + ZCX_EXCEL . methods SET_SHOW_ROWCOLHEADERS importing !I_SHOW_ROWCOLHEADERS type ZEXCEL_SHOW_ROWCOLHEADER . @@ -371,7 +375,10 @@ private section. !IP_ROW type ZEXCEL_CELL_ROW returning value(EP_WIDTH) type I . - methods UPDATE_DIMENSION_RANGE . + methods UPDATE_DIMENSION_RANGE . + methods GENERATE_TITLE + returning + value(EP_TITLE) type ZEXCEL_SHEET_TITLE . *"* local class implementation for public class *"* use this source file for the implementation part of *"* local helper classes @@ -541,19 +548,19 @@ endclass. - - - - - - - - - - - + + + + + + + + + + + - + @@ -561,9 +568,9 @@ endclass. - - - + + + method ZIF_EXCEL_SHEET_PROPERTIES~GET_STYLE. ep_style = zif_excel_sheet_properties~style. @@ -3440,10 +3447,11 @@ endmethod. endmethod. - + - method CONSTRUCTOR. + + METHOD constructor. DATA: lv_title TYPE zexcel_sheet_title. me->excel = ip_excel. @@ -3455,7 +3463,8 @@ endmethod. IF ip_title IS NOT INITIAL. lv_title = ip_title. ELSE. - lv_title = me->guid. +* lv_title = me->guid. " del issue #154 - Names of worksheets + lv_title = me->generate_title( ). " ins issue #154 - Names of worksheets ENDIF. me->set_title( ip_title = lv_title ). @@ -3481,7 +3490,7 @@ endmethod. upper_cell-cell_row = 1. upper_cell-cell_column = 1. -endmethod. +ENDMETHOD. method DELETE_MERGE. @@ -3520,6 +3529,49 @@ endmethod. freeze_pane_cell_column = ip_num_columns + 1. freeze_pane_cell_row = ip_num_rows + 1. endmethod. + + + + METHOD generate_title. + DATA: lo_worksheets_iterator TYPE REF TO cl_object_collection_iterator, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + errormessage TYPE string. + + DATA: t_titles TYPE HASHED TABLE OF zexcel_sheet_title WITH UNIQUE KEY table_line, + title TYPE zexcel_sheet_title, + sheetnumber TYPE i. + +* Get list of currently used titles + lo_worksheets_iterator = me->excel->get_worksheets_iterator( ). + WHILE lo_worksheets_iterator->has_next( ) = 'X'. + lo_worksheet ?= lo_worksheets_iterator->get_next( ). + title = lo_worksheet->get_title( ). + INSERT title INTO TABLE t_titles. + ADD 1 TO sheetnumber. + ENDWHILE. + +* Now build sheetnumber. Increase counter until we hit a number that is not used so far + add 1 to sheetnumber. " Start counting with next number + DO. + title = sheetnumber. + shift title LEFT DELETING LEADING space. + CASE sy-langu. + WHEN 'D'. " German + CONCATENATE 'Tabelle' title INTO ep_title. + + WHEN OTHERS. " Use english as default for all other languages + CONCATENATE 'Sheet' title INTO ep_title. + + ENDCASE. + INSERT ep_title INTO TABLE t_titles. + IF sy-subrc = 0. " Title not used so far --> take it + EXIT. + ENDIF. + + + ADD 1 TO sheetnumber. + ENDDO. +ENDMETHOD. @@ -3847,7 +3899,7 @@ endmethod. ep_size = tables->if_object_collection~size( ). endmethod. - + method GET_TITLE. @@ -4301,11 +4353,41 @@ endmethod. endmethod. - + - method SET_TITLE. + + 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. + + +* Check whether title consists only of allowed characters +* Illegal characters are: / \ [ ] * ? : --> http://msdn.microsoft.com/en-us/library/ff837411.aspx + IF ip_title CA '/\[]*?:'. + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = 'Found illegal character in sheetname. List of forbidden characters: /\[]*?: '. + ENDIF. + + +* Check whether title is unique in worksheet + 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 + errormessage = 'Duplicate sheetname &'. + REPLACE '&' IN errormessage WITH ip_title. + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = errormessage. + ENDIF. + ENDWHILE. + + me->title = ip_title. -endmethod. +ENDMETHOD. method UPDATE_DIMENSION_RANGE.