From b47788b58e680fed9e1bb88c82cfba342914d038 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Schm=C3=B6cker?= Date: Wed, 4 Apr 2012 22:03:54 +0000 Subject: [PATCH] Issue #157, 2nd topic:Allow default styles for columns, sheet or whole document Added demoreport 36 to demonstrate this git-svn-id: https://subversion.assembla.com/svn/abap2xlsx/trunk@292 b7d68dce-7c3c-4a99-8ce0-9ea847f5d049 --- ZA2X/CLAS/ZCL_EXCEL.slnk | 699 ++++++++++++++++-- ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk | 20 +- ZA2X/CLAS/ZCL_EXCEL_WORKSHEET_COLUMNDIME.slnk | 163 ++-- ZA2X/CLAS/ZCL_EXCEL_WRITER_2007.slnk | 227 +++--- ZA2X/PROG/ZDEMO_EXCEL36.slnk | 106 +++ 5 files changed, 1003 insertions(+), 212 deletions(-) create mode 100644 ZA2X/PROG/ZDEMO_EXCEL36.slnk diff --git a/ZA2X/CLAS/ZCL_EXCEL.slnk b/ZA2X/CLAS/ZCL_EXCEL.slnk index 1d026d5..e5c7584 100644 --- a/ZA2X/CLAS/ZCL_EXCEL.slnk +++ b/ZA2X/CLAS/ZCL_EXCEL.slnk @@ -1,8 +1,9 @@ - - - - + + + + + class ZCL_EXCEL definition public final @@ -45,6 +46,109 @@ public section. 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 @@ -73,6 +177,13 @@ public section. 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 @@ -94,13 +205,21 @@ public section. !I_ACTIVE_WORKSHEET type ZEXCEL_ACTIVE_WORKSHEET . methods SET_ACTIVE_SHEET_INDEX_BY_NAME importing - !I_WORKSHEET_NAME type ZEXCEL_WORKSHEETS_NAME . + !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 section. -*"* private components of class ZCL_EXCEL + *"* 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 . @@ -109,6 +228,7 @@ protected section. 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 @@ -123,15 +243,16 @@ 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. @@ -171,17 +292,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 @@ -191,17 +312,17 @@ 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. * Start of deletion # issue 139 - Dateretention of cellstyles * CREATE OBJECT eo_style. @@ -223,10 +344,10 @@ endmethod. endmethod. - - - - + + + + method ADD_NEW_WORKSHEET. DATA: lv_guid TYPE guid_16. * Create default blank worksheet @@ -238,7 +359,7 @@ endmethod. 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 @@ -263,7 +384,405 @@ endmethod. 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. @@ -287,38 +806,44 @@ 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_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, @@ -337,18 +862,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. @@ -371,18 +896,49 @@ endmethod. 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 @@ -402,38 +958,38 @@ 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, @@ -455,9 +1011,16 @@ endmethod. 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( ). diff --git a/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk b/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk index 41f539a..4f83636 100644 --- a/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk +++ b/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk @@ -592,9 +592,13 @@ endclass. - method ZIF_EXCEL_SHEET_PROPERTIES~GET_STYLE. - ep_style = zif_excel_sheet_properties~style. -endmethod. + METHOD zif_excel_sheet_properties~get_style. + IF zif_excel_sheet_properties~style IS NOT INITIAL. + ep_style = zif_excel_sheet_properties~style. + ELSE. + ep_style = me->excel->get_default_style( ). + ENDIF. +ENDMETHOD. method ZIF_EXCEL_SHEET_PROPERTIES~INITIALIZE. @@ -3646,9 +3650,9 @@ endmethod. - method GET_COLUMN_DIMENSION. + METHOD get_column_dimension. FIELD-SYMBOLS: <fs_column_dimension> LIKE LINE OF column_dimensions. - data: lv_column_alpha type ZEXCEL_CELL_COLUMN_ALPHA. " issue #155 - less restrictive typing for ip_column + DATA: lv_column_alpha TYPE zexcel_cell_column_alpha. " issue #155 - less restrictive typing for ip_column lv_column_alpha = zcl_excel_common=>convert_column2alpha( ip_column )." issue #155 - less restrictive typing for ip_column READ TABLE me->column_dimensions ASSIGNING <fs_column_dimension> @@ -3657,7 +3661,9 @@ endmethod. IF NOT <fs_column_dimension> IS ASSIGNED. CREATE OBJECT r_column_dimension EXPORTING - ip_index = lv_column_alpha. " issue #155 - less restrictive typing for ip_column + ip_index = lv_column_alpha " issue #155 - less restrictive typing for ip_column + ip_excel = me->excel " issue #157 - Allow style for columns + ip_worksheet = me. " issue #157 - Allow style for columns APPEND INITIAL LINE TO me->column_dimensions ASSIGNING <fs_column_dimension>. <fs_column_dimension>-column = lv_column_alpha. " issue #155 - less restrictive typing for ip_column <fs_column_dimension>-column_dimension = r_column_dimension. @@ -3665,7 +3671,7 @@ endmethod. r_column_dimension = <fs_column_dimension>-column_dimension. ENDIF. -endmethod. +ENDMETHOD. diff --git a/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET_COLUMNDIME.slnk b/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET_COLUMNDIME.slnk index 8ece7b0..8d2d49d 100644 --- a/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET_COLUMNDIME.slnk +++ b/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET_COLUMNDIME.slnk @@ -1,5 +1,6 @@ - + + class ZCL_EXCEL_WORKSHEET_COLUMNDIME definition public final @@ -12,7 +13,9 @@ public section. methods CONSTRUCTOR importing - !IP_INDEX type ZEXCEL_CELL_COLUMN_ALPHA . + !IP_INDEX type ZEXCEL_CELL_COLUMN_ALPHA + !IP_WORKSHEET type ref to ZCL_EXCEL_WORKSHEET + !IP_EXCEL type ref to ZCL_EXCEL . methods GET_AUTO_SIZE returning value(R_AUTO_SIZE) type ABAP_BOOL . @@ -68,7 +71,17 @@ public section. importing !IP_XF_INDEX type INT4 returning - value(R_WORKSHEET_COLUMNDIME) type ref to ZCL_EXCEL_WORKSHEET_COLUMNDIME . + value(R_WORKSHEET_COLUMNDIME) type ref to ZCL_EXCEL_WORKSHEET_COLUMNDIME . + methods SET_COLUMN_STYLE_BY_GUID + importing + !IP_STYLE_GUID type ZEXCEL_CELL_STYLE + raising + ZCX_EXCEL . + methods GET_COLUMN_STYLE_GUID + returning + value(EP_STYLE_GUID) type ZEXCEL_CELL_STYLE + raising + ZCX_EXCEL . *"* protected components of class ZCL_EXCEL_WORKSHEET_COLUMNDIME *"* do not include other source files here!!! protected section. @@ -78,12 +91,14 @@ private section. data COLUMN_INDEX type INT4 . data WIDTH type FLOAT . - type-pools ABAP . data AUTO_SIZE type ABAP_BOOL . data VISIBLE type ABAP_BOOL . data OUTLINE_LEVEL type INT4 . data COLLAPSED type ABAP_BOOL . - data XF_INDEX type INT4 . + data XF_INDEX type INT4 . + data STYLE_GUID type ZEXCEL_CELL_STYLE . + data EXCEL type ref to ZCL_EXCEL . + data WORKSHEET type ref to ZCL_EXCEL_WORKSHEET . *"* local class implementation for public class *"* use this source file for the implementation part of *"* local helper classes @@ -94,125 +109,165 @@ private section. *"* in the implementation part of the class ABAP - - - - - - - - - - method CONSTRUCTOR. + + + + + + + + + + + + + + + METHOD constructor. me->column_index = zcl_excel_common=>convert_column2int( ip_index ). me->width = -1. me->auto_size = abap_false. me->visible = abap_true. me->outline_level = 0. me->collapsed = abap_false. + me->excel = ip_excel. "ins issue #157 - Allow Style for columns + me->worksheet = ip_worksheet. "ins issue #157 - Allow Style for columns " set default index to cellXf me->xf_index = 0. -endmethod. + +ENDMETHOD. - - + + method GET_AUTO_SIZE. r_auto_size = me->auto_size. endmethod. - - + + method GET_COLLAPSED. r_Collapsed = me->Collapsed. endmethod. - - + + method GET_COLUMN_INDEX. r_column_index = me->column_index. endmethod. - - + + + + METHOD get_column_style_guid. + IF me->style_guid IS NOT INITIAL. + ep_style_guid = me->style_guid. + ELSE. + ep_style_guid = me->worksheet->zif_excel_sheet_properties~get_style( ). + ENDIF. +ENDMETHOD. + + + method GET_OUTLINE_LEVEL. r_outline_level = me->outline_level. endmethod. - - + + method GET_VISIBLE. r_Visible = me->Visible. endmethod. - - + + method GET_WIDTH. r_WIDTH = me->WIDTH. endmethod. - - + + method GET_XF_INDEX. r_xf_index = me->xf_index. endmethod. - - - + + + method SET_AUTO_SIZE. me->auto_size = ip_auto_size. r_worksheet_columndime = me. endmethod. - - - + + + method SET_COLLAPSED. me->Collapsed = ip_Collapsed. r_worksheet_columndime = me. endmethod. - - - + + + method SET_COLUMN_INDEX. me->column_index = zcl_excel_common=>convert_column2int( ip_index ). r_worksheet_columndime = me. endmethod. - - + + + + METHOD set_column_style_by_guid. + DATA: stylemapping TYPE zexcel_s_stylemapping. + + IF me->excel IS NOT BOUND. + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = 'Internal error - reference to ZCL_EXCEL not bound'. + ENDIF. + TRY. + stylemapping = me->excel->get_style_to_guid( ip_style_guid ). + me->style_guid = stylemapping-guid. + + CATCH zcx_excel . + EXIT. " leave as is in case of error + ENDTRY. + +ENDMETHOD. + + + method SET_OUTLINE_LEVEL. me->outline_level = ip_outline_level. endmethod. - - - + + + method SET_VISIBLE. me->Visible = ip_Visible. r_worksheet_columndime = me. endmethod. - - - - - METHOD set_width. + + + + + method SET_WIDTH. TRY. me->width = ip_width. r_worksheet_columndime = me. CATCH cx_sy_conversion_no_number. RAISE EXCEPTION TYPE zcx_excel EXPORTING - error = 'Unable to interpret ip_row_height as number'. + error = 'Unable to interpret width as number'. ENDTRY. -ENDMETHOD. +endmethod. - - - + + + method SET_XF_INDEX. me->XF_INDEX = ip_XF_INDEX. r_worksheet_columndime = me. diff --git a/ZA2X/CLAS/ZCL_EXCEL_WRITER_2007.slnk b/ZA2X/CLAS/ZCL_EXCEL_WRITER_2007.slnk index 2f219c0..3dd3123 100644 --- a/ZA2X/CLAS/ZCL_EXCEL_WRITER_2007.slnk +++ b/ZA2X/CLAS/ZCL_EXCEL_WRITER_2007.slnk @@ -1,6 +1,7 @@ - - - + + + + class ZCL_EXCEL_WRITER_2007 definition public create public . @@ -10,9 +11,9 @@ public section. *"* do not include other source files here!!! interfaces ZIF_EXCEL_WRITER . - protected section. -*"* protected components of class ZCL_EXCEL_WRITER_2007 + *"* protected components of class ZCL_EXCEL_WRITER_2007 *"* do not include other source files here!!! +protected section. constants C_CONTENT_TYPES type STRING value '[Content_Types].xml'. "#EC NOTEXT constants C_DOCPROPS_APP type STRING value 'docProps/app.xml'. "#EC NOTEXT @@ -66,7 +67,9 @@ public section. !IO_WORKSHEET type ref to ZCL_EXCEL_WORKSHEET !IV_ACTIVE type FLAG default '' returning - value(EP_CONTENT) type XSTRING . + value(EP_CONTENT) type XSTRING + raising + ZCX_EXCEL . methods CREATE_XL_SHEET_RELS importing !IO_WORKSHEET type ref to ZCL_EXCEL_WORKSHEET @@ -121,26 +124,26 @@ public 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_WRITER~WRITE_FILE. me->excel = io_excel. @@ -148,8 +151,8 @@ public section. ep_file = me->create( ). endmethod. - - + + method CREATE. * Office 2007 file format is a cab of several xml files with extension .xlsx @@ -321,8 +324,8 @@ endmethod. endmethod. - - + + method CREATE_CONTENT_TYPES. @@ -576,8 +579,8 @@ endmethod. endmethod. - - + + method CREATE_DOCPROPS_APP. @@ -799,8 +802,8 @@ endmethod. endmethod. - - + + method CREATE_DOCPROPS_CORE. @@ -924,8 +927,8 @@ endmethod. endmethod. - - + + method CREATE_RELATIONSHIPS. @@ -1023,9 +1026,9 @@ endmethod. endmethod. - - - + + + method CREATE_XL_DRAWINGS. @@ -1253,9 +1256,9 @@ endmethod. endmethod. - - - + + + method CREATE_XL_DRAWINGS_RELS. ** Constant node name @@ -1339,8 +1342,8 @@ endmethod. endmethod. - - + + method CREATE_XL_RELATIONSHIPS. @@ -1487,8 +1490,8 @@ endmethod. endmethod. - - + + method CREATE_XL_SHAREDSTRINGS. @@ -1604,11 +1607,12 @@ endmethod. endmethod. - - - - - method CREATE_XL_SHEET. + + + + + + METHOD create_xl_sheet. TYPES: BEGIN OF cfvo, value TYPE zexcel_conditional_value, @@ -2151,13 +2155,16 @@ endmethod. " outlineLevel IF <column_dimension>-column_dimension->get_outline_level( ) > 0. lv_value = <column_dimension>-column_dimension->get_outline_level( ). + SHIFT lv_value RIGHT DELETING TRAILING space. SHIFT lv_value LEFT DELETING LEADING space. lo_element_2->set_attribute_ns( name = lc_xml_attr_outlinelevel value = lv_value ). ENDIF. " Style - lv_value = <column_dimension>-column_dimension->get_xf_index( ). +* lv_value = <column_dimension>-column_dimension->get_xf_index( ). "del issue #157 - set column style + lv_style_guid = <column_dimension>-column_dimension->get_column_style_guid( ). "ins issue #157 - set column style + lv_value = me->excel->get_style_index_in_styles( lv_style_guid ). "ins issue #157 - set column style SHIFT lv_value RIGHT DELETING TRAILING space. SHIFT lv_value LEFT DELETING LEADING space. lo_element_2->set_attribute_ns( name = lc_xml_attr_style @@ -2165,15 +2172,49 @@ endmethod. lo_element->append_child( new_child = lo_element_2 ). " col node ENDLOOP. - ELSE. - IF io_worksheet->zif_excel_sheet_properties~get_style( ) IS NOT INITIAL. +* ELSE. "del issue #157 - set sheet style ( add missing columns +* IF io_worksheet->zif_excel_sheet_properties~get_style( ) IS NOT INITIAL. "del issue #157 - set sheet style ( add missing columns +* Begin of insertion issue #157 - set sheet style ( add missing columns + ENDIF. +* Always pass through this coding + IF io_worksheet->zif_excel_sheet_properties~get_style( ) IS NOT INITIAL. + DATA: lts_sorted_columns TYPE SORTED TABLE OF zexcel_cell_column WITH UNIQUE KEY table_line. + TYPES: BEGIN OF ty_missing_columns, + first_column TYPE zexcel_cell_column, + last_column TYPE zexcel_cell_column, + END OF ty_missing_columns. + DATA: t_missing_columns TYPE STANDARD TABLE OF ty_missing_columns WITH NON-UNIQUE DEFAULT KEY, + missing_column LIKE LINE OF t_missing_columns. + +* First collect columns that were already handled before. The rest has to be inserted now + LOOP AT column_dimensions ASSIGNING <column_dimension>. + lv_column = zcl_excel_common=>convert_column2int( <column_dimension>-column ). + INSERT lv_column INTO TABLE lts_sorted_columns. + ENDLOOP. + +* Now find all columns that were missing so far + missing_column-first_column = 1. + LOOP AT lts_sorted_columns INTO lv_column. + IF lv_column > missing_column-first_column. + missing_column-last_column = lv_column - 1. + APPEND missing_column TO t_missing_columns. + ENDIF. + missing_column-first_column = lv_column + 1. + ENDLOOP. + missing_column-last_column = zcl_excel_common=>c_excel_sheet_max_col. + APPEND missing_column TO t_missing_columns. +* Now apply stylesetting ( and other defaults - I copy it from above. Whoever programmed that seems to know what to do :o) + LOOP AT t_missing_columns INTO missing_column. +* End of insertion issue #157 - set column style lo_element_2 = lo_document->create_simple_element( name = lc_xml_node_col parent = lo_document ). - lv_value = zcl_excel_common=>c_excel_sheet_min_col. +* lv_value = zcl_excel_common=>c_excel_sheet_min_col."del issue #157 - set sheet style ( add missing columns + lv_value = missing_column-first_column. "ins issue #157 - set sheet style ( add missing columns CONDENSE lv_value. lo_element_2->set_attribute_ns( name = lc_xml_attr_min value = lv_value ). - lv_value = zcl_excel_common=>c_excel_sheet_max_col. +* lv_value = zcl_excel_common=>c_excel_sheet_max_col."del issue #157 - set sheet style ( add missing columns + lv_value = missing_column-last_column. "ins issue #157 - set sheet style ( add missing columns CONDENSE lv_value. lo_element_2->set_attribute_ns( name = lc_xml_attr_max value = lv_value ). @@ -2186,7 +2227,8 @@ endmethod. lo_element_2->set_attribute_ns( name = lc_xml_attr_style value = lv_value ). lo_element->append_child( new_child = lo_element_2 ). " col node - ENDIF. + ENDLOOP. "ins issue #157 - set sheet style ( add missing columns + ENDIF. lo_element_root->append_child( new_child = lo_element ). " cols node ENDIF. @@ -2284,8 +2326,27 @@ endmethod. lo_element_3->set_attribute_ns( name = lc_xml_attr_r value = <ls_sheet_content>-cell_coords ). +* begin of change issue #157 - allow column cellstyle +* if no cellstyle is set, look into column, then into sheet IF <ls_sheet_content>-cell_style IS NOT INITIAL. - READ TABLE styles_mapping INTO ls_style_mapping WITH KEY guid = <ls_sheet_content>-cell_style. + lv_style_guid = <ls_sheet_content>-cell_style. + ELSE. + lv_column_p = zcl_excel_common=>convert_column2alpha( <ls_sheet_content>-cell_column ). + READ TABLE column_dimensions with key column = lv_column_p ASSIGNING <column_dimension>. + IF sy-subrc = 0. + lv_style_guid = <column_dimension>-column_dimension->get_column_style_guid( ). + IF lv_style_guid IS INITIAL. + lv_style_guid = io_worksheet->zif_excel_sheet_properties~get_style( ). + ENDIF. + ELSE. + lv_style_guid = io_worksheet->zif_excel_sheet_properties~get_style( ). + ENDIF. + ENDIF. +* IF <ls_sheet_content>-cell_style IS NOT INITIAL. +* READ TABLE styles_mapping INTO ls_style_mapping WITH KEY guid = <ls_sheet_content>-cell_style. + IF lv_style_guid IS NOT INITIAL. + READ TABLE styles_mapping INTO ls_style_mapping WITH KEY guid = lv_style_guid. +* end of change issue #157 - allow column cellstyles lv_value = ls_style_mapping-style. SHIFT lv_value RIGHT DELETING TRAILING space. SHIFT lv_value LEFT DELETING LEADING space. @@ -3074,12 +3135,12 @@ endmethod. lo_renderer = lo_ixml->create_renderer( ostream = lo_ostream document = lo_document ). lo_renderer->render( ). -endmethod. +ENDMETHOD. - - - - + + + + method CREATE_XL_SHEET_RELS. @@ -3221,8 +3282,8 @@ endmethod. endmethod. - - + + method CREATE_XL_STYLES. @@ -4126,11 +4187,11 @@ endmethod. endmethod. - - - - - + + + + + method CREATE_XL_STYLES_COLOR_NODE. DATA: lo_sub_element TYPE REF TO if_ixml_element, lv_value TYPE string. @@ -4177,9 +4238,9 @@ endmethod. io_parent->append_child( new_child = lo_sub_element ). endmethod. - - - + + + method CREATE_XL_TABLE. DATA: lc_xml_node_table TYPE string VALUE 'table', @@ -4348,8 +4409,8 @@ endmethod. endmethod. - - + + method CREATE_XL_THEME. @@ -4437,8 +4498,8 @@ endmethod. endmethod. - - + + method CREATE_XL_WORKBOOK. ** Constant node name @@ -4696,9 +4757,9 @@ endmethod. endmethod. - - - + + + method FLAG2BOOL. @@ -4709,9 +4770,9 @@ endmethod. ENDIF. endmethod. - - - + + + method GET_SHARED_STRING_INDEX. diff --git a/ZA2X/PROG/ZDEMO_EXCEL36.slnk b/ZA2X/PROG/ZDEMO_EXCEL36.slnk new file mode 100644 index 0000000..a7435e9 --- /dev/null +++ b/ZA2X/PROG/ZDEMO_EXCEL36.slnk @@ -0,0 +1,106 @@ + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL36 +REPORT zdemo_excel36. + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + column_dimension TYPE REF TO zcl_excel_worksheet_columndime, + col type i. + +DATA: guid_arial20 TYPE zexcel_cell_style, + gui_times11 TYPE zexcel_cell_style, + gui_cambria8red TYPE zexcel_cell_style. + + +CONSTANTS: gc_save_file_name TYPE string VALUE '36_DefaultStyles.xlsx'. +INCLUDE zdemo_excel_outputopt_incl. + +START-OF-SELECTION. + + " Creates active sheet + CREATE OBJECT lo_excel. + + guid_arial20 = lo_excel->build_style( ip_font_name = zcl_excel_style_font=>c_name_arial + ip_font_scheme = zcl_excel_style_font=>c_scheme_none + ip_font_size = 20 ). + gui_times11 = lo_excel->build_style( ip_font_name = zcl_excel_style_font=>c_name_roman + ip_font_scheme = zcl_excel_style_font=>c_scheme_none + ip_font_size = 11 ). + gui_cambria8red = lo_excel->build_style( ip_font_name = zcl_excel_style_font=>C_NAME_CAMBRIA + ip_font_scheme = zcl_excel_style_font=>c_scheme_none + ip_font_size = 8 + ip_font_color_rgb = zcl_excel_style_color=>c_red ). + + lo_excel->set_default_style( guid_arial20 ). " Default for all new worksheets + +* 1st sheet - do not change anything --> defaultstyle from lo_excel should apply + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( 'Style for complete document' ). + lo_worksheet->set_cell( ip_column = 2 ip_row = 4 ip_value = 'All cells in this sheet are set to font Arial, fontsize 20' ). + lo_worksheet->set_cell( ip_column = 2 ip_row = 5 ip_value = 'because no separate style was passed for this sheet' ). + lo_worksheet->set_cell( ip_column = 2 ip_row = 6 ip_value = 'but a default style was set for the complete instance of zcl_excel' ). + lo_worksheet->set_cell( ip_column = 2 ip_row = 1 ip_value = space ). " Missing feature "set active cell - use this to simulate that + + +* 2nd sheet - defaultstyle for this sheet set explicitly ( set to Times New Roman 11 ) + lo_worksheet = lo_excel->add_new_worksheet( ). + lo_worksheet->set_title( 'Style for this sheet' ). + lo_worksheet->zif_excel_sheet_properties~set_style( gui_times11 ). + + lo_worksheet->set_cell( ip_column = 2 ip_row = 4 ip_value = 'All cells in this sheet are set to font Times New Roman, fontsize 11' ). + lo_worksheet->set_cell( ip_column = 2 ip_row = 5 ip_value = 'because this style was passed for this sheet' ). + lo_worksheet->set_cell( ip_column = 2 ip_row = 6 ip_value = 'thus the default style from zcl_excel does not apply to this sheet' ). + lo_worksheet->set_cell( ip_column = 2 ip_row = 1 ip_value = space ). " Missing feature "set active cell - use this to simulate that + + +* 3rd sheet - defaultstyle for columns ( set to Times New Roman 11 ) + lo_worksheet = lo_excel->add_new_worksheet( ). + lo_worksheet->set_title( 'Style for 3 columns' ). + column_dimension = lo_worksheet->get_column_dimension( 'B' ). + column_dimension->set_column_style_by_guid( ip_style_guid = gui_times11 ). + column_dimension = lo_worksheet->get_column_dimension( 'C' ). + column_dimension->set_column_style_by_guid( ip_style_guid = gui_times11 ). + column_dimension = lo_worksheet->get_column_dimension( 'F' ). + column_dimension->set_column_style_by_guid( ip_style_guid = gui_times11 ). + + lo_worksheet->set_cell( ip_column = 2 ip_row = 4 ip_value = 'The columns B,C and F are set to Times New Roman' ). + lo_worksheet->set_cell( ip_column = 2 ip_row = 10 ip_value = 'All other cells in this sheet are set to font Arial, fontsize 20' ). + lo_worksheet->set_cell( ip_column = 2 ip_row = 11 ip_value = 'because no separate style was passed for this sheet' ). + lo_worksheet->set_cell( ip_column = 2 ip_row = 12 ip_value = 'but a default style was set for the complete instance of zcl_excel' ). + + lo_worksheet->set_cell( ip_column = 8 ip_row = 1 ip_value = 'Of course' ip_style = gui_cambria8red ). + lo_worksheet->set_cell( ip_column = 8 ip_row = 2 ip_value = 'setting a specific style to a cell' ip_style = gui_cambria8red ). + lo_worksheet->set_cell( ip_column = 8 ip_row = 3 ip_value = 'takes precedence over all defaults' ip_style = gui_cambria8red ). + lo_worksheet->set_cell( ip_column = 8 ip_row = 4 ip_value = 'Here: Cambria 8 in red' ip_style = gui_cambria8red ). + + +* Set entry into each of the first 10 columns + DO 20 TIMES. + col = sy-index. + CASE col. + WHEN 2 " B + OR 3 " C + OR 6." F + lo_worksheet->set_cell( ip_column = col ip_row = 6 ip_value = 'Times 11' ). + WHEN OTHERS. + lo_worksheet->set_cell( ip_column = col ip_row = 6 ip_value = 'Arial 20' ). + ENDCASE. + ENDDO. + + lo_worksheet->set_cell( ip_column = 2 ip_row = 1 ip_value = space ). " Missing feature "set active cell - use this to simulate that + + + + lo_excel->set_active_sheet_index( 1 ). + + +*** Create output + lcl_output=>output( lo_excel ). +