class ZCL_EXCEL definition public final create public . public section. *"* public components of class ZCL_EXCEL *"* do not include other source files here!!! interfaces ZIF_EXCEL_BOOK_PROTECTION . interfaces ZIF_EXCEL_BOOK_VBA_PROJECT . interfaces ZIF_EXCEL_BOOK_PROPERTIES . data SECURITY type ref to ZCL_EXCEL_SECURITY . data LEGACY_PALETTE type ref to ZCL_EXCEL_LEGACY_PALETTE read-only . 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 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 . 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_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_STYLES_ITERATOR returning value(EO_ITERATOR) type ref to CL_OBJECT_COLLECTION_ITERATOR . 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 . *"* 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_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 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 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. * Create default style CREATE OBJECT eo_style. styles->add( eo_style ). 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 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. 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_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_STYLES_ITERATOR. eo_iterator = me->styles->get_iterator( ). 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.