class ZCL_EXCEL definition public final create public . *"* 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 . interfaces ZIF_EXCEL_BOOK_VBA_PROJECT . data SECURITY type ref to ZCL_EXCEL_SECURITY . data LEGACY_PALETTE type ref to ZCL_EXCEL_LEGACY_PALETTE read-only . methods ADD_NEW_AUTOFILTER importing !IO_SHEET type ref to ZCL_EXCEL_WORKSHEET returning value(RO_AUTOFILTER) type ref to ZCL_EXCEL_AUTOFILTER . methods ADD_NEW_DRAWING importing !IP_TITLE type ZEXCEL_SHEET_TITLE optional returning value(EO_DRAWING) type ref to ZCL_EXCEL_DRAWING . methods ADD_NEW_RANGE returning value(EO_RANGE) type ref to ZCL_EXCEL_RANGE . methods ADD_NEW_STYLE importing !IP_GUID type ZEXCEL_CELL_STYLE optional returning value(EO_STYLE) type ref to ZCL_EXCEL_STYLE . methods ADD_NEW_WORKSHEET importing !IP_TITLE type ZEXCEL_SHEET_TITLE optional returning value(EO_WORKSHEET) type ref to ZCL_EXCEL_WORKSHEET raising ZCX_EXCEL . methods ADD_STATIC_STYLES . methods CONSTRUCTOR . methods GET_ACTIVE_SHEET_INDEX returning value(R_ACTIVE_WORKSHEET) type ZEXCEL_ACTIVE_WORKSHEET . methods GET_ACTIVE_WORKSHEET returning value(EO_WORKSHEET) type ref to ZCL_EXCEL_WORKSHEET . methods GET_AUTOFILTERS_REFERENCE returning value(RO_AUTOFILTERS) type ref to ZCL_EXCEL_AUTOFILTERS . methods GET_DRAWINGS_ITERATOR returning value(EO_ITERATOR) type ref to CL_OBJECT_COLLECTION_ITERATOR . methods GET_NEXT_TABLE_ID returning value(EP_ID) type I . methods GET_RANGES_ITERATOR returning value(EO_ITERATOR) type ref to CL_OBJECT_COLLECTION_ITERATOR . methods GET_STATIC_CELLSTYLE_GUID importing !IP_CSTYLE_COMPLETE type ZEXCEL_S_CSTYLE_COMPLETE !IP_CSTYLEX_COMPLETE type ZEXCEL_S_CSTYLEX_COMPLETE returning value(EP_GUID) type ZEXCEL_CELL_STYLE . methods GET_STYLES_ITERATOR returning value(EO_ITERATOR) type ref to CL_OBJECT_COLLECTION_ITERATOR . methods GET_STYLE_TO_GUID importing !IP_GUID type ZEXCEL_CELL_STYLE returning value(EP_STYLEMAPPING) type ZEXCEL_S_STYLEMAPPING raising ZCX_EXCEL . methods GET_WORKSHEETS_ITERATOR returning value(EO_ITERATOR) type ref to CL_OBJECT_COLLECTION_ITERATOR . methods GET_WORKSHEETS_NAME returning value(EP_NAME) type ZEXCEL_WORKSHEETS_NAME . methods GET_WORKSHEETS_SIZE returning value(EP_SIZE) type I . methods SET_ACTIVE_SHEET_INDEX importing !I_ACTIVE_WORKSHEET type ZEXCEL_ACTIVE_WORKSHEET . methods SET_ACTIVE_SHEET_INDEX_BY_NAME importing !I_WORKSHEET_NAME type ZEXCEL_WORKSHEETS_NAME . *"* protected components of class ZCL_EXCEL *"* do not include other source files here!!! protected section. private section. *"* private components of class ZCL_EXCEL *"* do not include other source files here!!! data DRAWINGS type ref to ZCL_EXCEL_DRAWINGS . data RANGES type ref to ZCL_EXCEL_RANGES . data STYLES type ref to ZCL_EXCEL_STYLES . data WORKSHEETS type ref to ZCL_EXCEL_WORKSHEETS . data AUTOFILTERS type ref to ZCL_EXCEL_AUTOFILTERS . data T_STYLEMAPPING1 type ZEXCEL_T_STYLEMAPPING1 . data T_STYLEMAPPING2 type ZEXCEL_T_STYLEMAPPING2 . methods STYLEMAPPING_DYNAMIC_STYLE importing !IP_STYLE type ref to ZCL_EXCEL_STYLE returning value(EO_STYLE2) type ZEXCEL_S_STYLEMAPPING . *"* local class implementation for public class *"* use this source file for the implementation part of *"* local helper classes *"* use this source file for any type declarations (class *"* definitions, interfaces or data types) you need for method *"* 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. me->zif_excel_book_properties~application = 'Microsoft Excel'. me->zif_excel_book_properties~appversion = '12.0000'. GET TIME STAMP FIELD lv_timestamp. me->zif_excel_book_properties~created = lv_timestamp. me->zif_excel_book_properties~creator = sy-uname. me->zif_excel_book_properties~modified = lv_timestamp. me->zif_excel_book_properties~lastmodifiedby = sy-uname. endmethod. method ZIF_EXCEL_BOOK_PROTECTION~INITIALIZE. me->zif_excel_book_protection~protected = zif_excel_book_protection=>c_unprotected. me->zif_excel_book_protection~lockrevision = zif_excel_book_protection=>c_unlocked. me->zif_excel_book_protection~lockstructure = zif_excel_book_protection=>c_unlocked. me->zif_excel_book_protection~lockwindows = zif_excel_book_protection=>c_unlocked. CLEAR me->zif_excel_book_protection~workbookpassword. CLEAR me->zif_excel_book_protection~revisionspassword. endmethod. method ZIF_EXCEL_BOOK_VBA_PROJECT~SET_CODENAME. me->zif_excel_book_vba_project~codename = ip_codename. endmethod. method ZIF_EXCEL_BOOK_VBA_PROJECT~SET_CODENAME_PR. me->zif_excel_book_vba_project~codename_pr = ip_codename_pr. endmethod. method ZIF_EXCEL_BOOK_VBA_PROJECT~SET_VBAPROJECT. 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 CREATE OBJECT eo_drawing EXPORTING ip_title = ip_title. 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. * Start of deletion # issue 139 - Dateretention of cellstyles * CREATE OBJECT eo_style. * styles->add( eo_style ). * End of deletion # issue 139 - Dateretention of cellstyles * Start of insertion # issue 139 - Dateretention of cellstyles * Create default style CREATE OBJECT eo_style EXPORTING ip_guid = ip_guid. styles->add( eo_style ). DATA: style2 TYPE zexcel_s_stylemapping. * Copy to new representations style2 = stylemapping_dynamic_style( eo_style ). INSERT style2 INTO TABLE t_stylemapping1. INSERT style2 INTO TABLE t_stylemapping2. * End of insertion # issue 139 - Dateretention of cellstyles endmethod. method ADD_NEW_WORKSHEET. DATA: lv_guid TYPE guid_16. * Create default blank worksheet CREATE OBJECT eo_worksheet EXPORTING ip_excel = me ip_title = ip_title. worksheets->add( eo_worksheet ). worksheets->active_worksheet = worksheets->size( ). endmethod. 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 * 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 FIELD-SYMBOLS: <style1> LIKE LINE OF t_stylemapping1, <style2> LIKE LINE OF t_stylemapping2. DATA: style TYPE REF TO zcl_excel_style. LOOP AT me->t_stylemapping1 ASSIGNING <style1> WHERE added_to_iterator IS INITIAL. READ TABLE me->t_stylemapping2 ASSIGNING <style2> WITH TABLE KEY guid = <style1>-guid. CHECK sy-subrc = 0. " Should always be true since these tables are being filled parallel style = me->add_new_style( <style1>-guid ). zcl_excel_common=>recursive_struct_to_class( EXPORTING i_source = <style1>-complete_style i_sourcex = <style1>-complete_stylex CHANGING e_target = style ). ENDLOOP. endmethod. method CONSTRUCTOR. DATA: lo_worksheet TYPE REF TO zcl_excel_worksheet, lo_style TYPE REF TO zcl_excel_style. * Inizialize instance objects CREATE OBJECT security. CREATE OBJECT worksheets. CREATE OBJECT ranges. CREATE OBJECT styles. CREATE OBJECT drawings. CREATE OBJECT legacy_palette. CREATE OBJECT autofilters. me->zif_excel_book_protection~initialize( ). me->zif_excel_book_properties~initialize( ). me->add_new_worksheet( ). me->add_new_style( ). " Standard style lo_style = me->add_new_style( ). " Standard style with fill gray125 lo_style->fill->filltype = zcl_excel_style_fill=>c_fill_pattern_gray125. 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, lv_tables_count TYPE i. lo_iterator = me->get_worksheets_iterator( ). WHILE lo_iterator->if_object_collection_iterator~has_next( ) EQ abap_true. lo_worksheet ?= lo_iterator->if_object_collection_iterator~get_next( ). lv_tables_count = lo_worksheet->get_tables_size( ). ADD lv_tables_count TO ep_id. ENDWHILE. ADD 1 TO ep_id. 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. READ TABLE me->t_stylemapping1 INTO style WITH TABLE KEY dynamic_style_guid = style-guid " no dynamic style --> look for initial guid here complete_style = ip_cstyle_complete complete_stylex = ip_cstylex_complete. IF sy-subrc <> 0. style-complete_style = ip_cstyle_complete. style-complete_stylex = ip_cstylex_complete. CALL FUNCTION 'GUID_CREATE' IMPORTING ev_guid_16 = style-guid. INSERT style INTO TABLE me->t_stylemapping1. INSERT style INTO TABLE me->t_stylemapping2. ENDIF. ep_guid = style-guid. endmethod. method GET_STYLES_ITERATOR. eo_iterator = me->styles->get_iterator( ). endmethod. method GET_STYLE_TO_GUID. " # issue 139 READ TABLE me->t_stylemapping2 INTO ep_stylemapping WITH TABLE KEY guid = ip_guid. IF sy-subrc <> 0. RAISE EXCEPTION TYPE zcx_excel EXPORTING error = 'GUID not found'. ENDIF. IF ep_stylemapping-dynamic_style_guid IS NOT INITIAL. zcl_excel_common=>recursive_class_to_struct( EXPORTING i_source = ep_stylemapping-cl_style CHANGING e_target = ep_stylemapping-complete_style e_targetx = ep_stylemapping-complete_stylex ). ENDIF. 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, ws TYPE REF TO zcl_excel_worksheet, lv_title TYPE ZEXCEL_SHEET_TITLE, count TYPE i VALUE 1. ws_it = me->worksheets->get_iterator( ). WHILE ws_it->if_object_collection_iterator~has_next( ) = abap_true. ws ?= ws_it->if_object_collection_iterator~get_next( ). lv_title = ws->get_title( ). IF lv_title = i_worksheet_name. me->worksheets->active_worksheet = count. EXIT. ENDIF. count = count + 1. ENDWHILE. endmethod. method STYLEMAPPING_DYNAMIC_STYLE. " # issue 139 eo_style2-dynamic_style_guid = ip_style->get_guid( ). eo_style2-guid = eo_style2-dynamic_style_guid. eo_style2-added_to_iterator = abap_true. eo_style2-cl_style = ip_style. * don't care about attributes here, since this data may change * dynamically endmethod.