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 BUILD_STYLE
importing
!IP_COPY_FROM_STYLE type ANY optional
!IP_COMPLETE type ZEXCEL_S_CSTYLE_COMPLETE optional
!IP_XCOMPLETE type ZEXCEL_S_CSTYLEX_COMPLETE optional
!IP_FONT type ZEXCEL_S_CSTYLE_FONT optional
!IP_XFONT type ZEXCEL_S_CSTYLEX_FONT optional
!IP_FILL type ZEXCEL_S_CSTYLE_FILL optional
!IP_XFILL type ZEXCEL_S_CSTYLEX_FILL optional
!IP_BORDERS type ZEXCEL_S_CSTYLE_BORDERS optional
!IP_XBORDERS type ZEXCEL_S_CSTYLEX_BORDERS optional
!IP_ALIGNMENT type ZEXCEL_S_CSTYLE_ALIGNMENT optional
!IP_XALIGNMENT type ZEXCEL_S_CSTYLEX_ALIGNMENT optional
!IP_NUMBER_FORMAT_FORMAT_CODE type ZEXCEL_NUMBER_FORMAT optional
!IP_PROTECTION type ZEXCEL_S_CSTYLE_PROTECTION optional
!IP_XPROTECTION type ZEXCEL_S_CSTYLEX_PROTECTION optional
!IP_FONT_BOLD type FLAG optional
!IP_FONT_COLOR type ZEXCEL_S_STYLE_COLOR optional
!IP_FONT_COLOR_RGB type ZEXCEL_STYLE_COLOR_ARGB optional
!IP_FONT_COLOR_INDEXED type ZEXCEL_STYLE_COLOR_INDEXED optional
!IP_FONT_COLOR_THEME type ZEXCEL_STYLE_COLOR_THEME optional
!IP_FONT_COLOR_TINT type ZEXCEL_STYLE_COLOR_TINT optional
!IP_FONT_FAMILY type ZEXCEL_STYLE_FONT_FAMILY optional
!IP_FONT_ITALIC type FLAG optional
!IP_FONT_NAME type ZEXCEL_STYLE_FONT_NAME optional
!IP_FONT_SCHEME type ZEXCEL_STYLE_FONT_SCHEME optional
!IP_FONT_SIZE type ZEXCEL_STYLE_FONT_SIZE optional
!IP_FONT_STRIKETHROUGH type FLAG optional
!IP_FONT_UNDERLINE type FLAG optional
!IP_FONT_UNDERLINE_MODE type ZEXCEL_STYLE_FONT_UNDERLINE optional
!IP_FILL_FILLTYPE type ZEXCEL_FILL_TYPE optional
!IP_FILL_ROTATION type ZEXCEL_ROTATION optional
!IP_FILL_FGCOLOR type ZEXCEL_S_STYLE_COLOR optional
!IP_FILL_FGCOLOR_RGB type ZEXCEL_STYLE_COLOR_ARGB optional
!IP_FILL_FGCOLOR_INDEXED type ZEXCEL_STYLE_COLOR_INDEXED optional
!IP_FILL_FGCOLOR_THEME type ZEXCEL_STYLE_COLOR_THEME optional
!IP_FILL_FGCOLOR_TINT type ZEXCEL_STYLE_COLOR_TINT optional
!IP_FILL_BGCOLOR type ZEXCEL_S_STYLE_COLOR optional
!IP_FILL_BGCOLOR_RGB type ZEXCEL_STYLE_COLOR_ARGB optional
!IP_FILL_BGCOLOR_INDEXED type ZEXCEL_STYLE_COLOR_INDEXED optional
!IP_FILL_BGCOLOR_THEME type ZEXCEL_STYLE_COLOR_THEME optional
!IP_FILL_BGCOLOR_TINT type ZEXCEL_STYLE_COLOR_TINT optional
!IP_BORDERS_ALLBORDERS type ZEXCEL_S_CSTYLE_BORDER optional
!IP_XBORDERS_ALLBORDERS type ZEXCEL_S_CSTYLEX_BORDER optional
!IP_BORDERS_DIAGONAL type ZEXCEL_S_CSTYLE_BORDER optional
!IP_XBORDERS_DIAGONAL type ZEXCEL_S_CSTYLEX_BORDER optional
!IP_BORDERS_DIAGONAL_MODE type ZEXCEL_DIAGONAL optional
!IP_BORDERS_DOWN type ZEXCEL_S_CSTYLE_BORDER optional
!IP_XBORDERS_DOWN type ZEXCEL_S_CSTYLEX_BORDER optional
!IP_BORDERS_LEFT type ZEXCEL_S_CSTYLE_BORDER optional
!IP_XBORDERS_LEFT type ZEXCEL_S_CSTYLEX_BORDER optional
!IP_BORDERS_RIGHT type ZEXCEL_S_CSTYLE_BORDER optional
!IP_XBORDERS_RIGHT type ZEXCEL_S_CSTYLEX_BORDER optional
!IP_BORDERS_TOP type ZEXCEL_S_CSTYLE_BORDER optional
!IP_XBORDERS_TOP type ZEXCEL_S_CSTYLEX_BORDER optional
!IP_ALIGNMENT_HORIZONTAL type ZEXCEL_ALIGNMENT optional
!IP_ALIGNMENT_VERTICAL type ZEXCEL_ALIGNMENT optional
!IP_ALIGNMENT_TEXTROTATION type ZEXCEL_TEXT_ROTATION optional
!IP_ALIGNMENT_WRAPTEXT type FLAG optional
!IP_ALIGNMENT_SHRINKTOFIT type FLAG optional
!IP_ALIGNMENT_INDENT type ZEXCEL_INDENT optional
!IP_PROTECTION_HIDDEN type ZEXCEL_CELL_PROTECTION optional
!IP_PROTECTION_LOCKED type ZEXCEL_CELL_PROTECTION optional
!IP_BORDERS_ALLBORDERS_STYLE type ZEXCEL_BORDER optional
!IP_BORDERS_ALLBORDERS_COLOR type ZEXCEL_S_STYLE_COLOR optional
!IP_BORDERS_ALLBO_COLOR_RGB type ZEXCEL_STYLE_COLOR_ARGB optional
!IP_BORDERS_ALLBO_COLOR_INDEXED type ZEXCEL_STYLE_COLOR_INDEXED optional
!IP_BORDERS_ALLBO_COLOR_THEME type ZEXCEL_STYLE_COLOR_THEME optional
!IP_BORDERS_ALLBO_COLOR_TINT type ZEXCEL_STYLE_COLOR_TINT optional
!IP_BORDERS_DIAGONAL_STYLE type ZEXCEL_BORDER optional
!IP_BORDERS_DIAGONAL_COLOR type ZEXCEL_S_STYLE_COLOR optional
!IP_BORDERS_DIAGONAL_COLOR_RGB type ZEXCEL_STYLE_COLOR_ARGB optional
!IP_BORDERS_DIAGONAL_COLOR_INDE type ZEXCEL_STYLE_COLOR_INDEXED optional
!IP_BORDERS_DIAGONAL_COLOR_THEM type ZEXCEL_STYLE_COLOR_THEME optional
!IP_BORDERS_DIAGONAL_COLOR_TINT type ZEXCEL_STYLE_COLOR_TINT optional
!IP_BORDERS_DOWN_STYLE type ZEXCEL_BORDER optional
!IP_BORDERS_DOWN_COLOR type ZEXCEL_S_STYLE_COLOR optional
!IP_BORDERS_DOWN_COLOR_RGB type ZEXCEL_STYLE_COLOR_ARGB optional
!IP_BORDERS_DOWN_COLOR_INDEXED type ZEXCEL_STYLE_COLOR_INDEXED optional
!IP_BORDERS_DOWN_COLOR_THEME type ZEXCEL_STYLE_COLOR_THEME optional
!IP_BORDERS_DOWN_COLOR_TINT type ZEXCEL_STYLE_COLOR_TINT optional
!IP_BORDERS_LEFT_STYLE type ZEXCEL_BORDER optional
!IP_BORDERS_LEFT_COLOR type ZEXCEL_S_STYLE_COLOR optional
!IP_BORDERS_LEFT_COLOR_RGB type ZEXCEL_STYLE_COLOR_ARGB optional
!IP_BORDERS_LEFT_COLOR_INDEXED type ZEXCEL_STYLE_COLOR_INDEXED optional
!IP_BORDERS_LEFT_COLOR_THEME type ZEXCEL_STYLE_COLOR_THEME optional
!IP_BORDERS_LEFT_COLOR_TINT type ZEXCEL_STYLE_COLOR_TINT optional
!IP_BORDERS_RIGHT_STYLE type ZEXCEL_BORDER optional
!IP_BORDERS_RIGHT_COLOR type ZEXCEL_S_STYLE_COLOR optional
!IP_BORDERS_RIGHT_COLOR_RGB type ZEXCEL_STYLE_COLOR_ARGB optional
!IP_BORDERS_RIGHT_COLOR_INDEXED type ZEXCEL_STYLE_COLOR_INDEXED optional
!IP_BORDERS_RIGHT_COLOR_THEME type ZEXCEL_STYLE_COLOR_THEME optional
!IP_BORDERS_RIGHT_COLOR_TINT type ZEXCEL_STYLE_COLOR_TINT optional
!IP_BORDERS_TOP_STYLE type ZEXCEL_BORDER optional
!IP_BORDERS_TOP_COLOR type ZEXCEL_S_STYLE_COLOR optional
!IP_BORDERS_TOP_COLOR_RGB type ZEXCEL_STYLE_COLOR_ARGB optional
!IP_BORDERS_TOP_COLOR_INDEXED type ZEXCEL_STYLE_COLOR_INDEXED optional
!IP_BORDERS_TOP_COLOR_THEME type ZEXCEL_STYLE_COLOR_THEME optional
!IP_BORDERS_TOP_COLOR_TINT type ZEXCEL_STYLE_COLOR_TINT optional
returning
value(EP_GUID) type ZEXCEL_CELL_STYLE
raising
ZCX_EXCEL .
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_INDEX_IN_STYLES
importing
!IP_GUID type ZEXCEL_CELL_STYLE
returning
value(EP_INDEX) type SYTABIX
raising
ZCX_EXCEL .
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 .
methods SET_DEFAULT_STYLE
importing
!IP_STYLE type ZEXCEL_CELL_STYLE
raising
ZCX_EXCEL .
methods GET_DEFAULT_STYLE
returning
value(EP_STYLE) type ZEXCEL_CELL_STYLE .*"* protected components of class ZCL_EXCEL
*"* do not include other source files here!!!
protected section.*"* private components of class ZCL_EXCEL
*"* do not include other source files here!!!
private section.
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 .
data DEFAULT_STYLE type ZEXCEL_CELL_STYLE .
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 classmethod 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 BUILD_STYLE.
DATA: stylemapping TYPE zexcel_s_stylemapping,
complete_style TYPE zexcel_s_cstyle_complete,
complete_stylex TYPE zexcel_s_cstylex_complete,
borderx TYPE zexcel_s_cstylex_border.
* We have a lot of parameters. Use some macros to make the coding more structured
DEFINE clear_initial_colorxfields.
if &1-rgb is initial.
clear &2-rgb.
endif.
if &1-indexed is initial.
clear &2-indexed.
endif.
if &1-theme is initial.
clear &2-theme.
endif.
if &1-tint is initial.
clear &2-tint.
endif.
END-OF-DEFINITION.
DEFINE move_supplied_borders.
if ip_&1 is supplied. " only act if parameter was supplied
if ip_x&1 is supplied. "
borderx = ip_x&1. " use supplied x-parameter
else.
clear borderx with 'X'.
* clear in a way that would be expected to work easily
if ip_&1-border_style is initial.
clear borderx-border_style.
endif.
clear_initial_colorxfields ip_&1-border_color borderx-border_color.
endif.
move-corresponding ip_&1 to complete_style-&2.
move-corresponding borderx to complete_stylex-&2.
endif.
END-OF-DEFINITION.
** First get current stylsettings
* TRY.
* me->get_cell( EXPORTING ip_column = ip_column " Cell Column
* ip_row = ip_row " Cell Row
* IMPORTING ep_guid = guid )." Cell Value ).
*
*
* stylemapping = me->excel->get_style_to_guid( guid ).
* complete_style = stylemapping-complete_style.
* complete_stylex = stylemapping-complete_stylex.
* CATCH zcx_excel.
** Error --> use submitted style
* ENDTRY.
if ip_copy_from_style is SUPPLIED.
RAISE EXCEPTION TYPE zcx_excel
EXPORTING
error = 'Work in progress - copy from style not implemented yet'.
endif.
* move_supplied_multistyles: complete.
IF ip_complete IS SUPPLIED.
IF ip_xcomplete IS NOT SUPPLIED.
RAISE EXCEPTION TYPE zcx_excel
EXPORTING
error = 'Complete styleinfo has to be supplied with corresponding X-field'.
ENDIF.
MOVE-CORRESPONDING ip_complete TO complete_style.
MOVE-CORRESPONDING ip_xcomplete TO complete_stylex.
ENDIF.
IF ip_font IS SUPPLIED.
DATA: fontx LIKE ip_xfont.
IF ip_xfont IS SUPPLIED.
fontx = ip_xfont.
ELSE.
* Only supplied values should be used - exception: Flags bold and italic strikethrough underline
MOVE 'X' TO: fontx-bold,
fontx-italic,
fontx-strikethrough,
fontx-underline_mode.
CLEAR fontx-color WITH 'X'.
clear_initial_colorxfields ip_font-color fontx-color.
IF ip_font-family IS NOT INITIAL.
fontx-family = 'X'.
ENDIF.
IF ip_font-name IS NOT INITIAL.
fontx-name = 'X'.
ENDIF.
IF ip_font-scheme IS NOT INITIAL.
fontx-scheme = 'X'.
ENDIF.
IF ip_font-size IS NOT INITIAL.
fontx-size = 'X'.
ENDIF.
IF ip_font-underline_mode IS NOT INITIAL.
fontx-underline_mode = 'X'.
ENDIF.
ENDIF.
MOVE-CORRESPONDING ip_font TO complete_style-font.
MOVE-CORRESPONDING fontx TO complete_stylex-font.
* Correction for undeline mode
ENDIF.
IF ip_fill IS SUPPLIED.
DATA: fillx LIKE ip_xfill.
IF ip_xfill IS SUPPLIED.
fillx = ip_xfill.
ELSE.
CLEAR fillx WITH 'X'.
IF ip_fill-filltype IS INITIAL.
CLEAR fillx-filltype.
ENDIF.
clear_initial_colorxfields ip_fill-fgcolor fillx-fgcolor.
clear_initial_colorxfields ip_fill-bgcolor fillx-bgcolor.
ENDIF.
MOVE-CORRESPONDING ip_fill TO complete_style-fill.
MOVE-CORRESPONDING fillx TO complete_stylex-fill.
ENDIF.
IF ip_borders IS SUPPLIED.
DATA: bordersx LIKE ip_xborders.
IF ip_xborders IS SUPPLIED.
bordersx = ip_xborders.
ELSE.
CLEAR bordersx WITH 'X'.
IF ip_borders-allborders-border_style IS INITIAL.
CLEAR bordersx-allborders-border_style.
ENDIF.
IF ip_borders-diagonal-border_style IS INITIAL.
CLEAR bordersx-diagonal-border_style.
ENDIF.
IF ip_borders-down-border_style IS INITIAL.
CLEAR bordersx-down-border_style.
ENDIF.
IF ip_borders-left-border_style IS INITIAL.
CLEAR bordersx-left-border_style.
ENDIF.
IF ip_borders-right-border_style IS INITIAL.
CLEAR bordersx-right-border_style.
ENDIF.
IF ip_borders-top-border_style IS INITIAL.
CLEAR bordersx-top-border_style.
ENDIF.
clear_initial_colorxfields ip_borders-allborders-border_color bordersx-allborders-border_color.
clear_initial_colorxfields ip_borders-diagonal-border_color bordersx-diagonal-border_color.
clear_initial_colorxfields ip_borders-down-border_color bordersx-down-border_color.
clear_initial_colorxfields ip_borders-left-border_color bordersx-left-border_color.
clear_initial_colorxfields ip_borders-right-border_color bordersx-right-border_color.
clear_initial_colorxfields ip_borders-top-border_color bordersx-top-border_color.
ENDIF.
MOVE-CORRESPONDING ip_borders TO complete_style-borders.
MOVE-CORRESPONDING bordersx TO complete_stylex-borders.
ENDIF.
IF ip_alignment IS SUPPLIED.
DATA: alignmentx LIKE ip_xalignment.
IF ip_xalignment IS SUPPLIED.
alignmentx = ip_xalignment.
ELSE.
CLEAR alignmentx WITH 'X'.
IF ip_alignment-horizontal IS INITIAL.
CLEAR alignmentx-horizontal.
ENDIF.
IF ip_alignment-vertical IS INITIAL.
CLEAR alignmentx-vertical.
ENDIF.
ENDIF.
MOVE-CORRESPONDING ip_alignment TO complete_style-alignment.
MOVE-CORRESPONDING alignmentx TO complete_stylex-alignment.
ENDIF.
IF ip_protection IS SUPPLIED.
MOVE-CORRESPONDING ip_alignment TO complete_style-alignment.
IF ip_xprotection IS SUPPLIED.
MOVE-CORRESPONDING ip_xprotection TO complete_stylex-protection.
ELSE.
IF ip_protection-hidden IS NOT INITIAL.
complete_style-protection-hidden = 'X'.
ENDIF.
IF ip_protection-locked IS NOT INITIAL.
complete_style-protection-locked = 'X'.
ENDIF.
ENDIF.
ENDIF.
move_supplied_borders : borders_allborders borders-allborders,
borders_diagonal borders-diagonal ,
borders_down borders-down ,
borders_left borders-left ,
borders_right borders-right ,
borders_top borders-top .
DEFINE move_supplied_singlestyles.
if ip_&1 is supplied.
complete_style-&2 = ip_&1.
complete_stylex-&2 = 'X'.
endif.
END-OF-DEFINITION.
move_supplied_singlestyles: number_format_format_code number_format-format_code,
font_bold font-bold,
font_color font-color,
font_color_rgb font-color-rgb,
font_color_indexed font-color-indexed,
font_color_theme font-color-theme,
font_color_tint font-color-tint,
font_family font-family,
font_italic font-italic,
font_name font-name,
font_scheme font-scheme,
font_size font-size,
font_strikethrough font-strikethrough,
font_underline font-underline,
font_underline_mode font-underline_mode,
fill_filltype fill-filltype,
fill_rotation fill-rotation,
fill_fgcolor fill-fgcolor,
fill_fgcolor_rgb fill-fgcolor-rgb,
fill_fgcolor_indexed fill-fgcolor-indexed,
fill_fgcolor_theme fill-fgcolor-theme,
fill_fgcolor_tint fill-fgcolor-tint,
fill_bgcolor fill-bgcolor,
fill_bgcolor_rgb fill-bgcolor-rgb,
fill_bgcolor_indexed fill-bgcolor-indexed,
fill_bgcolor_theme fill-bgcolor-theme,
fill_bgcolor_tint fill-bgcolor-tint,
borders_diagonal_mode borders-diagonal_mode,
alignment_horizontal alignment-horizontal,
alignment_vertical alignment-vertical,
alignment_textrotation alignment-textrotation,
alignment_wraptext alignment-wraptext,
alignment_shrinktofit alignment-shrinktofit,
alignment_indent alignment-indent,
protection_hidden protection-hidden,
protection_locked protection-locked,
borders_allborders_style borders-allborders-border_style,
borders_allborders_color borders-allborders-border_color,
borders_allbo_color_rgb borders-allborders-border_color-rgb,
borders_allbo_color_indexed borders-allborders-border_color-indexed,
borders_allbo_color_theme borders-allborders-border_color-theme,
borders_allbo_color_tint borders-allborders-border_color-tint,
borders_diagonal_style borders-diagonal-border_style,
borders_diagonal_color borders-diagonal-border_color,
borders_diagonal_color_rgb borders-diagonal-border_color-rgb,
borders_diagonal_color_inde borders-diagonal-border_color-indexed,
borders_diagonal_color_them borders-diagonal-border_color-theme,
borders_diagonal_color_tint borders-diagonal-border_color-tint,
borders_down_style borders-down-border_style,
borders_down_color borders-down-border_color,
borders_down_color_rgb borders-down-border_color-rgb,
borders_down_color_indexed borders-down-border_color-indexed,
borders_down_color_theme borders-down-border_color-theme,
borders_down_color_tint borders-down-border_color-tint,
borders_left_style borders-left-border_style,
borders_left_color borders-left-border_color,
borders_left_color_rgb borders-left-border_color-rgb,
borders_left_color_indexed borders-left-border_color-indexed,
borders_left_color_theme borders-left-border_color-theme,
borders_left_color_tint borders-left-border_color-tint,
borders_right_style borders-right-border_style,
borders_right_color borders-right-border_color,
borders_right_color_rgb borders-right-border_color-rgb,
borders_right_color_indexed borders-right-border_color-indexed,
borders_right_color_theme borders-right-border_color-theme,
borders_right_color_tint borders-right-border_color-tint,
borders_top_style borders-top-border_style,
borders_top_color borders-top-border_color,
borders_top_color_rgb borders-top-border_color-rgb,
borders_top_color_indexed borders-top-border_color-indexed,
borders_top_color_theme borders-top-border_color-theme,
borders_top_color_tint borders-top-border_color-tint.
* Now we have a completly filled styles.
* This can be used to get the guid
* Return guid if requested. Might be used if copy&paste of styles is requested
ep_guid = me->get_static_cellstyle_guid( ip_cstyle_complete = complete_style
ip_cstylex_complete = complete_stylex ).
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_default_style.
ep_style = me->default_style.
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_index_in_styles.
DATA: index TYPE syindex.
DATA: lo_iterator TYPE REF TO cl_object_collection_iterator,
lo_style TYPE REF TO zcl_excel_style.
CHECK ip_guid IS NOT INITIAL.
lo_iterator = me->get_styles_iterator( ).
WHILE lo_iterator->has_next( ) = 'X'.
ADD 1 TO index.
lo_style ?= lo_iterator->get_next( ).
IF lo_style->get_guid( ) = ip_guid.
ep_index = index.
EXIT.
ENDIF.
ENDWHILE.
IF ep_index IS INITIAL.
RAISE EXCEPTION TYPE zcx_excel
EXPORTING
error = 'Index not found'.
else.
SUBTRACT 1 from ep_index. " In excel list starts with "0"
ENDIF.
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 set_default_style.
me->default_style = ip_style.
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.