diff --git a/build/ABAP2XLSX_V_7_0.nugg b/build/ABAP2XLSX_V_7_0.nugg index 7ec9fb7..ac5677b 100644 --- a/build/ABAP2XLSX_V_7_0.nugg +++ b/build/ABAP2XLSX_V_7_0.nugg @@ -1,7 +1,12582 @@ + + *"* 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 + + ABAP + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + method CONSTRUCTOR. + " Initialise instance variables + formula1 = ''. + formula2 = ''. + type = me->c_type_none. + errorstyle = me->c_style_stop. + operator = ''. + allowblank = abap_false. + showdropdown = abap_false. + showinputmessage = abap_true. + showerrormessage = abap_true. + errortitle = ''. + error = ''. + prompttitle = ''. + prompt = ''. +* inizialize dimension range + cell_row = 1. + cell_column = 'A'. + endmethod. + + + + *"* 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 + + ABAP + + + + method ADD. + data_validations->add( ip_data_validation ). + endmethod. + + + method CLEAR. + data_validations->clear( ). + endmethod. + + + method CONSTRUCTOR. + + CREATE OBJECT data_validations. + + endmethod. + + + + method GET_ITERATOR. + eo_iterator ?= data_validations->if_object_collection~get_iterator( ). + endmethod. + + + + method IS_EMPTY. + is_empty = data_validations->if_object_collection~is_empty( ). + endmethod. + + + + method REMOVE. + data_validations->remove( ip_data_validation ). + endmethod. + + + + method SIZE. + ep_size = data_validations->if_object_collection~size( ). + endmethod. + + + + *"* 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 + + ABAP + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + method CONSTRUCTOR. + + CALL FUNCTION 'GUID_CREATE' + IMPORTING + ev_guid_16 = me->guid. + + IF ip_title IS NOT INITIAL. + title = ip_title. + ELSE. + title = me->guid. + ENDIF. + + me->type = ip_type. + +* inizialize dimension range + anchor = anchor_one_cell. + from_loc-col = 1. + from_loc-row = 1. + endmethod. + + + + method CREATE_MEDIA_NAME. + +* if media name is initial, create unique name + CHECK media_name IS INITIAL. + + index = ip_index. + CONCATENATE me->type index INTO media_name. + CONDENSE media_name NO-GAPS. + endmethod. + + + + method GET_FROM_COL. + r_from_col = me->from_loc-col. + endmethod. + + + + method GET_FROM_ROW. + r_from_row = me->from_loc-row. + endmethod. + + + + method GET_GUID. + + ep_guid = me->guid. + + endmethod. + + + + method GET_HEIGHT_EMU_STR. + r_height = pixel2emu( size-height ). + CONDENSE r_height NO-GAPS. + endmethod. + + + + method GET_INDEX. + rp_index = me->index. + endmethod. + + + + method GET_MEDIA. + CASE media_source. + WHEN c_media_source_xstring. + r_media = media. + WHEN c_media_source_www. + DATA: lt_mime TYPE tsfmime, + lv_filesize TYPE i, + lv_filesizec(10). + + CALL FUNCTION 'WWWDATA_IMPORT' + EXPORTING + key = media_key_www + TABLES + mime = lt_mime + EXCEPTIONS + OTHERS = 1. + + CALL FUNCTION 'WWWPARAMS_READ' + EXPORTING + relid = media_key_www-relid + objid = media_key_www-objid + name = 'filesize' + IMPORTING + value = lv_filesizec. + + lv_filesize = lv_filesizec. + CALL FUNCTION 'SCMS_BINARY_TO_XSTRING' + EXPORTING + input_length = lv_filesize + IMPORTING + buffer = r_media + TABLES + binary_tab = lt_mime + EXCEPTIONS + failed = 1 + OTHERS = 2. + WHEN c_media_source_mime. + DATA: lt_bin_mime TYPE sdokcntbins. + cl_wb_mime_repository=>load_mime( EXPORTING + io = me->io + IMPORTING + filesize = lv_filesize + bin_data = lt_bin_mime + CHANGING + language = sy-langu ). + + CALL FUNCTION 'SCMS_BINARY_TO_XSTRING' + EXPORTING + input_length = lv_filesize + IMPORTING + buffer = r_media + TABLES + binary_tab = lt_bin_mime + EXCEPTIONS + failed = 1 + OTHERS = 2. + ENDCASE. + endmethod. + + + + method GET_MEDIA_NAME. + CONCATENATE media_name `.` media_type INTO r_name. + endmethod. + + + + method GET_MEDIA_TYPE. + r_type = media_type. + endmethod. + + + + method GET_NAME. + r_name = title. + endmethod. + + + + method GET_POSITION. + rp_position-anchor = anchor. + rp_position-from = from_loc. + rp_position-to = to_loc. + rp_position-size = size. + endmethod. + + + + method GET_TO_COL. + r_to_col = me->to_loc-col. + endmethod. + + + + method GET_TO_ROW. + r_to_row = me->to_loc-row. + endmethod. + + + + method GET_TYPE. + rp_type = me->type. + endmethod. + + + + method GET_WIDTH_EMU_STR. + r_width = pixel2emu( size-width ). + CONDENSE r_width NO-GAPS. + endmethod. + + + + method LOAD_CHART_ATTRIBUTES. + DATA: node TYPE REF TO if_ixml_element. + DATA: node2 TYPE REF TO if_ixml_element. + DATA: node3 TYPE REF TO if_ixml_element. + DATA: node4 TYPE REF TO if_ixml_element. + DATA: iterator TYPE REF TO if_ixml_node_iterator. + + DATA: chartspace TYPE REF TO if_ixml_node_collection. + DATA: coll_length TYPE i. + DATA: chartelem TYPE REF TO if_ixml_element. + + DATA lo_barchart TYPE REF TO zcl_excel_graph_bars. + DATA lo_piechart TYPE REF TO zcl_excel_graph_pie. + DATA lo_linechart TYPE REF TO zcl_excel_graph_line. + + TYPES: BEGIN OF t_prop, + val TYPE string, + rtl TYPE string, + lang TYPE string, + formatcode TYPE string, + sourcelinked TYPE string, + END OF t_prop. + + TYPES: BEGIN OF t_pagemargins, + b TYPE string, + l TYPE string, + r TYPE string, + t TYPE string, + header TYPE string, + footer TYPE string, + END OF t_pagemargins. + + DATA ls_prop TYPE t_prop. + DATA ls_pagemargins TYPE t_pagemargins. + + DATA lo_collection TYPE REF TO if_ixml_node_collection. + DATA lo_node TYPE REF TO if_ixml_node. + DATA lo_iterator TYPE REF TO if_ixml_node_iterator. + DATA lv_idx TYPE i. + DATA lv_order TYPE i. + DATA lv_invertifnegative TYPE string. + DATA lv_symbol TYPE string. + DATA lv_smooth TYPE c. + DATA lv_sername TYPE string. + DATA lv_label TYPE string. + DATA lv_value TYPE string. + DATA lv_axid TYPE string. + DATA lv_orientation TYPE string. + DATA lv_delete TYPE string. + DATA lv_axpos TYPE string. + DATA lv_formatcode TYPE string. + DATA lv_sourcelinked TYPE string. + DATA lv_majortickmark TYPE string. + DATA lv_minortickmark TYPE string. + DATA lv_ticklblpos TYPE string. + DATA lv_crossax TYPE string. + DATA lv_crosses TYPE string. + DATA lv_auto TYPE string. + DATA lv_lblalgn TYPE string. + DATA lv_lbloffset TYPE string. + DATA lv_nomultilvllbl TYPE string. + DATA lv_crossbetween TYPE string. + + node ?= ip_chart->if_ixml_node~get_first_child( ). + CHECK node IS NOT INITIAL. + + CASE me->graph_type. + WHEN c_graph_bars. + CREATE OBJECT lo_barchart. + me->graph = lo_barchart. + WHEN c_graph_pie. + CREATE OBJECT lo_piechart. + me->graph = lo_piechart. + WHEN c_graph_line. + CREATE OBJECT lo_linechart. + me->graph = lo_linechart. + WHEN OTHERS. + ENDCASE. + + "Fill properties + node2 ?= node->find_from_name( name = 'date1904' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + me->graph->ns_1904val = ls_prop-val. + node2 ?= node->find_from_name( name = 'lang' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + me->graph->ns_langval = ls_prop-val. + node2 ?= node->find_from_name( name = 'roundedCorners' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + me->graph->ns_roundedcornersval = ls_prop-val. + + "style + node2 ?= node->find_from_name( name = 'style' namespace = 'c14' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + me->graph->ns_c14styleval = ls_prop-val. + node2 ?= node->find_from_name( name = 'style' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + me->graph->ns_styleval = ls_prop-val. + "---------------------------Read graph properties + node2 ?= node->find_from_name( name = 'autoTitleDeleted' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + me->graph->ns_autotitledeletedval = ls_prop-val. + + "plotArea + CASE me->graph_type. + WHEN c_graph_bars. + node2 ?= node->find_from_name( name = 'barDir' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lo_barchart->ns_bardirval = ls_prop-val. + node2 ?= node->find_from_name( name = 'grouping' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lo_barchart->ns_groupingval = ls_prop-val. + node2 ?= node->find_from_name( name = 'varyColors' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lo_barchart->ns_varycolorsval = ls_prop-val. + + "Load series + CALL METHOD node->get_elements_by_tag_name + EXPORTING +* depth = 0 + name = 'ser' +* namespace = '' + RECEIVING + rval = lo_collection. + CALL METHOD lo_collection->create_iterator + RECEIVING + rval = lo_iterator. + lo_node = lo_iterator->get_next( ). + IF lo_node IS BOUND. + node2 ?= lo_node->query_interface( ixml_iid_element ). + ENDIF. + WHILE lo_node IS BOUND. + node3 ?= node2->find_from_name( name = 'idx' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_idx = ls_prop-val. + node3 ?= node2->find_from_name( name = 'order' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_order = ls_prop-val. + node3 ?= node2->find_from_name( name = 'invertIfNegative' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_invertifnegative = ls_prop-val. + node3 ?= node2->find_from_name( name = 'v' namespace = 'c' ). + IF node3 IS BOUND. + lv_sername = node3->get_value( ). + ENDIF. + node3 ?= node2->find_from_name( name = 'strRef' namespace = 'c' ). + IF node3 IS BOUND. + node4 ?= node3->find_from_name( name = 'f' namespace = 'c' ). + lv_label = node4->get_value( ). + ENDIF. + node3 ?= node2->find_from_name( name = 'numRef' namespace = 'c' ). + IF node3 IS BOUND. + node4 ?= node3->find_from_name( name = 'f' namespace = 'c' ). + lv_value = node4->get_value( ). + ENDIF. + CALL METHOD lo_barchart->create_serie + EXPORTING + ip_idx = lv_idx + ip_order = lv_order + ip_invertifnegative = lv_invertifnegative + ip_lbl = lv_label + ip_ref = lv_value + ip_sername = lv_sername. + lo_node = lo_iterator->get_next( ). + IF lo_node IS BOUND. + node2 ?= lo_node->query_interface( ixml_iid_element ). + ENDIF. + ENDWHILE. + "note: numCache avoided + node2 ?= node->find_from_name( name = 'showLegendKey' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lo_barchart->ns_showlegendkeyval = ls_prop-val. + node2 ?= node->find_from_name( name = 'showVal' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lo_barchart->ns_showvalval = ls_prop-val. + node2 ?= node->find_from_name( name = 'showCatName' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lo_barchart->ns_showcatnameval = ls_prop-val. + node2 ?= node->find_from_name( name = 'showSerName' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lo_barchart->ns_showsernameval = ls_prop-val. + node2 ?= node->find_from_name( name = 'showPercent' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lo_barchart->ns_showpercentval = ls_prop-val. + node2 ?= node->find_from_name( name = 'showBubbleSize' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lo_barchart->ns_showbubblesizeval = ls_prop-val. + node2 ?= node->find_from_name( name = 'gapWidth' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lo_barchart->ns_gapwidthval = ls_prop-val. + + "Load axes + node2 ?= node->find_from_name( name = 'barChart' namespace = 'c' ). + CALL METHOD node2->get_elements_by_tag_name + EXPORTING +* depth = 0 + name = 'axId' +* namespace = '' + RECEIVING + rval = lo_collection. + CALL METHOD lo_collection->create_iterator + RECEIVING + rval = lo_iterator. + lo_node = lo_iterator->get_next( ). + IF lo_node IS BOUND. + node2 ?= lo_node->query_interface( ixml_iid_element ). + ENDIF. + WHILE lo_node IS BOUND. + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lv_axid = ls_prop-val. + IF sy-index EQ 1. "catAx + node2 ?= node->find_from_name( name = 'catAx' namespace = 'c' ). + node3 ?= node2->find_from_name( name = 'orientation' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_orientation = ls_prop-val. + node3 ?= node2->find_from_name( name = 'delete' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_delete = ls_prop-val. + node3 ?= node2->find_from_name( name = 'axPos' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_axpos = ls_prop-val. + node3 ?= node2->find_from_name( name = 'numFmt' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_formatcode = ls_prop-formatcode. + lv_sourcelinked = ls_prop-sourcelinked. + node3 ?= node2->find_from_name( name = 'majorTickMark' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_majortickmark = ls_prop-val. + node3 ?= node2->find_from_name( name = 'majorTickMark' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_minortickmark = ls_prop-val. + node3 ?= node2->find_from_name( name = 'tickLblPos' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_ticklblpos = ls_prop-val. + node3 ?= node2->find_from_name( name = 'crossAx' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_crossax = ls_prop-val. + node3 ?= node2->find_from_name( name = 'crosses' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_crosses = ls_prop-val. + node3 ?= node2->find_from_name( name = 'auto' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_auto = ls_prop-val. + node3 ?= node2->find_from_name( name = 'lblAlgn' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_lblalgn = ls_prop-val. + node3 ?= node2->find_from_name( name = 'lblOffset' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_lbloffset = ls_prop-val. + node3 ?= node2->find_from_name( name = 'noMultiLvlLbl' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_nomultilvllbl = ls_prop-val. + CALL METHOD lo_barchart->create_ax + EXPORTING + ip_axid = lv_axid + ip_type = zcl_excel_graph_bars=>c_catax + ip_orientation = lv_orientation + ip_delete = lv_delete + ip_axpos = lv_axpos + ip_formatcode = lv_formatcode + ip_sourcelinked = lv_sourcelinked + ip_majortickmark = lv_majortickmark + ip_minortickmark = lv_minortickmark + ip_ticklblpos = lv_ticklblpos + ip_crossax = lv_crossax + ip_crosses = lv_crosses + ip_auto = lv_auto + ip_lblalgn = lv_lblalgn + ip_lbloffset = lv_lbloffset + ip_nomultilvllbl = lv_nomultilvllbl. + ELSEIF sy-index EQ 2. "valAx + node2 ?= node->find_from_name( name = 'valAx' namespace = 'c' ). + node3 ?= node2->find_from_name( name = 'orientation' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_orientation = ls_prop-val. + node3 ?= node2->find_from_name( name = 'delete' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_delete = ls_prop-val. + node3 ?= node2->find_from_name( name = 'axPos' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_axpos = ls_prop-val. + node3 ?= node2->find_from_name( name = 'numFmt' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_formatcode = ls_prop-formatcode. + lv_sourcelinked = ls_prop-sourcelinked. + node3 ?= node2->find_from_name( name = 'majorTickMark' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_majortickmark = ls_prop-val. + node3 ?= node2->find_from_name( name = 'majorTickMark' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_minortickmark = ls_prop-val. + node3 ?= node2->find_from_name( name = 'tickLblPos' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_ticklblpos = ls_prop-val. + node3 ?= node2->find_from_name( name = 'crossAx' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_crossax = ls_prop-val. + node3 ?= node2->find_from_name( name = 'crosses' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_crosses = ls_prop-val. + node3 ?= node2->find_from_name( name = 'crossBetween' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_crossbetween = ls_prop-val. + CALL METHOD lo_barchart->create_ax + EXPORTING + ip_axid = lv_axid + ip_type = zcl_excel_graph_bars=>c_valax + ip_orientation = lv_orientation + ip_delete = lv_delete + ip_axpos = lv_axpos + ip_formatcode = lv_formatcode + ip_sourcelinked = lv_sourcelinked + ip_majortickmark = lv_majortickmark + ip_minortickmark = lv_minortickmark + ip_ticklblpos = lv_ticklblpos + ip_crossax = lv_crossax + ip_crosses = lv_crosses + ip_crossbetween = lv_crossbetween. + ENDIF. + lo_node = lo_iterator->get_next( ). + IF lo_node IS BOUND. + node2 ?= lo_node->query_interface( ixml_iid_element ). + ENDIF. + ENDWHILE. + + WHEN c_graph_pie. + node2 ?= node->find_from_name( name = 'varyColors' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lo_piechart->ns_varycolorsval = ls_prop-val. + + "Load series + CALL METHOD node->get_elements_by_tag_name + EXPORTING +* depth = 0 + name = 'ser' +* namespace = '' + RECEIVING + rval = lo_collection. + CALL METHOD lo_collection->create_iterator + RECEIVING + rval = lo_iterator. + lo_node = lo_iterator->get_next( ). + IF lo_node IS BOUND. + node2 ?= lo_node->query_interface( ixml_iid_element ). + ENDIF. + WHILE lo_node IS BOUND. + node3 ?= node2->find_from_name( name = 'idx' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_idx = ls_prop-val. + node3 ?= node2->find_from_name( name = 'order' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_order = ls_prop-val. + node3 ?= node2->find_from_name( name = 'v' namespace = 'c' ). + IF node3 IS BOUND. + lv_sername = node3->get_value( ). + ENDIF. + node3 ?= node2->find_from_name( name = 'strRef' namespace = 'c' ). + IF node3 IS BOUND. + node4 ?= node3->find_from_name( name = 'f' namespace = 'c' ). + lv_label = node4->get_value( ). + ENDIF. + node3 ?= node2->find_from_name( name = 'numRef' namespace = 'c' ). + IF node3 IS BOUND. + node4 ?= node3->find_from_name( name = 'f' namespace = 'c' ). + lv_value = node4->get_value( ). + ENDIF. + CALL METHOD lo_piechart->create_serie + EXPORTING + ip_idx = lv_idx + ip_order = lv_order + ip_lbl = lv_label + ip_ref = lv_value + ip_sername = lv_sername. + lo_node = lo_iterator->get_next( ). + IF lo_node IS BOUND. + node2 ?= lo_node->query_interface( ixml_iid_element ). + ENDIF. + ENDWHILE. + + "note: numCache avoided + node2 ?= node->find_from_name( name = 'showLegendKey' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lo_piechart->ns_showlegendkeyval = ls_prop-val. + node2 ?= node->find_from_name( name = 'showVal' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lo_piechart->ns_showvalval = ls_prop-val. + node2 ?= node->find_from_name( name = 'showCatName' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lo_piechart->ns_showcatnameval = ls_prop-val. + node2 ?= node->find_from_name( name = 'showSerName' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lo_piechart->ns_showsernameval = ls_prop-val. + node2 ?= node->find_from_name( name = 'showPercent' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lo_piechart->ns_showpercentval = ls_prop-val. + node2 ?= node->find_from_name( name = 'showBubbleSize' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lo_piechart->ns_showbubblesizeval = ls_prop-val. + node2 ?= node->find_from_name( name = 'showLeaderLines' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lo_piechart->ns_showleaderlinesval = ls_prop-val. + node2 ?= node->find_from_name( name = 'firstSliceAng' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lo_piechart->ns_firstsliceangval = ls_prop-val. + WHEN c_graph_line. + node2 ?= node->find_from_name( name = 'grouping' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lo_linechart->ns_groupingval = ls_prop-val. + node2 ?= node->find_from_name( name = 'varyColors' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lo_linechart->ns_varycolorsval = ls_prop-val. + + "Load series + CALL METHOD node->get_elements_by_tag_name + EXPORTING +* depth = 0 + name = 'ser' +* namespace = '' + RECEIVING + rval = lo_collection. + CALL METHOD lo_collection->create_iterator + RECEIVING + rval = lo_iterator. + lo_node = lo_iterator->get_next( ). + IF lo_node IS BOUND. + node2 ?= lo_node->query_interface( ixml_iid_element ). + ENDIF. + WHILE lo_node IS BOUND. + node3 ?= node2->find_from_name( name = 'idx' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_idx = ls_prop-val. + node3 ?= node2->find_from_name( name = 'order' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_order = ls_prop-val. + node3 ?= node2->find_from_name( name = 'symbol' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_symbol = ls_prop-val. + node3 ?= node2->find_from_name( name = 'smooth' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_smooth = ls_prop-val. + node3 ?= node2->find_from_name( name = 'v' namespace = 'c' ). + IF node3 IS BOUND. + lv_sername = node3->get_value( ). + ENDIF. + node3 ?= node2->find_from_name( name = 'strRef' namespace = 'c' ). + IF node3 IS BOUND. + node4 ?= node3->find_from_name( name = 'f' namespace = 'c' ). + lv_label = node4->get_value( ). + ENDIF. + node3 ?= node2->find_from_name( name = 'numRef' namespace = 'c' ). + IF node3 IS BOUND. + node4 ?= node3->find_from_name( name = 'f' namespace = 'c' ). + lv_value = node4->get_value( ). + ENDIF. + CALL METHOD lo_linechart->create_serie + EXPORTING + ip_idx = lv_idx + ip_order = lv_order + ip_symbol = lv_symbol + ip_smooth = lv_smooth + ip_lbl = lv_label + ip_ref = lv_value + ip_sername = lv_sername. + lo_node = lo_iterator->get_next( ). + IF lo_node IS BOUND. + node2 ?= lo_node->query_interface( ixml_iid_element ). + ENDIF. + ENDWHILE. + "note: numCache avoided + node2 ?= node->find_from_name( name = 'showLegendKey' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lo_linechart->ns_showlegendkeyval = ls_prop-val. + node2 ?= node->find_from_name( name = 'showVal' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lo_linechart->ns_showvalval = ls_prop-val. + node2 ?= node->find_from_name( name = 'showCatName' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lo_linechart->ns_showcatnameval = ls_prop-val. + node2 ?= node->find_from_name( name = 'showSerName' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lo_linechart->ns_showsernameval = ls_prop-val. + node2 ?= node->find_from_name( name = 'showPercent' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lo_linechart->ns_showpercentval = ls_prop-val. + node2 ?= node->find_from_name( name = 'showBubbleSize' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lo_linechart->ns_showbubblesizeval = ls_prop-val. + + node ?= node->find_from_name( name = 'lineChart' namespace = 'c' ). + node2 ?= node->find_from_name( name = 'marker' namespace = 'c' DEPTH = '1' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lo_linechart->NS_MARKERVAL = ls_prop-val. + node2 ?= node->find_from_name( name = 'smooth' namespace = 'c' DEPTH = '1' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lo_linechart->NS_SMOOTHVAL = ls_prop-val. + node ?= ip_chart->if_ixml_node~get_first_child( ). + CHECK node IS NOT INITIAL. + + "Load axes + node2 ?= node->find_from_name( name = 'lineChart' namespace = 'c' ). + CALL METHOD node2->get_elements_by_tag_name + EXPORTING +* depth = 0 + name = 'axId' +* namespace = '' + RECEIVING + rval = lo_collection. + CALL METHOD lo_collection->create_iterator + RECEIVING + rval = lo_iterator. + lo_node = lo_iterator->get_next( ). + IF lo_node IS BOUND. + node2 ?= lo_node->query_interface( ixml_iid_element ). + ENDIF. + WHILE lo_node IS BOUND. + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lv_axid = ls_prop-val. + IF sy-index EQ 1. "catAx + node2 ?= node->find_from_name( name = 'catAx' namespace = 'c' ). + node3 ?= node2->find_from_name( name = 'orientation' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_orientation = ls_prop-val. + node3 ?= node2->find_from_name( name = 'delete' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_delete = ls_prop-val. + node3 ?= node2->find_from_name( name = 'axPos' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_axpos = ls_prop-val. +* node3 ?= node2->find_from_name( name = 'numFmt' namespace = 'c' ). +* zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). +* lv_formatcode = ls_prop-formatcode. +* lv_sourcelinked = ls_prop-sourcelinked. + node3 ?= node2->find_from_name( name = 'majorTickMark' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_majortickmark = ls_prop-val. + node3 ?= node2->find_from_name( name = 'majorTickMark' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_minortickmark = ls_prop-val. + node3 ?= node2->find_from_name( name = 'tickLblPos' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_ticklblpos = ls_prop-val. + node3 ?= node2->find_from_name( name = 'crossAx' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_crossax = ls_prop-val. + node3 ?= node2->find_from_name( name = 'crosses' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_crosses = ls_prop-val. + node3 ?= node2->find_from_name( name = 'auto' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_auto = ls_prop-val. + node3 ?= node2->find_from_name( name = 'lblAlgn' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_lblalgn = ls_prop-val. + node3 ?= node2->find_from_name( name = 'lblOffset' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_lbloffset = ls_prop-val. + node3 ?= node2->find_from_name( name = 'noMultiLvlLbl' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_nomultilvllbl = ls_prop-val. + CALL METHOD lo_linechart->create_ax + EXPORTING + ip_axid = lv_axid + ip_type = zcl_excel_graph_line=>c_catax + ip_orientation = lv_orientation + ip_delete = lv_delete + ip_axpos = lv_axpos + ip_formatcode = lv_formatcode + ip_sourcelinked = lv_sourcelinked + ip_majortickmark = lv_majortickmark + ip_minortickmark = lv_minortickmark + ip_ticklblpos = lv_ticklblpos + ip_crossax = lv_crossax + ip_crosses = lv_crosses + ip_auto = lv_auto + ip_lblalgn = lv_lblalgn + ip_lbloffset = lv_lbloffset + ip_nomultilvllbl = lv_nomultilvllbl. + ELSEIF sy-index EQ 2. "valAx + node2 ?= node->find_from_name( name = 'valAx' namespace = 'c' ). + node3 ?= node2->find_from_name( name = 'orientation' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_orientation = ls_prop-val. + node3 ?= node2->find_from_name( name = 'delete' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_delete = ls_prop-val. + node3 ?= node2->find_from_name( name = 'axPos' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_axpos = ls_prop-val. + node3 ?= node2->find_from_name( name = 'numFmt' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_formatcode = ls_prop-formatcode. + lv_sourcelinked = ls_prop-sourcelinked. + node3 ?= node2->find_from_name( name = 'majorTickMark' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_majortickmark = ls_prop-val. + node3 ?= node2->find_from_name( name = 'majorTickMark' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_minortickmark = ls_prop-val. + node3 ?= node2->find_from_name( name = 'tickLblPos' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_ticklblpos = ls_prop-val. + node3 ?= node2->find_from_name( name = 'crossAx' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_crossax = ls_prop-val. + node3 ?= node2->find_from_name( name = 'crosses' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_crosses = ls_prop-val. + node3 ?= node2->find_from_name( name = 'crossBetween' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). + lv_crossbetween = ls_prop-val. + CALL METHOD lo_linechart->create_ax + EXPORTING + ip_axid = lv_axid + ip_type = zcl_excel_graph_line=>c_valax + ip_orientation = lv_orientation + ip_delete = lv_delete + ip_axpos = lv_axpos + ip_formatcode = lv_formatcode + ip_sourcelinked = lv_sourcelinked + ip_majortickmark = lv_majortickmark + ip_minortickmark = lv_minortickmark + ip_ticklblpos = lv_ticklblpos + ip_crossax = lv_crossax + ip_crosses = lv_crosses + ip_crossbetween = lv_crossbetween. + ENDIF. + lo_node = lo_iterator->get_next( ). + IF lo_node IS BOUND. + node2 ?= lo_node->query_interface( ixml_iid_element ). + ENDIF. + ENDWHILE. + WHEN OTHERS. + ENDCASE. + + "legend + CASE me->graph_type. + WHEN c_graph_bars. + node2 ?= node->find_from_name( name = 'legendPos' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lo_barchart->ns_legendposval = ls_prop-val. + node2 ?= node->find_from_name( name = 'overlay' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lo_barchart->ns_overlayval = ls_prop-val. + WHEN c_graph_line. + node2 ?= node->find_from_name( name = 'legendPos' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lo_linechart->ns_legendposval = ls_prop-val. + node2 ?= node->find_from_name( name = 'overlay' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lo_linechart->ns_overlayval = ls_prop-val. + WHEN c_graph_pie. + node2 ?= node->find_from_name( name = 'legendPos' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lo_piechart->ns_legendposval = ls_prop-val. + node2 ?= node->find_from_name( name = 'overlay' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lo_piechart->ns_overlayval = ls_prop-val. + node2 ?= node->find_from_name( name = 'pPr' namespace = 'a' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lo_piechart->ns_pprrtl = ls_prop-rtl. + node2 ?= node->find_from_name( name = 'endParaRPr' namespace = 'a' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + lo_piechart->ns_endpararprlang = ls_prop-lang. + + WHEN OTHERS. + ENDCASE. + + node2 ?= node->find_from_name( name = 'plotVisOnly' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + me->graph->ns_plotvisonlyval = ls_prop-val. + node2 ?= node->find_from_name( name = 'dispBlanksAs' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + me->graph->ns_dispblanksasval = ls_prop-val. + node2 ?= node->find_from_name( name = 'showDLblsOverMax' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). + me->graph->ns_showdlblsovermaxval = ls_prop-val. + "--------------------- + + node2 ?= node->find_from_name( name = 'pageMargins' namespace = 'c' ). + zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_pagemargins ). + me->graph->pagemargins = ls_pagemargins. + + + endmethod. + + + + + + method PIXEL2EMU. +* suppose 96 DPI + IF ip_dpi IS SUPPLIED. + r_emu = ip_pixel * 914400 / ip_dpi. + ELSE. +* suppose 96 DPI + r_emu = ip_pixel * 914400 / 96. + ENDIF. + endmethod. + + + + + + + method SET_MEDIA. + IF ip_media IS SUPPLIED. + media = ip_media. + ENDIF. + media_type = ip_media_type. + media_source = c_media_source_xstring. + IF ip_width IS SUPPLIED. + size-width = ip_width. + ENDIF. + IF ip_height IS SUPPLIED. + size-height = ip_height. + ENDIF. + endmethod. + + + + + + method SET_MEDIA_MIME. + + io = ip_io. + media_source = c_media_source_mime. + size-width = ip_width. + size-height = ip_height. + + cl_wb_mime_repository=>load_mime( EXPORTING + io = ip_io + IMPORTING + filename = media_name + "mimetype = media_type + CHANGING + language = sy-langu ). + + SPLIT media_name AT '.' INTO media_name media_type. + + + + endmethod. + + + + + + method SET_MEDIA_WWW. + DATA: lv_value(20). + + media_key_www = ip_key. + media_source = c_media_source_www. + + CALL FUNCTION 'WWWPARAMS_READ' + EXPORTING + relid = media_key_www-relid + objid = media_key_www-objid + name = 'fileextension' + IMPORTING + value = lv_value. + media_type = lv_value. + SHIFT media_type LEFT DELETING LEADING '.'. + + size-width = ip_width. + size-height = ip_height. + endmethod. + + + + + + + method SET_POSITION. + from_loc-col = zcl_excel_common=>convert_column2int( ip_from_col ) - 1. + IF ip_coloff IS SUPPLIED. + from_loc-col_offset = ip_coloff. + ENDIF. + from_loc-row = ip_from_row - 1. + IF ip_rowoff IS SUPPLIED. + from_loc-row_offset = ip_rowoff. + ENDIF. + anchor = anchor_one_cell. + endmethod. + + + + + + method SET_POSITION2. + + data: lv_anchor type zexcel_drawing_anchor. + lv_anchor = ip_anchor. + + IF lv_anchor IS INITIAL. + IF ip_to IS NOT INITIAL. + lv_anchor = anchor_two_cell. + ELSE. + lv_anchor = anchor_one_cell. + ENDIF. + ENDIF. + + CASE lv_anchor. + WHEN anchor_absolute OR anchor_one_cell. + CLEAR: me->to_loc. + WHEN anchor_two_cell. + CLEAR: me->size. + ENDCASE. + + me->from_loc = ip_from. + me->to_loc = ip_to. + me->anchor = lv_anchor. + + endmethod. + + + + *"* 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 ADD. + DATA: lv_index TYPE i. + + drawings->add( ip_drawing ). + lv_index = drawings->if_object_collection~size( ). + ip_drawing->create_media_name( + ip_index = lv_index ). + endmethod. + + + method CLEAR. + + drawings->clear( ). + endmethod. + + + + method CONSTRUCTOR. + + CREATE OBJECT drawings. + type = ip_type. + + endmethod. + + + + + method GET. + + DATA lv_index TYPE i. + lv_index = ip_index. + eo_drawing ?= drawings->if_object_collection~get( lv_index ). + endmethod. + + + + method GET_ITERATOR. + + eo_iterator ?= drawings->if_object_collection~get_iterator( ). + endmethod. + + + + method GET_TYPE. + rp_type = me->type. + endmethod. + + + + method INCLUDE. + drawings->add( ip_drawing ). + endmethod. + + + + method IS_EMPTY. + + is_empty = drawings->if_object_collection~is_empty( ). + endmethod. + + + + method REMOVE. + + drawings->remove( ip_drawing ). + endmethod. + + + + method SIZE. + + ep_size = drawings->if_object_collection~size( ). + endmethod. + + + + *"* 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 + + ABAP + + + + + + + + + + method CREATE. + data: lo_hyperlink type REF TO zcl_excel_hyperlink. + + create OBJECT lo_hyperlink. + + lo_hyperlink->location = iv_url. + lo_hyperlink->internal = iv_internal. + + ov_link = lo_hyperlink. + endmethod. + + + + + method CREATE_EXTERNAL_LINK. + + ov_link = zcl_excel_hyperlink=>create( iv_url = iv_url + iv_internal = abap_false ). + endmethod. + + + + + method CREATE_INTERNAL_LINK. + ov_link = zcl_excel_hyperlink=>create( iv_url = iv_location + iv_internal = abap_true ). + endmethod. + + + + method GET_REF. + ev_ref = row. + CONDENSE ev_ref. + CONCATENATE column ev_ref INTO ev_ref. + endmethod. + + + + method GET_URL. + ev_url = me->location. + endmethod. + + + + method IS_INTERNAL. + ev_ret = me->internal. + endmethod. + + + + + + method SET_CELL_REFERENCE. + me->column = zcl_excel_common=>convert_column2alpha( ip_column ). " issue #155 - less restrictive typing for ip_column + me->row = ip_row. + endmethod. + + + + *"* 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 CONSTRUCTOR. + endmethod. + + + + method GET_GUID. + + ep_guid = me->guid. + + endmethod. + + + + method GET_VALUE. + + ep_value = me->value. + + endmethod. + + + + method SET_RANGE_VALUE. + me->value = ip_value. + endmethod. + + + + + + + + method SET_VALUE. + DATA: lv_start_row_c TYPE char7, + lv_stop_row_c TYPE char7, + lv_value TYPE string. + lv_stop_row_c = ip_stop_row. + SHIFT lv_stop_row_c RIGHT DELETING TRAILING space. + SHIFT lv_stop_row_c LEFT DELETING LEADING space. + lv_start_row_c = ip_start_row. + SHIFT lv_start_row_c RIGHT DELETING TRAILING space. + SHIFT lv_start_row_c LEFT DELETING LEADING space. + lv_value = ip_sheet_name. + me->value = zcl_excel_common=>escape_string( ip_value = lv_value ). + + CONCATENATE me->value '!$' ip_start_column '$' lv_start_row_c ':$' ip_stop_column '$' lv_stop_row_c INTO me->value. + endmethod. + + + + *"* 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 ADD. + ranges->add( ip_range ). + endmethod. + + + method CLEAR. + ranges->clear( ). + endmethod. + + + method CONSTRUCTOR. + + + CREATE OBJECT ranges. + + endmethod. + + + + + method GET. + eo_range ?= ranges->if_object_collection~get( ip_index ). + endmethod. + + + + method GET_ITERATOR. + eo_iterator ?= ranges->if_object_collection~get_iterator( ). + endmethod. + + + + method IS_EMPTY. + is_empty = ranges->if_object_collection~is_empty( ). + endmethod. + + + + method REMOVE. + ranges->remove( ip_range ). + endmethod. + + + + method SIZE. + ep_size = ranges->if_object_collection~size( ). + endmethod. + + + + *"* 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 + + ABAP + + + + + + + method CONSTRUCTOR. + endmethod. + + + + method IS_SECURITY_ENABLED. + IF lockrevision EQ abap_true OR lockstructure EQ abap_true OR lockwindows EQ abap_true. + ep_security_enabled = abap_true. + ENDIF. + endmethod. + + + + *"* 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 + + ABAP + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + method CONSTRUCTOR. + orientation = me->c_orientation_default. + +* default margins + margin_bottom = '0.75'. + margin_footer = '0.3'. + margin_header = '0.3'. + margin_left = '0.7'. + margin_right = '0.7'. + margin_top = '0.75'. + +* clear page settings + CLEAR: black_and_white, + cell_comments, + copies, + draft, + errors, + first_page_number, + fit_to_page, + fit_to_height, + fit_to_width, + horizontal_dpi, + orientation, + page_order, + paper_height, + paper_size, + paper_width, + scale, + use_first_page_num, + use_printer_defaults, + vertical_dpi. + endmethod. + + + + + + + method GET_HEADER_FOOTER_STRING. +* ---------------------------------------------------------------------- + DATA: lc_marker_left(2) TYPE c VALUE '&L' + , lc_marker_right(2) TYPE c VALUE '&R' + , lc_marker_center(2) TYPE c VALUE '&C' + , lv_value TYPE string + . +* ---------------------------------------------------------------------- + IF ep_odd_header IS SUPPLIED. + + IF me->odd_header-left_value IS NOT INITIAL. + lv_value = me->process_header_footer( ip_header = me->odd_header ip_side = 'LEFT' ). + CONCATENATE lc_marker_left lv_value INTO ep_odd_header. + ENDIF. + + IF me->odd_header-center_value IS NOT INITIAL. + lv_value = me->process_header_footer( ip_header = me->odd_header ip_side = 'CENTER' ). + CONCATENATE ep_odd_header lc_marker_center lv_value INTO ep_odd_header. + ENDIF. + + IF me->odd_header-right_value IS NOT INITIAL. + lv_value = me->process_header_footer( ip_header = me->odd_header ip_side = 'RIGHT' ). + CONCATENATE ep_odd_header lc_marker_right lv_value INTO ep_odd_header. + ENDIF. + + ENDIF. +* ---------------------------------------------------------------------- + IF ep_odd_footer IS SUPPLIED. + + IF me->odd_footer-left_value IS NOT INITIAL. + lv_value = me->process_header_footer( ip_header = me->odd_footer ip_side = 'LEFT' ). + CONCATENATE lc_marker_left lv_value INTO ep_odd_footer. + ENDIF. + + IF me->odd_footer-center_value IS NOT INITIAL. + lv_value = me->process_header_footer( ip_header = me->odd_footer ip_side = 'CENTER' ). + CONCATENATE ep_odd_footer lc_marker_center lv_value INTO ep_odd_footer. + ENDIF. + + IF me->odd_footer-right_value IS NOT INITIAL. + lv_value = me->process_header_footer( ip_header = me->odd_footer ip_side = 'RIGHT' ). + CONCATENATE ep_odd_footer lc_marker_right lv_value INTO ep_odd_footer. + ENDIF. + + ENDIF. +* ---------------------------------------------------------------------- + IF ep_even_header IS SUPPLIED. + + IF me->even_header-left_value IS NOT INITIAL. + lv_value = me->process_header_footer( ip_header = me->even_header ip_side = 'LEFT' ). + CONCATENATE lc_marker_left lv_value INTO ep_even_header. + ENDIF. + + IF me->even_header-center_value IS NOT INITIAL. + lv_value = me->process_header_footer( ip_header = me->even_header ip_side = 'CENTER' ). + CONCATENATE ep_even_header lc_marker_center lv_value INTO ep_even_header. + ENDIF. + + IF me->even_header-right_value IS NOT INITIAL. + lv_value = me->process_header_footer( ip_header = me->even_header ip_side = 'RIGHT' ). + CONCATENATE ep_even_header lc_marker_right lv_value INTO ep_even_header. + ENDIF. + + ENDIF. +* ---------------------------------------------------------------------- + IF ep_even_footer IS SUPPLIED. + + IF me->even_footer-left_value IS NOT INITIAL. + lv_value = me->process_header_footer( ip_header = me->even_footer ip_side = 'LEFT' ). + CONCATENATE lc_marker_left lv_value INTO ep_even_footer. + ENDIF. + + IF me->even_footer-center_value IS NOT INITIAL. + lv_value = me->process_header_footer( ip_header = me->even_footer ip_side = 'CENTER' ). + CONCATENATE ep_even_footer lc_marker_center lv_value INTO ep_even_footer. + ENDIF. + + IF me->even_footer-right_value IS NOT INITIAL. + lv_value = me->process_header_footer( ip_header = me->even_footer ip_side = 'RIGHT' ). + CONCATENATE ep_even_footer lc_marker_right lv_value INTO ep_even_footer. + ENDIF. + + ENDIF. +* ---------------------------------------------------------------------- + endmethod. + + + + + + method PROCESS_HEADER_FOOTER. + +* ---------------------------------------------------------------------- +* Only Basic font/text formatting possible: +* Bold (yes / no), Font Type, Font Size + + DATA: lv_fname(12) TYPE c + , lv_string TYPE string + . + + FIELD-SYMBOLS: <lv_value> TYPE string + , <ls_font> TYPE zexcel_s_style_font + . + +* ---------------------------------------------------------------------- + CONCATENATE ip_side '_VALUE' INTO lv_fname. + ASSIGN COMPONENT lv_fname OF STRUCTURE ip_header TO <lv_value>. + + CONCATENATE ip_side '_FONT' INTO lv_fname. + ASSIGN COMPONENT lv_fname OF STRUCTURE ip_header TO <ls_font>. + + IF <ls_font> IS ASSIGNED AND <lv_value> IS ASSIGNED. + + IF <ls_font>-name IS NOT INITIAL. + CONCATENATE '&"' <ls_font>-name ',' INTO rv_processed_string. + ELSE. + rv_processed_string = '&"-,'. + ENDIF. + + IF <ls_font>-bold = abap_true. + CONCATENATE rv_processed_string 'Bold"' INTO rv_processed_string. + ELSE. + CONCATENATE rv_processed_string 'Standard"' INTO rv_processed_string. + ENDIF. + + IF <ls_font>-size IS NOT INITIAL. + lv_string = <ls_font>-size. + CONCATENATE rv_processed_string '&' lv_string INTO rv_processed_string. + ENDIF. + + CONCATENATE rv_processed_string <lv_value> INTO rv_processed_string. + + ENDIF. +* ---------------------------------------------------------------------- + + endmethod. + + + + + + + method SET_HEADER_FOOTER. + +* Only Basic font/text formatting possible: +* Bold (yes / no), Font Type, Font Size +* +* usefull placeholders, which can be used in header/footer value strings +* '&P' - page number +* '&N' - total number of pages +* '&D' - Date +* '&T' - Time +* '&F' - File Name +* '&Z' - Path +* '&A' - Sheet name +* new line via class constant CL_ABAP_CHAR_UTILITIES=>newline +* +* Example Value String 'page &P of &N' +* +* DO NOT USE &L , &C or &R which automatically created as position markers + + me->odd_header = ip_odd_header. + me->odd_footer = ip_odd_footer. + me->even_header = ip_even_header. + me->even_footer = ip_even_footer. + + IF me->even_header IS NOT INITIAL OR me->even_footer IS NOT INITIAL. + me->diff_oddeven_headerfooter = abap_true. + ENDIF. + + + endmethod. + + + + + + + + + + method SET_PAGE_MARGINS. + DATA: lv_coef TYPE f, + lv_unit TYPE string. + + lv_unit = ip_unit. + TRANSLATE lv_unit TO UPPER CASE. + + CASE lv_unit. + WHEN 'IN'. lv_coef = 1. + WHEN 'CM'. lv_coef = '0.393700787'. + WHEN 'MM'. lv_coef = '0.0393700787'. + ENDCASE. + + IF ip_bottom IS SUPPLIED. margin_bottom = lv_coef * ip_bottom. ENDIF. + IF ip_footer IS SUPPLIED. margin_footer = lv_coef * ip_footer. ENDIF. + IF ip_header IS SUPPLIED. margin_header = lv_coef * ip_header. ENDIF. + IF ip_left IS SUPPLIED. margin_left = lv_coef * ip_left. ENDIF. + IF ip_right IS SUPPLIED. margin_right = lv_coef * ip_right. ENDIF. + IF ip_top IS SUPPLIED. margin_top = lv_coef * ip_top. ENDIF. + + endmethod. + + + + *"* 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 CONSTRUCTOR. + + + CREATE OBJECT font. + CREATE OBJECT fill. + CREATE OBJECT borders. + CREATE OBJECT alignment. + CREATE OBJECT number_format. + CREATE OBJECT protection. + +* Start of insertion # issue 139 - Dateretention of cellstyles + IF ip_guid IS NOT INITIAL. + me->guid = ip_guid. + ELSE. +* End of insertion # issue 139 - Dateretention of cellstyles + CALL FUNCTION 'GUID_CREATE' + IMPORTING + ev_guid_16 = me->guid. +* Start of insertion # issue 139 - Dateretention of cellstyles + ENDIF. +* End of insertion # issue 139 - Dateretention of cellstyles + + endmethod. + + + + method GET_GUID. + + + ep_guid = me->guid. + endmethod. + + + + *"* 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 ADD. + + + styles->add( ip_style ). + endmethod. + + + method CLEAR. + + + styles->clear( ). + endmethod. + + + method CONSTRUCTOR. + + + CREATE OBJECT styles. + endmethod. + + + + + method GET. + + + eo_style ?= styles->if_object_collection~get( ip_index ). + endmethod. + + + + method GET_ITERATOR. + + + eo_iterator ?= styles->if_object_collection~get_iterator( ). + endmethod. + + + + method IS_EMPTY. + + + is_empty = styles->if_object_collection~is_empty( ). + endmethod. + + + + + method REGISTER_NEW_STYLE. + + + me->add( io_style ). + ep_style_code = me->size( ) - 1. "style count starts from 0 + endmethod. + + + + method REMOVE. + + + styles->remove( ip_style ). + endmethod. + + + + method SIZE. + + + ep_size = styles->if_object_collection~size( ). + endmethod. + + + + *"* 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 ADD. + styles_conditional->add( ip_style_conditional ). + endmethod. + + + method CLEAR. + styles_conditional->clear( ). + endmethod. + + + method CONSTRUCTOR. + + CREATE OBJECT styles_conditional. + + endmethod. + + + + + method GET. + DATA lv_index TYPE i. + lv_index = ip_index. + eo_style_conditional ?= styles_conditional->if_object_collection~get( lv_index ). + endmethod. + + + + method GET_ITERATOR. + eo_iterator ?= styles_conditional->if_object_collection~get_iterator( ). + endmethod. + + + + method IS_EMPTY. + is_empty = styles_conditional->if_object_collection~is_empty( ). + endmethod. + + + + method REMOVE. + styles_conditional->remove( ip_style_conditional ). + endmethod. + + + + method SIZE. + ep_size = styles_conditional->if_object_collection~size( ). + endmethod. + + + + *"* 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 + + ABAP + + + + + + + + + + + + + + + + + + method CONSTRUCTOR. + horizontal = me->c_horizontal_general. + vertical = me->c_vertical_bottom. + wrapText = abap_false. + shrinkToFit = abap_false. + endmethod. + + + + method GET_STRUCTURE. + + es_alignment-horizontal = me->horizontal. + es_alignment-vertical = me->vertical. + es_alignment-textrotation = me->textrotation. + es_alignment-wraptext = me->wraptext. + es_alignment-shrinktofit = me->shrinktofit. + es_alignment-indent = me->indent. + + endmethod. + + + + *"* use this source file for the definition and implementation of +*"* local helper classes, interface definitions and type +*"* declarations + *"* use this source file for any type of declarations (class +*"* definitions, interfaces or type declarations) you need for +*"* components in the private section + *"* use this source file for any macro definitions you need +*"* in the implementation part of the class + + + + + + + + + + method CREATE. + + +* Office 2007 file format is a cab of several xml files with extension .xlsx + + DATA: lo_zip TYPE REF TO cl_abap_zip, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + lo_active_worksheet TYPE REF TO zcl_excel_worksheet, + lo_iterator TYPE REF TO cl_object_collection_iterator, + lo_nested_iterator TYPE REF TO cl_object_collection_iterator, + lo_table TYPE REF TO zcl_excel_table, + lo_drawing TYPE REF TO zcl_excel_drawing, + lo_drawings TYPE REF TO zcl_excel_drawings. + + DATA: lv_content TYPE xstring, + lv_active TYPE flag, + lv_xl_sheet TYPE string, + lv_xl_sheet_rels TYPE string, + lv_xl_drawing TYPE string, + lv_xl_drawing_rels TYPE string, + lv_syindex TYPE string, + lv_value TYPE string, + lv_drawing_index TYPE i. + +********************************************************************** +* Start of insertion # issue 139 - Dateretention of cellstyles + me->excel->add_static_styles( ). +* End of insertion # issue 139 - Dateretention of cellstyles + +********************************************************************** +* STEP 1: Create archive object file (ZIP) + CREATE OBJECT lo_zip. + +********************************************************************** +* STEP 2: Add [Content_Types].xml to zip + lv_content = me->create_content_types( ). + lo_zip->add( name = me->c_content_types + content = lv_content ). + +********************************************************************** +* STEP 3: Add _rels/.rels to zip + lv_content = me->create_relationships( ). + lo_zip->add( name = me->c_relationships + content = lv_content ). + +********************************************************************** +* STEP 4: Add docProps/app.xml to zip + lv_content = me->create_docprops_app( ). + lo_zip->add( name = me->c_docprops_app + content = lv_content ). + +********************************************************************** +* STEP 5: Add docProps/core.xml to zip + lv_content = me->create_docprops_core( ). + lo_zip->add( name = me->c_docprops_core + content = lv_content ). + +********************************************************************** +* STEP 6: Add xl/_rels/workbook.xml.rels to zip + lv_content = me->create_xl_relationships( ). + lo_zip->add( name = me->c_xl_relationships + content = lv_content ). + +********************************************************************** +* STEP 6: Add xl/_rels/workbook.xml.rels to zip + lv_content = me->create_xl_theme( ). + lo_zip->add( name = me->c_xl_theme + content = lv_content ). + +********************************************************************** +* STEP 7: Add xl/workbook.xml to zip + lv_content = me->create_xl_workbook( ). + lo_zip->add( name = me->c_xl_workbook + content = lv_content ). + +********************************************************************** +* STEP 8: Add xl/workbook.xml to zip +* lv_content = me->create_xl_styles_static( ). + lv_content = me->create_xl_styles( ). + lo_zip->add( name = me->c_xl_styles + content = lv_content ). + +********************************************************************** +* STEP 9: Add sharedStrings.xml to zip + lv_content = me->create_xl_sharedstrings( ). + lo_zip->add( name = me->c_xl_sharedstrings + content = lv_content ). + +********************************************************************** +* STEP 10: Add sheet#.xml and drawing#.xml to zip + lo_iterator = me->excel->get_worksheets_iterator( ). + lo_active_worksheet = me->excel->get_active_worksheet( ). + lv_drawing_index = 1. + + WHILE lo_iterator->if_object_collection_iterator~has_next( ) EQ abap_true. + lo_worksheet ?= lo_iterator->if_object_collection_iterator~get_next( ). + IF lo_active_worksheet->get_guid( ) EQ lo_worksheet->get_guid( ). + lv_active = abap_true. + ELSE. + lv_active = abap_false. + ENDIF. + + lv_content = me->create_xl_sheet( io_worksheet = lo_worksheet + iv_active = lv_active ). + lv_xl_sheet = me->c_xl_sheet. + MOVE sy-index TO lv_syindex. + SHIFT lv_syindex RIGHT DELETING TRAILING space. + SHIFT lv_syindex LEFT DELETING LEADING space. + REPLACE ALL OCCURRENCES OF '#' IN lv_xl_sheet WITH lv_syindex. + lo_zip->add( name = lv_xl_sheet + content = lv_content ). + + lv_xl_sheet_rels = me->c_xl_sheet_rels. + lv_content = me->create_xl_sheet_rels( io_worksheet = lo_worksheet + iv_drawing_index = lv_drawing_index ). + REPLACE ALL OCCURRENCES OF '#' IN lv_xl_sheet_rels WITH lv_syindex. + lo_zip->add( name = lv_xl_sheet_rels + content = lv_content ). + + lo_nested_iterator = lo_worksheet->get_tables_iterator( ). + + WHILE lo_nested_iterator->if_object_collection_iterator~has_next( ) EQ abap_true. + lo_table ?= lo_nested_iterator->if_object_collection_iterator~get_next( ). + lv_content = me->create_xl_table( lo_table ). + + lv_value = lo_table->get_name( ). + CONCATENATE 'xl/tables/' lv_value '.xml' INTO lv_value. + lo_zip->add( name = lv_value + content = lv_content ). + ENDWHILE. + +* Add drawings ********************************** + lo_drawings = lo_worksheet->get_drawings( ). + IF lo_drawings->is_empty( ) = abap_false. + MOVE lv_drawing_index TO lv_syindex. + SHIFT lv_syindex RIGHT DELETING TRAILING space. + SHIFT lv_syindex LEFT DELETING LEADING space. + + lv_content = me->create_xl_drawings( lo_worksheet ). + lv_xl_drawing = me->c_xl_drawings. + REPLACE ALL OCCURRENCES OF '#' IN lv_xl_drawing WITH lv_syindex. + lo_zip->add( name = lv_xl_drawing + content = lv_content ). + + lv_content = me->create_xl_drawings_rels( lo_worksheet ). + lv_xl_drawing_rels = me->c_xl_drawings_rels. + REPLACE ALL OCCURRENCES OF '#' IN lv_xl_drawing_rels WITH lv_syindex. + lo_zip->add( name = lv_xl_drawing_rels + content = lv_content ). + ADD 1 TO lv_drawing_index. + ENDIF. + ENDWHILE. + +********************************************************************** +* STEP 11: Add media + lo_iterator = me->excel->get_drawings_iterator( zcl_excel_drawing=>type_image ). + WHILE lo_iterator->if_object_collection_iterator~has_next( ) EQ abap_true. + lo_drawing ?= lo_iterator->if_object_collection_iterator~get_next( ). + + lv_content = lo_drawing->get_media( ). + lv_value = lo_drawing->get_media_name( ). + CONCATENATE 'xl/media/' lv_value INTO lv_value. + lo_zip->add( name = lv_value + content = lv_content ). + ENDWHILE. + +********************************************************************** +* STEP 12: Add charts + lo_iterator = me->excel->get_drawings_iterator( zcl_excel_drawing=>type_chart ). + WHILE lo_iterator->if_object_collection_iterator~has_next( ) EQ abap_true. + lo_drawing ?= lo_iterator->if_object_collection_iterator~get_next( ). + + lv_content = lo_drawing->get_media( ). + lv_value = lo_drawing->get_media_name( ). + CONCATENATE 'xl/charts/' lv_value INTO lv_value. + lo_zip->add( name = lv_value + content = lv_content ). + ENDWHILE. + +********************************************************************** +* STEP 9: Add vbaProject.bin to zip + lo_zip->add( name = me->c_xl_vbaproject + content = me->excel->zif_excel_book_vba_project~vbaproject ). + +********************************************************************** +* STEP 12: Create the final zip + ep_excel = lo_zip->save( ). + + endmethod. + + + method CREATE_CONTENT_TYPES. +** Constant node name + DATA: lc_xml_node_workb_ct TYPE string VALUE 'application/vnd.ms-excel.sheet.macroEnabled.main+xml', + lc_xml_node_default TYPE string VALUE 'Default', + " Node attributes + lc_xml_attr_partname TYPE string VALUE 'PartName', + lc_xml_attr_extension TYPE string VALUE 'Extension', + lc_xml_attr_contenttype TYPE string VALUE 'ContentType', + lc_xml_attr_codename TYPE string VALUE 'codeName', + lc_xml_node_workb_pn TYPE string VALUE '/xl/workbook.xml', + lc_xml_node_bin_ext TYPE string VALUE 'bin', + lc_xml_node_bin_ct TYPE string VALUE 'application/vnd.ms-office.vbaProject'. + + + DATA: lo_ixml TYPE REF TO if_ixml, + lo_document TYPE REF TO if_ixml_document, + lo_document_xml TYPE REF TO cl_xml_document, + lo_element_root TYPE REF TO if_ixml_node, + lo_element TYPE REF TO if_ixml_element, + lo_collection TYPE REF TO if_ixml_node_collection, + lo_iterator TYPE REF TO if_ixml_node_iterator, + lo_node TYPE REF TO if_ixml_node, + lo_encoding TYPE REF TO if_ixml_encoding, + lo_streamfactory TYPE REF TO if_ixml_stream_factory, + lo_ostream TYPE REF TO if_ixml_ostream, + lo_renderer TYPE REF TO if_ixml_renderer. + + DATA: lv_subrc TYPE sysubrc, + lv_contenttype TYPE string, + lv_syindex(2) TYPE c. + +********************************************************************** +* STEP 3: Create standard contentType + ep_content = super->create_content_types( ). + +********************************************************************** +* STEP 2: modify XML adding the extension bin definition + + CREATE OBJECT lo_document_xml. + lv_subrc = lo_document_xml->parse_xstring( ep_content ). + + lo_document ?= lo_document_xml->m_document. + lo_element_root = lo_document->if_ixml_node~get_first_child( ). + + " extension node + lo_element = lo_document->create_simple_element( name = lc_xml_node_default + parent = lo_document ). + lo_element->set_attribute_ns( name = lc_xml_attr_extension + value = lc_xml_node_bin_ext ). + lo_element->set_attribute_ns( name = lc_xml_attr_contenttype + value = lc_xml_node_bin_ct ). + lo_element_root->append_child( new_child = lo_element ). + +********************************************************************** +* STEP 3: modify XML changing the contentType of node Override /xl/workbook.xml + + lo_collection = lo_document->get_elements_by_tag_name( 'Override' ). + lo_iterator = lo_collection->create_iterator( ). + lo_element ?= lo_iterator->get_next( ). + WHILE lo_element IS BOUND. + lv_contenttype = lo_element->get_attribute_ns( lc_xml_attr_partname ). + IF lv_contenttype EQ lc_xml_node_workb_pn. + lo_element->remove_attribute_ns( lc_xml_attr_contenttype ). + lo_element->set_attribute_ns( name = lc_xml_attr_contenttype + value = lc_xml_node_workb_ct ). + EXIT. + ENDIF. + lo_element ?= lo_iterator->get_next( ). + ENDWHILE. + +********************************************************************** +* STEP 3: Create xstring stream + CLEAR ep_content. + lo_ixml = cl_ixml=>create( ). + lo_streamfactory = lo_ixml->create_stream_factory( ). + lo_ostream = lo_streamfactory->create_ostream_xstring( string = ep_content ). + lo_renderer = lo_ixml->create_renderer( ostream = lo_ostream document = lo_document ). + lo_renderer->render( ). + + endmethod. + + + method CREATE_XL_RELATIONSHIPS. + +** Constant node name + DATA: lc_xml_node_relationships TYPE string VALUE 'Relationships', + lc_xml_node_relationship TYPE string VALUE 'Relationship', + " Node attributes + lc_xml_attr_id TYPE string VALUE 'Id', + lc_xml_attr_type TYPE string VALUE 'Type', + lc_xml_attr_target TYPE string VALUE 'Target', + " Node id + lc_xml_node_ridx_id TYPE string VALUE 'rId#', + " Node type + lc_xml_node_rid_vba_tp TYPE string VALUE 'http://schemas.microsoft.com/office/2006/relationships/vbaProject', + " Node target + lc_xml_node_rid_vba_tg TYPE string VALUE 'vbaProject.bin'. + + DATA: lo_ixml TYPE REF TO if_ixml, + lo_document TYPE REF TO if_ixml_document, + lo_document_xml TYPE REF TO cl_xml_document, + lo_element_root TYPE REF TO if_ixml_node, + lo_element TYPE REF TO if_ixml_element, + lo_node TYPE REF TO if_ixml_node, + lo_encoding TYPE REF TO if_ixml_encoding, + lo_streamfactory TYPE REF TO if_ixml_stream_factory, + lo_ostream TYPE REF TO if_ixml_ostream, + lo_renderer TYPE REF TO if_ixml_renderer. + + DATA: lv_xml_node_ridx_tg TYPE string, + lv_xml_node_ridx_id TYPE string, + lv_size TYPE i, + lv_subrc TYPE sysubrc, + lv_syindex(2) TYPE c. + +********************************************************************** +* STEP 3: Create standard relationship + ep_content = super->create_xl_relationships( ). + +********************************************************************** +* STEP 2: modify XML adding the vbaProject relation + + CREATE OBJECT lo_document_xml. + lv_subrc = lo_document_xml->parse_xstring( ep_content ). + + lo_document ?= lo_document_xml->m_document. + lo_element_root = lo_document->if_ixml_node~get_first_child( ). + + + lv_size = excel->get_worksheets_size( ). + + " Relationship node + lo_element = lo_document->create_simple_element( name = lc_xml_node_relationship + parent = lo_document ). + ADD 4 TO lv_size. + lv_syindex = lv_size. + SHIFT lv_syindex RIGHT DELETING TRAILING space. + SHIFT lv_syindex LEFT DELETING LEADING space. + lv_xml_node_ridx_id = lc_xml_node_ridx_id. + REPLACE ALL OCCURRENCES OF '#' IN lv_xml_node_ridx_id WITH lv_syindex. + lo_element->set_attribute_ns( name = lc_xml_attr_id + value = lv_xml_node_ridx_id ). + lo_element->set_attribute_ns( name = lc_xml_attr_type + value = lc_xml_node_rid_vba_tp ). + lo_element->set_attribute_ns( name = lc_xml_attr_target + value = lc_xml_node_rid_vba_tg ). + lo_element_root->append_child( new_child = lo_element ). + +********************************************************************** +* STEP 3: Create xstring stream + CLEAR ep_content. + lo_ixml = cl_ixml=>create( ). + lo_streamfactory = lo_ixml->create_stream_factory( ). + lo_ostream = lo_streamfactory->create_ostream_xstring( string = ep_content ). + lo_renderer = lo_ixml->create_renderer( ostream = lo_ostream document = lo_document ). + lo_renderer->render( ). + + endmethod. + + + method CREATE_XL_SHEET. + +** Constant node name + DATA: lc_xml_attr_codename TYPE string VALUE 'codeName'. + + DATA: lo_ixml TYPE REF TO if_ixml, + lo_document TYPE REF TO if_ixml_document, + lo_document_xml TYPE REF TO cl_xml_document, + lo_element_root TYPE REF TO if_ixml_node, + lo_element TYPE REF TO if_ixml_element, + lo_collection TYPE REF TO if_ixml_node_collection, + lo_iterator TYPE REF TO if_ixml_node_iterator, + lo_node TYPE REF TO if_ixml_node, + lo_encoding TYPE REF TO if_ixml_encoding, + lo_streamfactory TYPE REF TO if_ixml_stream_factory, + lo_ostream TYPE REF TO if_ixml_ostream, + lo_renderer TYPE REF TO if_ixml_renderer. + + DATA: lv_subrc TYPE sysubrc, + lv_syindex(2) TYPE c. + +********************************************************************** +* STEP 3: Create standard relationship + ep_content = super->create_xl_sheet( io_worksheet = io_worksheet + iv_active = iv_active ). + +********************************************************************** +* STEP 2: modify XML adding the vbaProject relation + + CREATE OBJECT lo_document_xml. + lv_subrc = lo_document_xml->parse_xstring( ep_content ). + + lo_document ?= lo_document_xml->m_document. + lo_element_root = lo_document->if_ixml_node~get_first_child( ). + +* lo_collection = lo_document->get_elements_by_tag_name( 'fileVersion' ). +* lo_iterator = lo_collection->create_iterator( ). +* lo_element ?= lo_iterator->get_next( ). +* WHILE lo_element IS BOUND. +* lo_element->set_attribute_ns( name = lc_xml_attr_codename +* value = me->excel->zif_excel_book_vba_project~codename ). +* lo_element ?= lo_iterator->get_next( ). +* ENDWHILE. + + lo_collection = lo_document->get_elements_by_tag_name( 'sheetPr' ). + lo_iterator = lo_collection->create_iterator( ). + lo_element ?= lo_iterator->get_next( ). + WHILE lo_element IS BOUND. + lo_element->set_attribute_ns( name = lc_xml_attr_codename + value = io_worksheet->zif_excel_sheet_vba_project~codename_pr ). + lo_element ?= lo_iterator->get_next( ). + ENDWHILE. + +********************************************************************** +* STEP 3: Create xstring stream + CLEAR ep_content. + lo_ixml = cl_ixml=>create( ). + lo_streamfactory = lo_ixml->create_stream_factory( ). + lo_ostream = lo_streamfactory->create_ostream_xstring( string = ep_content ). + lo_renderer = lo_ixml->create_renderer( ostream = lo_ostream document = lo_document ). + lo_renderer->render( ). + endmethod. + + + method CREATE_XL_WORKBOOK. + +** Constant node name + DATA: lc_xml_attr_codename TYPE string VALUE 'codeName'. + + DATA: lo_ixml TYPE REF TO if_ixml, + lo_document TYPE REF TO if_ixml_document, + lo_document_xml TYPE REF TO cl_xml_document, + lo_element_root TYPE REF TO if_ixml_node, + lo_element TYPE REF TO if_ixml_element, + lo_collection TYPE REF TO if_ixml_node_collection, + lo_iterator TYPE REF TO if_ixml_node_iterator, + lo_node TYPE REF TO if_ixml_node, + lo_encoding TYPE REF TO if_ixml_encoding, + lo_streamfactory TYPE REF TO if_ixml_stream_factory, + lo_ostream TYPE REF TO if_ixml_ostream, + lo_renderer TYPE REF TO if_ixml_renderer. + + DATA: lv_subrc TYPE sysubrc, + lv_syindex(2) TYPE c. + +********************************************************************** +* STEP 3: Create standard relationship + ep_content = super->create_xl_workbook( ). + +********************************************************************** +* STEP 2: modify XML adding the vbaProject relation + + CREATE OBJECT lo_document_xml. + lv_subrc = lo_document_xml->parse_xstring( ep_content ). + + lo_document ?= lo_document_xml->m_document. + lo_element_root = lo_document->if_ixml_node~get_first_child( ). + + lo_collection = lo_document->get_elements_by_tag_name( 'fileVersion' ). + lo_iterator = lo_collection->create_iterator( ). + lo_element ?= lo_iterator->get_next( ). + WHILE lo_element IS BOUND. + lo_element->set_attribute_ns( name = lc_xml_attr_codename + value = me->excel->zif_excel_book_vba_project~codename ). + lo_element ?= lo_iterator->get_next( ). + ENDWHILE. + + lo_collection = lo_document->get_elements_by_tag_name( 'workbookPr' ). + lo_iterator = lo_collection->create_iterator( ). + lo_element ?= lo_iterator->get_next( ). + WHILE lo_element IS BOUND. + lo_element->set_attribute_ns( name = lc_xml_attr_codename + value = me->excel->zif_excel_book_vba_project~codename_pr ). + lo_element ?= lo_iterator->get_next( ). + ENDWHILE. + +********************************************************************** +* STEP 3: Create xstring stream + CLEAR ep_content. + lo_ixml = cl_ixml=>create( ). + lo_streamfactory = lo_ixml->create_stream_factory( ). + lo_ostream = lo_streamfactory->create_ostream_xstring( string = ep_content ). + lo_renderer = lo_ixml->create_renderer( ostream = lo_ostream document = lo_document ). + lo_renderer->render( ). + endmethod. + + + + *"* 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 LOAD_DATA. + DATA: lo_columns TYPE REF TO cl_salv_columns_table, + lo_aggregations TYPE REF TO cl_salv_aggregations, + lo_sorts TYPE REF TO cl_salv_sorts, + lo_filters TYPE REF TO cl_salv_filters, + lo_functional TYPE REF TO cl_salv_functional_settings, + lo_display TYPE REF TO cl_salv_display_settings, + lo_selections TYPE REF TO cl_salv_selections. + + DATA: ls_vari TYPE disvariant, + lo_layout TYPE REF TO cl_salv_layout. + + DATA: lr_form_tol TYPE REF TO cl_salv_form, + lr_form_eol TYPE REF TO cl_salv_form. + + DATA lt_kkblo_fieldcat TYPE kkblo_t_fieldcat. + DATA ls_kkblo_layout TYPE kkblo_layout. + DATA lt_kkblo_filter TYPE kkblo_t_filter. + DATA lt_kkblo_sort TYPE kkblo_t_sortinfo. + + lo_layout = io_salv->get_layout( ) . + lo_columns = io_salv->get_columns( ). + lo_aggregations = io_salv->get_aggregations( ) . + lo_sorts = io_salv->get_sorts( ) . + lo_filters = io_salv->get_filters( ) . + lo_display = io_salv->get_display_settings( ) . + lo_functional = io_salv->get_functional_settings( ) . + + REFRESH: wt_fcat, + wt_sort, + wt_filt. + +* First update metadata if we can. + IF io_salv->is_offline( ) = abap_false. + io_salv->get_metadata( ) . + ELSE. +* If we are offline we need to build this. + cl_salv_controller_metadata=>get_variant( + EXPORTING + r_layout = lo_layout + CHANGING + s_variant = ls_vari ). + ENDIF. + +*... get the column information + wt_fcat = cl_salv_controller_metadata=>get_lvc_fieldcatalog( + r_columns = lo_columns + r_aggregations = lo_aggregations ). + +*... get the layout information + cl_salv_controller_metadata=>get_lvc_layout( + EXPORTING + r_functional_settings = lo_functional + r_display_settings = lo_display + r_columns = lo_columns + r_aggregations = lo_aggregations + CHANGING + s_layout = ws_layo ). + +* the fieldcatalog is not complete yet! + CALL FUNCTION 'LVC_FIELDCAT_COMPLETE' + EXPORTING + i_complete = 'X' + i_refresh_buffer = space + i_buffer_active = space + is_layout = ws_layo + i_test = '1' + i_fcat_complete = 'X' + IMPORTING +* E_EDIT = + es_layout = ws_layo + CHANGING + ct_fieldcat = wt_fcat. + + IF ls_vari IS NOT INITIAL AND io_salv->is_offline( ) = abap_true. + CALL FUNCTION 'LVC_TRANSFER_TO_KKBLO' + EXPORTING + it_fieldcat_lvc = wt_fcat + is_layout_lvc = ws_layo + IMPORTING + et_fieldcat_kkblo = lt_kkblo_fieldcat + es_layout_kkblo = ls_kkblo_layout + TABLES + it_data = it_table + EXCEPTIONS + it_data_missing = 1 + it_fieldcat_lvc_missing = 2 + OTHERS = 3. + IF sy-subrc <> 0. +* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO +* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. + ENDIF. + + CALL FUNCTION 'LT_VARIANT_LOAD' + EXPORTING +* I_TOOL = 'LT' + i_tabname = '1' +* I_TABNAME_SLAVE = + i_dialog = ' ' +* I_USER_SPECIFIC = ' ' +* I_DEFAULT = 'X' +* I_NO_REPTEXT_OPTIMIZE = +* I_VIA_GRID = + i_fcat_complete = 'X' + IMPORTING +* E_EXIT = + et_fieldcat = lt_kkblo_fieldcat + et_sort = lt_kkblo_sort + et_filter = lt_kkblo_filter + CHANGING + cs_layout = ls_kkblo_layout + ct_default_fieldcat = lt_kkblo_fieldcat + cs_variant = ls_vari + EXCEPTIONS + wrong_input = 1 + fc_not_complete = 2 + not_found = 3 + OTHERS = 4 + . + IF sy-subrc <> 0. +* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO +* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. + ENDIF. + + CALL FUNCTION 'LVC_TRANSFER_FROM_KKBLO' + EXPORTING +* I_TECH_COMPLETE = +* I_STRUCTURE_NAME = + it_fieldcat_kkblo = lt_kkblo_fieldcat + it_sort_kkblo = lt_kkblo_sort + it_filter_kkblo = lt_kkblo_filter +* IT_SPECIAL_GROUPS_KKBLO = +* IT_FILTERED_ENTRIES_KKBLO = +* IT_GROUPLEVELS_KKBLO = +* IS_SUBTOT_OPTIONS_KKBLO = + is_layout_kkblo = ls_kkblo_layout +* IS_REPREP_ID_KKBLO = +* I_CALLBACK_PROGRAM_KKBLO = +* IT_ADD_FIELDCAT = +* IT_EXCLUDING_KKBLO = +* IT_EXCEPT_QINFO_KKBLO = + IMPORTING + et_fieldcat_lvc = wt_fcat + et_sort_lvc = wt_sort + et_filter_lvc = wt_filt +* ET_SPECIAL_GROUPS_LVC = +* ET_FILTER_INDEX_LVC = +* ET_GROUPLEVELS_LVC = +* ES_TOTAL_OPTIONS_LVC = + es_layout_lvc = ws_layo +* ES_VARIANT_LVC = +* E_VARIANT_SAVE_LVC = +* ES_PRINT_INFO_LVC = +* ES_REPREP_LVC = +* E_REPREP_ACTIVE_LVC = +* ET_EXCLUDING_LVC = +* ET_EXCEPT_QINFO_LVC = + TABLES + it_data = it_table + EXCEPTIONS + it_data_missing = 1 + OTHERS = 2 + . + IF sy-subrc <> 0. +* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO +* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. + ENDIF. + + ELSE. +* ... get the sort information + wt_sort = cl_salv_controller_metadata=>get_lvc_sort( lo_sorts ). + +* ... get the filter information + wt_filt = cl_salv_controller_metadata=>get_lvc_filter( lo_filters ). + ENDIF. + + endmethod. + + + + + + + + + *"* 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 + +TYPES: BEGIN OF ts_alv_types, + seoclass TYPE seoclsname, + clsname TYPE seoclsname, + END OF ts_alv_types, + tt_alv_types TYPE HASHED TABLE OF ts_alv_types WITH UNIQUE KEY seoclass. + +TYPES: BEGIN OF ts_sort_values, + fieldname TYPE fieldname, + row_int TYPE zexcel_cell_row, + value TYPE REF TO data, + new TYPE flag, + sort_level TYPE int4, + is_collapsed type flag, + END OF ts_sort_values, + + tt_sort_values TYPE HASHED TABLE OF ts_sort_values WITH UNIQUE KEY fieldname. +TYPES: BEGIN OF ts_subtotal_rows, + row_int TYPE zexcel_cell_row, + row_int_start TYPE zexcel_cell_row, + columnname TYPE fieldname, + END OF ts_subtotal_rows, + + tt_subtotal_rows TYPE HASHED TABLE OF ts_subtotal_rows WITH UNIQUE KEY row_int. + +TYPES: BEGIN OF ts_styles, + type TYPE char1, + alignment TYPE zexcel_alignment, + inttype TYPE inttype, + decimals TYPE int1, + style TYPE REF TO zcl_excel_style, + guid TYPE zexcel_cell_style, + END OF ts_styles, + + tt_styles TYPE HASHED TABLE OF ts_styles WITH UNIQUE KEY type alignment inttype decimals. + +TYPES: BEGIN OF ts_color_styles, + guid_old TYPE zexcel_cell_style, + fontcolor TYPE zexcel_style_color_argb, + fillcolor TYPE zexcel_style_color_argb, + style_new TYPE REF TO zcl_excel_style, + END OF ts_color_styles, + + tt_color_styles TYPE HASHED TABLE OF ts_color_styles WITH UNIQUE KEY guid_old fontcolor fillcolor. + *"* use this source file for any macro definitions you need +*"* in the implementation part of the class + + + + + + + + + + + + + + + + ABAP + SLIS + SOI + + + + + + + + + + + + + + + + + + + + + + + + + + + + method ASK_OPTION. + DATA: ls_sval TYPE sval, + lt_sval TYPE STANDARD TABLE OF sval, + l_returncode TYPE string, + lt_fields TYPE ddfields, + ls_fields TYPE dfies. + + FIELD-SYMBOLS: <fs> TYPE ANY. + + rs_option = ws_option. + + CALL FUNCTION 'DDIF_FIELDINFO_GET' + EXPORTING + tabname = 'ZEXCEL_S_CONVERTER_OPTION' +* FIELDNAME = ' ' +* LANGU = sy-langu +* LFIELDNAME = ' ' +* ALL_TYPES = ' ' +* GROUP_NAMES = ' ' +* UCLEN = +* IMPORTING +* X030L_WA = +* DDOBJTYPE = +* DFIES_WA = +* LINES_DESCR = + TABLES + dfies_tab = lt_fields +* FIXED_VALUES = + EXCEPTIONS + not_found = 1 + internal_error = 2 + OTHERS = 3 + . + IF sy-subrc <> 0. +* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO +* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. + ENDIF. + + LOOP AT lt_fields INTO ls_fields. + ASSIGN COMPONENT ls_fields-fieldname OF STRUCTURE ws_option TO <fs>. + IF sy-subrc = 0. + CLEAR ls_sval. + ls_sval-tabname = ls_fields-tabname. + ls_sval-fieldname = ls_fields-fieldname. + ls_sval-value = <fs>. + ls_sval-field_attr = space. + ls_sval-field_obl = space. + ls_sval-comp_code = space. + ls_sval-fieldtext = ls_fields-scrtext_m. + ls_sval-comp_tab = space. + ls_sval-comp_field = space. + ls_sval-novaluehlp = space. + INSERT ls_sval INTO TABLE lt_sval. + ENDIF. + ENDLOOP. + + CALL FUNCTION 'POPUP_GET_VALUES' + EXPORTING +* NO_VALUE_CHECK = space + popup_title = 'Excel creation options'(008) +* START_COLUMN = '5' +* START_ROW = '5' + IMPORTING + returncode = l_returncode + TABLES + fields = lt_sval + EXCEPTIONS + error_in_fields = 1 + OTHERS = 2 + . + IF sy-subrc <> 0. +* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO +* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. + ELSE. + IF l_returncode = 'A'. + RAISE EXCEPTION TYPE zcx_excel. + ELSE. + LOOP AT lt_sval INTO ls_sval. + ASSIGN COMPONENT ls_sval-fieldname OF STRUCTURE ws_option TO <fs>. + IF sy-subrc = 0. + <fs> = ls_sval-value. + ENDIF. + ENDLOOP. + set_option( is_option = ws_option ) . + rs_option = ws_option. + ENDIF. + ENDIF. + endmethod. + + + + + method BIND_CELLS. + +* Do we need subtotals with grouping + READ TABLE wt_fieldcatalog TRANSPORTING NO FIELDS WITH KEY is_subtotalled = abap_true. + IF sy-subrc = 0 . + r_freeze_col = loop_subtotal( i_row_int = w_row_int + i_col_int = w_col_int ) . + ELSE. + r_freeze_col = loop_normal( i_row_int = w_row_int + i_col_int = w_col_int ) . + ENDIF. + + endmethod. + + + + + + method BIND_TABLE. + data: lt_field_catalog type zexcel_t_fieldcatalog, + ls_field_catalog type zexcel_s_fieldcatalog, + ls_fcat type zexcel_s_converter_fcat, + lo_col_dim type ref to zcl_excel_worksheet_columndime, + lo_row_dim type ref to zcl_excel_worksheet_rowdimensi, + l_col_int type zexcel_cell_column, + l_col_alpha type zexcel_cell_column_alpha, + ls_settings type zexcel_s_table_settings, + l_line type i. + + field-symbols: <fs_tab> type any table. + + assign wo_data->* to <fs_tab> . + + ls_settings-table_style = i_style_table. + ls_settings-top_left_column = zcl_excel_common=>convert_column2alpha( ip_column = w_col_int ). + ls_settings-top_left_row = w_row_int. + ls_settings-show_row_stripes = ws_layout-is_stripped. + + describe table wt_fieldcatalog lines l_line. + l_line = l_line + 1 + w_col_int. + ls_settings-bottom_right_column = zcl_excel_common=>convert_column2alpha( ip_column = l_line ). + + describe table <fs_tab> lines l_line. + ls_settings-bottom_right_row = l_line + 1 + w_row_int. + sort wt_fieldcatalog by position. + loop at wt_fieldcatalog into ls_fcat. + move-corresponding ls_fcat to ls_field_catalog. + ls_field_catalog-dynpfld = abap_true. + insert ls_field_catalog into table lt_field_catalog. + endloop. + + wo_worksheet->bind_table( + exporting + ip_table = <fs_tab> + it_field_catalog = lt_field_catalog + is_table_settings = ls_settings + importing + es_table_settings = ls_settings + ). + loop at wt_fieldcatalog into ls_fcat. + l_col_int = w_col_int + ls_fcat-position - 1. + l_col_alpha = zcl_excel_common=>convert_column2alpha( l_col_int ). +* Freeze panes + if ls_fcat-fix_column = abap_true. + add 1 to r_freeze_col. + endif. +* Now let's check for optimized + if ls_fcat-is_optimized = abap_true. + lo_col_dim = wo_worksheet->get_column_dimension( ip_column = l_col_alpha ). + lo_col_dim->set_auto_size( ip_auto_size = abap_true ) . + endif. +* Now let's check for visible + if ls_fcat-is_hidden = abap_true. + lo_col_dim = wo_worksheet->get_column_dimension( ip_column = l_col_alpha ). + lo_col_dim->set_visible( ip_visible = abap_false ) . + endif. + endloop. + + endmethod. + + + method CLASS_CONSTRUCTOR. + DATA: ls_objects TYPE ts_alv_types. + DATA: ls_option TYPE zexcel_s_converter_option, + l_uname TYPE sy-uname. + + GET PARAMETER ID 'ZUS' FIELD l_uname. + IF l_uname IS INITIAL OR l_uname = space. + l_uname = sy-uname. + ENDIF. + +* Object CL_GUI_ALV_GRID + ls_objects-seoclass = 'CL_GUI_ALV_GRID'. + ls_objects-clsname = 'ZCL_EXCEL_CONVERTER_ALV_GRID'. + INSERT ls_objects INTO TABLE wt_objects. + +* Object CL_SALV_TABLE + ls_objects-seoclass = 'CL_SALV_TABLE'. + ls_objects-clsname = 'ZCL_EXCEL_CONVERTER_SALV_TABLE'. + INSERT ls_objects INTO TABLE wt_objects. + +* Object CL_SALV_RESULT + ls_objects-seoclass = 'CL_SALV_EX_RESULT_DATA_TABLE '. + ls_objects-clsname = 'ZCL_EXCEL_CONVERTER_RESULT_EX'. + INSERT ls_objects INTO TABLE wt_objects. +* Object CL_SALV_WD_RESULT + ls_objects-seoclass = 'CL_SALV_WD_RESULT_DATA_TABLE '. + ls_objects-clsname = 'ZCL_EXCEL_CONVERTER_RESULT_WD'. + INSERT ls_objects INTO TABLE wt_objects. + + CONCATENATE 'EXCEL_' sy-uname INTO ws_indx-srtfd. + + IMPORT p1 = ls_option FROM DATABASE indx(xl) TO ws_indx ID ws_indx-srtfd. + + IF sy-subrc = 0. + ws_option = ls_option. + ELSE. + init_option( ) . + ENDIF. + + endmethod. + + + method CLEAN_FIELDCATALOG. + DATA: l_position TYPE int1. + + FIELD-SYMBOLS: <fs_sfcat> TYPE zexcel_s_converter_fcat. + + SORT wt_fieldcatalog BY position col_id. + + CLEAR l_position. + LOOP AT wt_fieldcatalog ASSIGNING <fs_sfcat>. + ADD 1 TO l_position. + <fs_sfcat>-position = l_position. +* Default stype with alignment and format + <fs_sfcat>-style_hdr = get_style( i_type = c_type_hdr + i_alignment = <fs_sfcat>-alignment ). + IF ws_layout-is_stripped = abap_true. + <fs_sfcat>-style_stripped = get_style( i_type = c_type_str + i_alignment = <fs_sfcat>-alignment + i_inttype = <fs_sfcat>-inttype + i_decimals = <fs_sfcat>-decimals ). + ENDIF. + <fs_sfcat>-style_normal = get_style( i_type = c_type_nor + i_alignment = <fs_sfcat>-alignment + i_inttype = <fs_sfcat>-inttype + i_decimals = <fs_sfcat>-decimals ). + <fs_sfcat>-style_subtotal = get_style( i_type = c_type_sub + i_alignment = <fs_sfcat>-alignment + i_inttype = <fs_sfcat>-inttype + i_decimals = <fs_sfcat>-decimals ). + <fs_sfcat>-style_total = get_style( i_type = c_type_tot + i_alignment = <fs_sfcat>-alignment + i_inttype = <fs_sfcat>-inttype + i_decimals = <fs_sfcat>-decimals ). + ENDLOOP. + + endmethod. + + + + + + + + + + + + + method CONVERT. + + IF is_option IS SUPPLIED. + ws_option = is_option. + ENDIF. + + TRY. + execute_converter( EXPORTING io_object = io_alv + it_table = it_table ) . + ENDTRY. + + IF io_worksheet IS SUPPLIED AND io_worksheet IS BOUND. + wo_worksheet = io_worksheet. + ENDIF. + IF co_excel IS SUPPLIED. + IF co_excel IS NOT BOUND. + CREATE OBJECT co_excel. + co_excel->zif_excel_book_properties~creator = sy-uname. + ENDIF. + wo_excel = co_excel. + ENDIF. + +* Move table to data object and clean it up + IF wt_fieldcatalog IS NOT INITIAL. + create_table( ). + ELSE. + wo_data = wo_table . + ENDIF. + + IF wo_excel IS NOT BOUND. + CREATE OBJECT wo_excel. + wo_excel->zif_excel_book_properties~creator = sy-uname. + ENDIF. + IF wo_worksheet IS NOT BOUND. + " Get active sheet + wo_worksheet = wo_excel->get_active_worksheet( ). + wo_worksheet->set_title( ip_title = 'Sheet1'(001) ). + ENDIF. + + IF i_row_int <= 0. + w_row_int = 1. + ELSE. + w_row_int = i_row_int. + ENDIF. + IF i_column_int <= 0. + w_col_int = 1. + ELSE. + w_col_int = i_column_int. + ENDIF. + + create_worksheet( i_table = i_table + i_style_table = i_style_table ) . + + endmethod. + + + + + + method CREATE_COLOR_STYLE. + DATA: ls_styles TYPE ts_styles. + DATA: lo_style TYPE REF TO zcl_excel_style. + + READ TABLE wt_styles INTO ls_styles WITH KEY guid = i_style. + IF sy-subrc = 0. + lo_style = wo_excel->add_new_style( ). +* lo_style->borders = ls_styles-style->borders. +* lo_style->protection = ls_styles-style->protection. + lo_style->font->bold = ls_styles-style->font->bold. + lo_style->alignment->horizontal = ls_styles-style->alignment->horizontal. + lo_style->number_format->format_code = ls_styles-style->number_format->format_code. + + lo_style->font->color-rgb = is_colors-fontcolor. + lo_style->fill->filltype = zcl_excel_style_fill=>c_fill_solid. + lo_style->fill->fgcolor-rgb = is_colors-fillcolor. + + ro_style = lo_style. + ENDIF. + endmethod. + + + + + + + + method CREATE_FORMULAR_SUBTOTAL. + data: l_row_alpha_start type string, + l_row_alpha_end type string, + l_func_num type string. + + l_row_alpha_start = i_row_int_start. + l_row_alpha_end = i_row_int_end. + + l_func_num = get_function_number( i_totals_function = i_totals_function ). + concatenate 'SUBTOTAL(' l_func_num ',' i_column l_row_alpha_start ':' i_column l_row_alpha_end ')' into r_formula. + endmethod. + + + + + + + method CREATE_FORMULAR_TOTAL. + data: l_row_alpha type string, + l_row_e_alpha type string. + + l_row_alpha = w_row_int + 1. + l_row_e_alpha = i_row_int. + + concatenate i_totals_function '(' i_column l_row_alpha ':' i_column l_row_e_alpha ')' into r_formula. + endmethod. + + + + method CREATE_PATH. + DATA: l_sep TYPE c , + l_path TYPE string, + l_return TYPE i . + + CLEAR r_path. + + " Save the file + cl_gui_frontend_services=>get_sapgui_workdir( + CHANGING + sapworkdir = l_path + EXCEPTIONS + get_sapworkdir_failed = 1 + cntl_error = 2 + error_no_gui = 3 + not_supported_by_gui = 4 + ). + IF sy-subrc <> 0. +* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO +* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. + CONCATENATE 'Excel_' w_fcount '.xlsx' INTO r_path. + ELSE. + DO. + ADD 1 TO w_fcount. +*-obtain file separator character--------------------------------------- + CALL METHOD cl_gui_frontend_services=>get_file_separator + CHANGING + file_separator = l_sep + EXCEPTIONS + cntl_error = 1 + error_no_gui = 2 + not_supported_by_gui = 3 + OTHERS = 4. + + IF sy-subrc <> 0. + l_sep = ''. + ENDIF. + + CONCATENATE l_path l_sep 'Excel_' w_fcount '.xlsx' INTO r_path. + + IF cl_gui_frontend_services=>file_exist( file = r_path ) = abap_true. + cl_gui_frontend_services=>file_delete( EXPORTING filename = r_path + CHANGING rc = l_return + EXCEPTIONS OTHERS = 1 ). + IF sy-subrc = 0 . + RETURN. + ENDIF. + ELSE. + RETURN. + ENDIF. + ENDDO. + ENDIF. + + endmethod. + + + + + method CREATE_STYLE_HDR. + data: lo_style type ref to zcl_excel_style. + + lo_style = wo_excel->add_new_style( ). + lo_style->font->bold = abap_true. + lo_style->font->color-rgb = zcl_excel_style_color=>c_white. + lo_style->fill->filltype = zcl_excel_style_fill=>c_fill_solid. + lo_style->fill->fgcolor-rgb = 'FF4F81BD'. + if i_alignment is supplied and i_alignment is not initial. + lo_style->alignment->horizontal = i_alignment. + endif. + ro_style = lo_style . + endmethod. + + + + + + + method CREATE_STYLE_NORMAL. + DATA: lo_style TYPE REF TO zcl_excel_style, + l_format TYPE zexcel_number_format. + + IF i_inttype IS SUPPLIED AND i_inttype IS NOT INITIAL. + l_format = set_cell_format( i_inttype = i_inttype + i_decimals = i_decimals ) . + ENDIF. + IF l_format IS NOT INITIAL OR + ( i_alignment IS SUPPLIED AND i_alignment IS NOT INITIAL ) . + + lo_style = wo_excel->add_new_style( ). + + IF i_alignment IS SUPPLIED AND i_alignment IS NOT INITIAL. + lo_style->alignment->horizontal = i_alignment. + ENDIF. + + IF l_format IS NOT INITIAL. + lo_style->number_format->format_code = l_format. + ENDIF. + + ro_style = lo_style . + + ENDIF. + endmethod. + + + + + + + method CREATE_STYLE_STRIPPED. + data: lo_style type ref to zcl_excel_style. + data: l_format type zexcel_number_format. + + lo_style = wo_excel->add_new_style( ). + lo_style->fill->filltype = zcl_excel_style_fill=>c_fill_solid. + lo_style->fill->fgcolor-rgb = 'FFDBE5F1'. + if i_alignment is supplied and i_alignment is not initial. + lo_style->alignment->horizontal = i_alignment. + endif. + if i_inttype is supplied and i_inttype is not initial. + l_format = set_cell_format( i_inttype = i_inttype + i_decimals = i_decimals ) . + if l_format is not initial. + lo_style->number_format->format_code = l_format. + endif. + endif. + ro_style = lo_style. + + endmethod. + + + + + + + method CREATE_STYLE_SUBTOTAL. + data: lo_style type ref to zcl_excel_style. + data: l_format type zexcel_number_format. + + lo_style = wo_excel->add_new_style( ). + lo_style->font->bold = abap_true. + + if i_alignment is supplied and i_alignment is not initial. + lo_style->alignment->horizontal = i_alignment. + endif. + if i_inttype is supplied and i_inttype is not initial. + l_format = set_cell_format( i_inttype = i_inttype + i_decimals = i_decimals ) . + if l_format is not initial. + lo_style->number_format->format_code = l_format. + endif. + endif. + + ro_style = lo_style . + + endmethod. + + + + + + + method CREATE_STYLE_TOTAL. + DATA: lo_style TYPE REF TO zcl_excel_style. + DATA: l_format TYPE zexcel_number_format. + + lo_style = wo_excel->add_new_style( ). + lo_style->font->bold = abap_true. + + CREATE OBJECT lo_style->borders->top. + lo_style->borders->top->border_style = zcl_excel_style_border=>c_border_thin. + lo_style->borders->top->border_color-rgb = zcl_excel_style_color=>c_black. + + CREATE OBJECT lo_style->borders->right. + lo_style->borders->right->border_style = zcl_excel_style_border=>c_border_none. + lo_style->borders->right->border_color-rgb = zcl_excel_style_color=>c_black. + + CREATE OBJECT lo_style->borders->down. + lo_style->borders->down->border_style = zcl_excel_style_border=>c_border_double. + lo_style->borders->down->border_color-rgb = zcl_excel_style_color=>c_black. + + CREATE OBJECT lo_style->borders->left. + lo_style->borders->left->border_style = zcl_excel_style_border=>c_border_none. + lo_style->borders->left->border_color-rgb = zcl_excel_style_color=>c_black. + + IF i_alignment IS SUPPLIED AND i_alignment IS NOT INITIAL. + lo_style->alignment->horizontal = i_alignment. + ENDIF. + IF i_inttype IS SUPPLIED AND i_inttype IS NOT INITIAL. + l_format = set_cell_format( i_inttype = i_inttype + i_decimals = i_decimals ) . + IF l_format IS NOT INITIAL. + lo_style->number_format->format_code = l_format. + ENDIF. + ENDIF. + + ro_style = lo_style . + + endmethod. + + + method CREATE_TABLE. + TYPES: BEGIN OF ts_output, + fieldname TYPE fieldname, + function TYPE funcname, + END OF ts_output. + + DATA: lo_data TYPE REF TO data. + DATA: lo_addit TYPE REF TO cl_abap_elemdescr, + lt_components_tab TYPE cl_abap_structdescr=>component_table, + ls_components TYPE abap_componentdescr, + lo_table TYPE REF TO cl_abap_tabledescr, + lo_struc TYPE REF TO cl_abap_structdescr, + lt_fieldcatalog TYPE zexcel_t_converter_fcat. + + FIELD-SYMBOLS: <fs_scat> TYPE zexcel_s_converter_fcat, + <fs_stab> TYPE ANY, + <fs_ttab> TYPE STANDARD TABLE, + <fs> TYPE ANY, + <fs_table> TYPE STANDARD TABLE. + + SORT wt_fieldcatalog BY position. + ASSIGN wo_table->* TO <fs_table>. + + READ TABLE <fs_table> ASSIGNING <fs_stab> INDEX 1. + IF sy-subrc EQ 0 . + LOOP AT wt_fieldcatalog ASSIGNING <fs_scat>. + ASSIGN COMPONENT <fs_scat>-columnname OF STRUCTURE <fs_stab> TO <fs>. + IF sy-subrc = 0. + ls_components-name = <fs_scat>-columnname. + TRY. + lo_addit ?= cl_abap_typedescr=>describe_by_data( <fs> ). + CATCH cx_sy_move_cast_error. + CLEAR lo_addit. + DELETE TABLE wt_fieldcatalog FROM <fs_scat>. + ENDTRY. + IF lo_addit IS BOUND. + ls_components-type = lo_addit . + INSERT ls_components INTO TABLE lt_components_tab. + ENDIF. + ENDIF. + ENDLOOP. + IF lt_components_tab IS NOT INITIAL. + "create new line type + TRY. + lo_struc = cl_abap_structdescr=>create( P_COMPONENTS = lt_components_tab + P_STRICT = abap_false ). + CATCH cx_sy_struct_creation. + RETURN. " We can not do anything in this case. + ENDTRY. + + lo_table = cl_abap_tabledescr=>create( lo_struc ). + + CREATE DATA wo_data TYPE HANDLE lo_table. + CREATE DATA lo_data TYPE HANDLE lo_struc. + + ASSIGN wo_data->* TO <fs_ttab>. + ASSIGN lo_data->* TO <fs_stab>. + LOOP AT <fs_table> ASSIGNING <fs>. + CLEAR <fs_stab>. + MOVE-CORRESPONDING <fs> TO <fs_stab>. + APPEND <fs_stab> TO <fs_ttab>. + ENDLOOP. + ENDIF. + ENDIF. + + endmethod. + + + + + + method CREATE_TEXT_SUBTOTAL. + DATA: l_string(256) TYPE c, + l_func TYPE string. + + CASE i_totals_function. + WHEN zcl_excel_table=>totals_function_sum. " Total + l_func = 'Total'(003). + WHEN zcl_excel_table=>totals_function_min. " Minimum + l_func = 'Minimum'(004). + WHEN zcl_excel_table=>totals_function_max. " Maximum + l_func = 'Maximum'(005). + WHEN zcl_excel_table=>totals_function_average. " Mean Value + l_func = 'Average'(006). + WHEN zcl_excel_table=>totals_function_count. " Count + l_func = 'Count'(007). + WHEN OTHERS. + CLEAR l_func. + ENDCASE. + + WRITE i_value TO l_string. + + CONCATENATE l_string l_func INTO r_text SEPARATED BY space. + + endmethod. + + + + + + method CREATE_WORKSHEET. + DATA: l_freeze_col TYPE i. + DATA: l_guid TYPE oltpguid16. + + IF wo_data IS BOUND AND wo_worksheet IS BOUND. + + wo_worksheet->zif_excel_sheet_properties~summarybelow = zif_excel_sheet_properties=>c_below_on. " By default is on + + IF wt_fieldcatalog IS INITIAL. + set_fieldcatalog( ) . + ELSE. + clean_fieldcatalog( ) . + ENDIF. + + IF i_table = abap_true. + l_freeze_col = bind_table( i_style_table = i_style_table ) . + ELSE. +* Let's check for filter. + IF wt_filter IS NOT INITIAL. + wo_autofilter = wo_excel->add_new_autofilter( io_sheet = wo_worksheet ). + l_freeze_col = bind_cells( ) . + set_autofilter_area( ) . + ELSE. + l_freeze_col = bind_cells( ) . + ENDIF. + + ENDIF. + +* Check for freeze panes + IF ws_layout-is_fixed = abap_true. + IF l_freeze_col = 0. + l_freeze_col = w_col_int. + ENDIF. + wo_worksheet->freeze_panes( EXPORTING ip_num_columns = l_freeze_col + ip_num_rows = w_row_int ) . + ENDIF. + ENDIF. + + endmethod. + + + + + + method EXECUTE_CONVERTER. + DATA: lt_fieldcatalog TYPE zexcel_t_fieldcatalog, + ls_fieldcatalog TYPE zexcel_s_converter_fcat, + lo_if TYPE REF TO zif_excel_converter, + ls_types TYPE ts_alv_types, + lo_addit TYPE REF TO cl_abap_classdescr. + + IF io_object IS BOUND. + TRY. + lo_addit ?= cl_abap_typedescr=>describe_by_object_ref( io_object ). + CATCH cx_sy_move_cast_error. + RAISE EXCEPTION TYPE zcx_excel. + ENDTRY. + ls_types-seoclass = lo_addit->get_relative_name( ). + READ TABLE wt_objects INTO ls_types WITH TABLE KEY seoclass = ls_types-seoclass. + IF sy-subrc = 0. + CREATE OBJECT lo_if TYPE (ls_types-clsname). + + TRY. + lo_if->create_fieldcatalog( + EXPORTING + is_option = ws_option + io_object = io_object + it_table = it_table + IMPORTING + es_layout = ws_layout + et_fieldcatalog = wt_fieldcatalog + eo_table = wo_table + et_colors = wt_colors + et_filter = wt_filter + ). + ENDTRY. +* data lines of highest level. + IF ws_layout-max_subtotal_level > 0. + ADD 1 TO ws_layout-max_subtotal_level. + ENDIF. + ELSE. + RAISE EXCEPTION TYPE zcx_excel. + ENDIF. + ELSE. + REFRESH wt_fieldcatalog. + GET REFERENCE OF it_table INTO wo_table. + ENDIF. + + endmethod. + + + + + + + method GET_COLOR_STYLE. + DATA: ls_colors TYPE zexcel_s_converter_col, + ls_color_styles TYPE ts_color_styles, + lo_style TYPE REF TO zcl_excel_style. + + r_style = i_style. " Default we change nothing + + IF wt_colors IS NOT INITIAL. +* Full line has color + READ TABLE wt_colors INTO ls_colors WITH KEY rownumber = i_row + columnname = space. + IF sy-subrc = 0. + READ TABLE wt_color_styles INTO ls_color_styles WITH KEY guid_old = i_style + fontcolor = ls_colors-fontcolor + fillcolor = ls_colors-fillcolor. + IF sy-subrc = 0. + r_style = ls_color_styles-style_new->get_guid( ). + ELSE. + lo_style = create_color_style( i_style = i_style + is_colors = ls_colors ) . + r_style = lo_style->get_guid( ) . + ls_color_styles-guid_old = i_style. + ls_color_styles-fontcolor = ls_colors-fontcolor. + ls_color_styles-fillcolor = ls_colors-fillcolor. + ls_color_styles-style_new = lo_style. + INSERT ls_color_styles INTO TABLE wt_color_styles. + ENDIF. + ELSE. +* Only field has color + READ TABLE wt_colors INTO ls_colors WITH KEY rownumber = i_row + columnname = i_fieldname. + IF sy-subrc = 0. + READ TABLE wt_color_styles INTO ls_color_styles WITH KEY guid_old = i_style + fontcolor = ls_colors-fontcolor + fillcolor = ls_colors-fillcolor. + IF sy-subrc = 0. + r_style = ls_color_styles-style_new->get_guid( ). + ELSE. + lo_style = create_color_style( i_style = i_style + is_colors = ls_colors ) . + ls_color_styles-guid_old = i_style. + ls_color_styles-fontcolor = ls_colors-fontcolor. + ls_color_styles-fillcolor = ls_colors-fillcolor. + ls_color_styles-style_new = lo_style. + INSERT ls_color_styles INTO TABLE wt_color_styles. + r_style = ls_color_styles-style_new->get_guid( ). + ENDIF. + ELSE. + r_style = i_style. + ENDIF. + ENDIF. + ELSE. + r_style = i_style. + ENDIF. + + endmethod. + + + + + + method GET_FILE. + data: lo_excel_writer type ref to zif_excel_writer, + lo_excel type ref to zcl_excel. + + data: ls_seoclass type seoclass. + + + if wo_excel is bound. + create object lo_excel_writer type zcl_excel_writer_2007. + e_file = lo_excel_writer->write_file( wo_excel ). + + select single * into ls_seoclass + from seoclass + where clsname = 'CL_BCS_CONVERT'. + + if sy-subrc = 0. + call method (ls_seoclass-clsname)=>xstring_to_solix + exporting + iv_xstring = e_file + receiving + et_solix = et_file. + e_bytecount = xstrlen( e_file ). + else. + " Convert to binary + call function 'SCMS_XSTRING_TO_BINARY' + exporting + buffer = e_file + importing + output_length = e_bytecount + tables + binary_tab = et_file. + endif. + endif. + + endmethod. + + + + + method GET_FUNCTION_NUMBER. +*Number Function +*1 AVERAGE +*2 COUNT +*3 COUNTA +*4 MAX +*5 MIN +*6 PRODUCT +*7 STDEV +*8 STDEVP +*9 SUM +*10 VAR +*11 VARP + + case i_totals_function. + when ZCL_EXCEL_TABLE=>TOTALS_FUNCTION_SUM. " Total + r_function_number = 9. + when ZCL_EXCEL_TABLE=>TOTALS_FUNCTION_MIN. " Minimum + r_function_number = 5. + when ZCL_EXCEL_TABLE=>TOTALS_FUNCTION_MAX. " Maximum + r_function_number = 4. + when ZCL_EXCEL_TABLE=>TOTALS_FUNCTION_AVERAGE. " Mean Value + r_function_number = 1. + when ZCL_EXCEL_TABLE=>TOTALS_FUNCTION_count. " Count + r_function_number = 2. + when others. + clear r_function_number. + endcase. + endmethod. + + + + method GET_OPTION. + + rs_option = ws_option. + + endmethod. + + + + + + + + method GET_STYLE. + DATA: ls_styles TYPE ts_styles, + lo_style TYPE REF TO zcl_excel_style. + + CLEAR r_style. + + READ TABLE wt_styles INTO ls_styles WITH TABLE KEY type = i_type + alignment = i_alignment + inttype = i_inttype + decimals = i_decimals. + IF sy-subrc = 0. + r_style = ls_styles-guid. + ELSE. + CASE i_type. + WHEN c_type_hdr. " Header + lo_style = create_style_hdr( i_alignment = i_alignment ). + WHEN c_type_str. "Stripped + lo_style = create_style_stripped( i_alignment = i_alignment + i_inttype = i_inttype + i_decimals = i_decimals ). + WHEN c_type_nor. "Normal + lo_style = create_style_normal( i_alignment = i_alignment + i_inttype = i_inttype + i_decimals = i_decimals ). + WHEN c_type_sub. "Subtotals + lo_style = create_style_subtotal( i_alignment = i_alignment + i_inttype = i_inttype + i_decimals = i_decimals ). + WHEN c_type_tot. "Totals + lo_style = create_style_total( i_alignment = i_alignment + i_inttype = i_inttype + i_decimals = i_decimals ). + ENDCASE. + IF lo_style IS NOT INITIAL. + r_style = lo_style->get_guid( ). + ls_styles-type = i_type. + ls_styles-alignment = i_alignment. + ls_styles-inttype = i_inttype. + ls_styles-decimals = i_decimals. + ls_styles-guid = r_style. + ls_styles-style = lo_style. + INSERT ls_styles INTO TABLE wt_styles. + ENDIF. + ENDIF. + endmethod. + + + method INIT_OPTION. + + ws_option-filter = abap_true. + ws_option-hidenc = abap_true. + ws_option-subtot = abap_true. + + endmethod. + + + + + + + method LOOP_NORMAL. + DATA: lo_data TYPE REF TO data, + l_row_header TYPE zexcel_cell_row VALUE '2', + l_col_header TYPE zexcel_cell_column_alpha VALUE 'B', + l_row_int_start TYPE zexcel_cell_row, + l_row_int_end TYPE zexcel_cell_row, + l_row_int TYPE zexcel_cell_row, + l_col_int TYPE zexcel_cell_column, + l_col_alpha TYPE zexcel_cell_column_alpha, + l_col_alpha_start TYPE zexcel_cell_column_alpha, + l_cell_value TYPE zexcel_cell_value, + l_s_color TYPE abap_bool, + lo_col_dim TYPE REF TO zcl_excel_worksheet_columndime, + lo_row_dim TYPE REF TO zcl_excel_worksheet_rowdimensi, + l_formula TYPE zexcel_cell_formula, + l_style TYPE zexcel_cell_style, + l_cells TYPE i, + l_count TYPE i, + l_table_row TYPE i. + + FIELD-SYMBOLS: <fs_stab> TYPE ANY, + <fs_tab> TYPE STANDARD TABLE, + <fs_sfcat> TYPE zexcel_s_converter_fcat, + <fs_fldval> TYPE ANY, + <fs_cell_value> TYPE zexcel_cell_value. + + ASSIGN wo_data->* TO <fs_tab> . + + DESCRIBE TABLE wt_fieldcatalog LINES l_cells. + DESCRIBE TABLE <fs_tab> LINES l_count. + l_cells = l_cells * l_count. + +* It is better to loop column by column + LOOP AT wt_fieldcatalog ASSIGNING <fs_sfcat>. + l_row_int = i_row_int. + l_col_int = i_col_int + <fs_sfcat>-position - 1. + +* Freeze panes + IF <fs_sfcat>-fix_column = abap_true. + ADD 1 TO r_freeze_col. + ENDIF. + l_s_color = abap_true. + + l_col_alpha = zcl_excel_common=>convert_column2alpha( l_col_int ). + +* Only if the Header is required create it. + IF ws_option-hidehd IS INITIAL. + " First of all write column header + l_cell_value = <fs_sfcat>-scrtext_m. + wo_worksheet->set_cell( ip_column = l_col_alpha + ip_row = l_row_int + ip_value = l_cell_value + ip_style = <fs_sfcat>-style_hdr ). + ADD 1 TO l_row_int. + ENDIF. + LOOP AT <fs_tab> ASSIGNING <fs_stab>. + l_table_row = sy-tabix. +* Now the cell values + ASSIGN COMPONENT <fs_sfcat>-columnname OF STRUCTURE <fs_stab> TO <fs_fldval>. +* Now let's write the cell values + IF ws_layout-is_stripped = abap_true AND l_s_color = abap_true. + l_style = get_color_style( i_row = l_table_row + i_fieldname = <fs_sfcat>-columnname + i_style = <fs_sfcat>-style_stripped ). + wo_worksheet->set_cell( ip_column = l_col_alpha + ip_row = l_row_int + ip_value = <fs_fldval> + ip_style = l_style ). + CLEAR l_s_color. + ELSE. + l_style = get_color_style( i_row = l_table_row + i_fieldname = <fs_sfcat>-columnname + i_style = <fs_sfcat>-style_normal ). + wo_worksheet->set_cell( ip_column = l_col_alpha + ip_row = l_row_int + ip_value = <fs_fldval> + ip_style = l_style ). + l_s_color = abap_true. + ENDIF. + READ TABLE wt_filter TRANSPORTING NO FIELDS WITH TABLE KEY rownumber = l_table_row + columnname = <fs_sfcat>-columnname. + IF sy-subrc = 0. + wo_worksheet->get_cell( EXPORTING + ip_column = l_col_alpha + ip_row = l_row_int + IMPORTING + ep_value = l_cell_value ). + wo_autofilter->set_value( i_column = l_col_int + i_value = l_cell_value ). + ENDIF. + ADD 1 TO l_row_int. + ENDLOOP. +* Now let's check for optimized + IF <fs_sfcat>-is_optimized = abap_true . + lo_col_dim = wo_worksheet->get_column_dimension( ip_column = l_col_alpha ). + lo_col_dim->set_auto_size( ip_auto_size = abap_true ) . + ENDIF. +* Now let's check for visible + IF <fs_sfcat>-is_hidden = abap_true. + lo_col_dim = wo_worksheet->get_column_dimension( ip_column = l_col_alpha ). + lo_col_dim->set_visible( ip_visible = abap_false ) . + ENDIF. +* Now let's check for total versus subtotal. + IF <fs_sfcat>-totals_function IS NOT INITIAL. + l_row_int_end = l_row_int - 1. + + l_formula = create_formular_total( i_row_int = l_row_int_end + i_column = l_col_alpha + i_totals_function = <fs_sfcat>-totals_function ). + wo_worksheet->set_cell( ip_column = l_col_alpha + ip_row = l_row_int + ip_formula = l_formula + ip_style = <fs_sfcat>-style_total ). + ENDIF. + ENDLOOP. + endmethod. + + + + + + + method LOOP_SUBTOTAL. + + DATA: lo_data TYPE REF TO data, + l_row_header TYPE zexcel_cell_row VALUE '2', + l_col_header TYPE zexcel_cell_column_alpha VALUE 'B', + l_row_int_start TYPE zexcel_cell_row, + l_row_int_end TYPE zexcel_cell_row, + l_row_int TYPE zexcel_cell_row, + l_col_int TYPE zexcel_cell_column, + l_col_alpha TYPE zexcel_cell_column_alpha, + l_col_alpha_start TYPE zexcel_cell_column_alpha, + l_cell_value TYPE zexcel_cell_value, + l_s_color TYPE abap_bool, + lo_col_dim TYPE REF TO zcl_excel_worksheet_columndime, + lo_row_dim TYPE REF TO zcl_excel_worksheet_rowdimensi, + l_formula TYPE zexcel_cell_formula, + l_style TYPE zexcel_cell_style, + l_subtotalled TYPE flag, + l_text TYPE string, + ls_sort_values TYPE ts_sort_values, + ls_subtotal_rows TYPE ts_subtotal_rows, + l_sort_level TYPE int4, + l_hidden TYPE int4, + l_line TYPE i, + l_guid TYPE guid_22, + l_tabix TYPE sy-tabix, + l_cells TYPE i, + l_count TYPE i, + l_table_row TYPE i, + lt_fcat TYPE zexcel_t_converter_fcat. + + FIELD-SYMBOLS: <fs_stab> TYPE ANY, + <fs_tab> TYPE STANDARD TABLE, + <fs_sfcat> TYPE zexcel_s_converter_fcat, + <fs_fldval> TYPE ANY, + <fs_sortval> TYPE ANY, + <fs_sortv> TYPE ts_sort_values, + <fs_cell_value> TYPE zexcel_cell_value. + + ASSIGN wo_data->* TO <fs_tab> . + + REFRESH: wt_sort_values, + wt_subtotal_rows. + + DESCRIBE TABLE wt_fieldcatalog LINES l_cells. + DESCRIBE TABLE <fs_tab> LINES l_count. + l_cells = l_cells * l_count. + + READ TABLE <fs_tab> ASSIGNING <fs_stab> INDEX 1. + IF sy-subrc = 0. + l_row_int = i_row_int + 1. + lt_fcat = wt_fieldcatalog. + SORT lt_fcat BY sort_level DESCENDING. + LOOP AT lt_fcat ASSIGNING <fs_sfcat> WHERE is_subtotalled = abap_true. + ASSIGN COMPONENT <fs_sfcat>-columnname OF STRUCTURE <fs_stab> TO <fs_fldval>. + ls_sort_values-fieldname = <fs_sfcat>-columnname. + ls_sort_values-row_int = l_row_int. + ls_sort_values-sort_level = <fs_sfcat>-sort_level. + ls_sort_values-is_collapsed = <fs_sfcat>-is_collapsed. + CREATE DATA ls_sort_values-value LIKE <fs_fldval>. + ASSIGN ls_sort_values-value->* TO <fs_sortval>. + <fs_sortval> = <fs_fldval>. + INSERT ls_sort_values INTO TABLE wt_sort_values. + ENDLOOP. + ENDIF. + l_row_int = i_row_int. +* Let's check if we need to hide a sort level. + DESCRIBE TABLE wt_sort_values LINES l_line. + IF l_line <= 1. + CLEAR l_hidden. + ELSE. + LOOP AT wt_sort_values INTO ls_sort_values WHERE is_collapsed = abap_false. + IF l_hidden < ls_sort_values-sort_level. + l_hidden = ls_sort_values-sort_level. + ENDIF. + ENDLOOP. + ENDIF. + ADD 1 TO l_hidden. " As this is the first level we show. +* First loop without formular only addtional rows with subtotal text. + LOOP AT <fs_tab> ASSIGNING <fs_stab>. + ADD 1 TO l_row_int. " 1 is for header row. + l_row_int_start = l_row_int. + SORT lt_fcat BY sort_level DESCENDING. + LOOP AT lt_fcat ASSIGNING <fs_sfcat> WHERE is_subtotalled = abap_true. + l_col_int = i_col_int + <fs_sfcat>-position - 1. + l_col_alpha = zcl_excel_common=>convert_column2alpha( l_col_int ). +* Now the cell values + ASSIGN COMPONENT <fs_sfcat>-columnname OF STRUCTURE <fs_stab> TO <fs_fldval>. + IF sy-subrc = 0. + READ TABLE wt_sort_values ASSIGNING <fs_sortv> WITH TABLE KEY fieldname = <fs_sfcat>-columnname. + IF sy-subrc = 0. + ASSIGN <fs_sortv>-value->* TO <fs_sortval>. + IF <fs_sortval> <> <fs_fldval> OR <fs_sortv>-new = abap_true. +* First let's remmember the subtotal values as it has to appear later. + ls_subtotal_rows-row_int = l_row_int. + ls_subtotal_rows-row_int_start = <fs_sortv>-row_int. + ls_subtotal_rows-columnname = <fs_sfcat>-columnname. + INSERT ls_subtotal_rows INTO TABLE wt_subtotal_rows. +* Now let's write the subtotal line + l_cell_value = create_text_subtotal( i_value = <fs_sortval> + i_totals_function = <fs_sfcat>-totals_function ). + wo_worksheet->set_cell( ip_column = l_col_alpha + ip_row = l_row_int + ip_value = l_cell_value + ip_abap_type = cl_abap_typedescr=>typekind_string + ip_style = <fs_sfcat>-style_subtotal ). + lo_row_dim = wo_worksheet->get_row_dimension( ip_row = l_row_int ). + lo_row_dim->set_outline_level( ip_outline_level = <fs_sfcat>-sort_level ) . + IF <fs_sfcat>-is_collapsed = abap_true. + IF <fs_sfcat>-sort_level > l_hidden. + lo_row_dim->set_visible( ip_visible = abap_false ) . + ENDIF. + lo_row_dim->set_collapsed( ip_collapsed = <fs_sfcat>-is_collapsed ) . + ENDIF. +* Now let's change the key + ADD 1 TO l_row_int. + <fs_sortval> = <fs_fldval>. + <fs_sortv>-new = abap_false. + l_line = <fs_sortv>-sort_level. + LOOP AT wt_sort_values ASSIGNING <fs_sortv> WHERE sort_level >= l_line. + <fs_sortv>-row_int = l_row_int. + ENDLOOP. + ENDIF. + ENDIF. + ENDIF. + ENDLOOP. + ENDLOOP. + ADD 1 TO l_row_int. + l_row_int_start = l_row_int. + SORT lt_fcat BY sort_level DESCENDING. + LOOP AT lt_fcat ASSIGNING <fs_sfcat> WHERE is_subtotalled = abap_true. + l_col_int = i_col_int + <fs_sfcat>-position - 1. + l_col_alpha = zcl_excel_common=>convert_column2alpha( l_col_int ). + READ TABLE wt_sort_values ASSIGNING <fs_sortv> WITH TABLE KEY fieldname = <fs_sfcat>-columnname. + IF sy-subrc = 0. + ASSIGN <fs_sortv>-value->* TO <fs_sortval>. + ls_subtotal_rows-row_int = l_row_int. + ls_subtotal_rows-row_int_start = <fs_sortv>-row_int. + ls_subtotal_rows-columnname = <fs_sfcat>-columnname. + INSERT ls_subtotal_rows INTO TABLE wt_subtotal_rows. +* First let's write the value as it has to appear. + l_cell_value = create_text_subtotal( i_value = <fs_sortval> + i_totals_function = <fs_sfcat>-totals_function ). + wo_worksheet->set_cell( ip_column = l_col_alpha + ip_row = l_row_int + ip_value = l_cell_value + ip_abap_type = cl_abap_typedescr=>typekind_string + ip_style = <fs_sfcat>-style_subtotal ). + + l_sort_level = <fs_sfcat>-sort_level. + lo_row_dim = wo_worksheet->get_row_dimension( ip_row = l_row_int ). + lo_row_dim->set_outline_level( ip_outline_level = l_sort_level ) . + IF <fs_sfcat>-is_collapsed = abap_true. + IF <fs_sfcat>-sort_level > l_hidden. + lo_row_dim->set_visible( ip_visible = abap_false ) . + ENDIF. + lo_row_dim->set_collapsed( ip_collapsed = <fs_sfcat>-is_collapsed ) . + ENDIF. + ADD 1 TO l_row_int. + ENDIF. + ENDLOOP. +* Let's write the Grand total + l_sort_level = 0. + lo_row_dim = wo_worksheet->get_row_dimension( ip_row = l_row_int ). + lo_row_dim->set_outline_level( ip_outline_level = l_sort_level ) . +* lo_row_dim->set_collapsed( ip_collapsed = <fs_sfcat>-is_collapsed ) . Not on grand total + + l_text = create_text_subtotal( i_value = 'Grand'(002) + i_totals_function = <fs_sfcat>-totals_function ). + + l_col_alpha_start = zcl_excel_common=>convert_column2alpha( i_col_int ). + wo_worksheet->set_cell( ip_column = l_col_alpha_start + ip_row = l_row_int + ip_value = l_text + ip_abap_type = cl_abap_typedescr=>typekind_string + ip_style = <fs_sfcat>-style_subtotal ). + +* It is better to loop column by column second time around +* Second loop with formular and data. + LOOP AT wt_fieldcatalog ASSIGNING <fs_sfcat>. + l_row_int = i_row_int. + l_col_int = i_col_int + <fs_sfcat>-position - 1. +* Freeze panes + IF <fs_sfcat>-fix_column = abap_true. + ADD 1 TO r_freeze_col. + ENDIF. + l_s_color = abap_true. + l_col_alpha = zcl_excel_common=>convert_column2alpha( l_col_int ). + " First of all write column header + l_cell_value = <fs_sfcat>-scrtext_m. + wo_worksheet->set_cell( ip_column = l_col_alpha + ip_row = l_row_int + ip_value = l_cell_value + ip_abap_type = cl_abap_typedescr=>typekind_string + ip_style = <fs_sfcat>-style_hdr ). + ADD 1 TO l_row_int. + LOOP AT <fs_tab> ASSIGNING <fs_stab>. + l_table_row = sy-tabix. +* Now the cell values + ASSIGN COMPONENT <fs_sfcat>-columnname OF STRUCTURE <fs_stab> TO <fs_fldval>. +* Let's check for subtotal lines + DO. + READ TABLE wt_subtotal_rows TRANSPORTING NO FIELDS WITH TABLE KEY row_int = l_row_int. + IF sy-subrc = 0. + IF <fs_sfcat>-is_subtotalled = abap_false AND + <fs_sfcat>-totals_function IS NOT INITIAL. + DO. + READ TABLE wt_subtotal_rows INTO ls_subtotal_rows WITH TABLE KEY row_int = l_row_int. + IF sy-subrc = 0. + l_row_int_start = ls_subtotal_rows-row_int_start. + l_row_int_end = l_row_int - 1. + + l_formula = create_formular_subtotal( i_row_int_start = l_row_int_start + i_row_int_end = l_row_int_end + i_column = l_col_alpha + i_totals_function = <fs_sfcat>-totals_function ). + wo_worksheet->set_cell( ip_column = l_col_alpha + ip_row = l_row_int + ip_formula = l_formula + ip_style = <fs_sfcat>-style_subtotal ). + IF <fs_sfcat>-is_collapsed = abap_true. + lo_row_dim = wo_worksheet->get_row_dimension( ip_row = l_row_int ). + lo_row_dim->set_collapsed( ip_collapsed = <fs_sfcat>-is_collapsed ). + IF <fs_sfcat>-sort_level > l_hidden. + lo_row_dim->set_visible( ip_visible = abap_false ) . + ENDIF. + ENDIF. + ADD 1 TO l_row_int. + ELSE. + EXIT. + ENDIF. + ENDDO. + ELSE. + ADD 1 TO l_row_int. + ENDIF. + ELSE. + EXIT. + ENDIF. + ENDDO. +* Let's set the row dimension values + lo_row_dim = wo_worksheet->get_row_dimension( ip_row = l_row_int ). + lo_row_dim->set_outline_level( ip_outline_level = ws_layout-max_subtotal_level ) . + IF <fs_sfcat>-is_collapsed = abap_true. + lo_row_dim->set_visible( ip_visible = abap_false ) . + lo_row_dim->set_collapsed( ip_collapsed = <fs_sfcat>-is_collapsed ) . + ENDIF. +* Now let's write the cell values + IF ws_layout-is_stripped = abap_true AND l_s_color = abap_true. + l_style = get_color_style( i_row = l_table_row + i_fieldname = <fs_sfcat>-columnname + i_style = <fs_sfcat>-style_stripped ). + wo_worksheet->set_cell( ip_column = l_col_alpha + ip_row = l_row_int + ip_value = <fs_fldval> + ip_style = l_style ). + CLEAR l_s_color. + ELSE. + l_style = get_color_style( i_row = l_table_row + i_fieldname = <fs_sfcat>-columnname + i_style = <fs_sfcat>-style_normal ). + wo_worksheet->set_cell( ip_column = l_col_alpha + ip_row = l_row_int + ip_value = <fs_fldval> + ip_style = l_style ). + l_s_color = abap_true. + ENDIF. + READ TABLE wt_filter TRANSPORTING NO FIELDS WITH TABLE KEY rownumber = l_table_row + columnname = <fs_sfcat>-columnname. + IF sy-subrc = 0. + wo_worksheet->get_cell( EXPORTING + ip_column = l_col_alpha + ip_row = l_row_int + IMPORTING + ep_value = l_cell_value ). + wo_autofilter->set_value( i_column = l_col_int + i_value = l_cell_value ). + ENDIF. + ADD 1 TO l_row_int. + ENDLOOP. +* Let's check for subtotal lines + DO. + READ TABLE wt_subtotal_rows TRANSPORTING NO FIELDS WITH TABLE KEY row_int = l_row_int. + IF sy-subrc = 0. + IF <fs_sfcat>-is_subtotalled = abap_false AND + <fs_sfcat>-totals_function IS NOT INITIAL. + DO. + READ TABLE wt_subtotal_rows INTO ls_subtotal_rows WITH TABLE KEY row_int = l_row_int. + IF sy-subrc = 0. + l_row_int_start = ls_subtotal_rows-row_int_start. + l_row_int_end = l_row_int - 1. + + l_formula = create_formular_subtotal( i_row_int_start = l_row_int_start + i_row_int_end = l_row_int_end + i_column = l_col_alpha + i_totals_function = <fs_sfcat>-totals_function ). + wo_worksheet->set_cell( ip_column = l_col_alpha + ip_row = l_row_int + ip_formula = l_formula + ip_style = <fs_sfcat>-style_subtotal ). + IF <fs_sfcat>-is_collapsed = abap_true. + lo_row_dim = wo_worksheet->get_row_dimension( ip_row = l_row_int ). + lo_row_dim->set_collapsed( ip_collapsed = <fs_sfcat>-is_collapsed ). + ENDIF. + ADD 1 TO l_row_int. + ELSE. + EXIT. + ENDIF. + ENDDO. + ELSE. + ADD 1 TO l_row_int. + ENDIF. + ELSE. + EXIT. + ENDIF. + ENDDO. +* Now let's check for Grand total + IF <fs_sfcat>-is_subtotalled = abap_false AND + <fs_sfcat>-totals_function IS NOT INITIAL. + l_row_int_start = i_row_int + 1. + l_row_int_end = l_row_int - 1. + + l_formula = create_formular_subtotal( i_row_int_start = l_row_int_start + i_row_int_end = l_row_int_end + i_column = l_col_alpha + i_totals_function = <fs_sfcat>-totals_function ). + wo_worksheet->set_cell( ip_column = l_col_alpha + ip_row = l_row_int + ip_formula = l_formula + ip_style = <fs_sfcat>-style_subtotal ). + ENDIF. +* Now let's check for optimized + IF <fs_sfcat>-is_optimized = abap_true. + lo_col_dim = wo_worksheet->get_column_dimension( ip_column = l_col_alpha ). + lo_col_dim->set_auto_size( ip_auto_size = abap_true ) . + ENDIF. +* Now let's check for visible + IF <fs_sfcat>-is_hidden = abap_true. + lo_col_dim = wo_worksheet->get_column_dimension( ip_column = l_col_alpha ). + lo_col_dim->set_visible( ip_visible = abap_false ) . + ENDIF. + ENDLOOP. + + endmethod. + + + method OPEN_FILE. + data: l_bytecount type i, + lt_file type solix_tab, + l_dir type string, + l_sep type c. + + field-symbols: <fs_data> type any table. + + assign wo_data->* to <fs_data>. + +* catch zcx_excel . +*endtry. + if wo_excel is bound. + get_file( importing e_bytecount = l_bytecount + et_file = lt_file ) . + + l_dir = create_path( ) . + + cl_gui_frontend_services=>gui_download( exporting bin_filesize = l_bytecount + filename = l_dir + filetype = 'BIN' + changing data_tab = lt_file ). + cl_gui_frontend_services=>execute( + exporting + document = l_dir +* application = +* parameter = +* default_directory = +* maximized = +* minimized = +* synchronous = +* operation = 'OPEN' + exceptions + cntl_error = 1 + error_no_gui = 2 + bad_parameter = 3 + file_not_found = 4 + path_not_found = 5 + file_extension_unknown = 6 + error_execute_failed = 7 + synchronous_failed = 8 + not_supported_by_gui = 9 + ). + if sy-subrc <> 0. + message id sy-msgid type sy-msgty number sy-msgno + with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. + endif. + + endif. + + + endmethod. + + + method SET_AUTOFILTER_AREA. + DATA: ls_area TYPE zexcel_s_autofilter_area, + l_lines TYPE i, + lt_values TYPE zexcel_t_autofilter_values, + ls_values TYPE zexcel_s_autofilter_values. + +* Let's check for filter. + IF wo_autofilter IS BOUND. + ls_area-row_start = 1. + lt_values = wo_autofilter->get_values( ) . + SORT lt_values BY column ASCENDING. + DESCRIBE TABLE lt_values LINES l_lines. + READ TABLE lt_values INTO ls_values INDEX 1. + IF sy-subrc = 0. + ls_area-col_start = ls_values-column. + ENDIF. + READ TABLE lt_values INTO ls_values INDEX l_lines. + IF sy-subrc = 0. + ls_area-col_end = ls_values-column. + ENDIF. + wo_autofilter->set_filter_area( is_area = ls_area ) . + ENDIF. + + endmethod. + + + + + + method SET_CELL_FORMAT. + DATA: l_format TYPE zexcel_number_format. + + CLEAR r_format. + CASE i_inttype. + WHEN cl_abap_typedescr=>typekind_date. + r_format = wo_worksheet->get_default_excel_date_format( ). + WHEN cl_abap_typedescr=>typekind_time. + r_format = wo_worksheet->get_default_excel_time_format( ). + WHEN cl_abap_typedescr=>typekind_float OR cl_abap_typedescr=>typekind_packed. + IF i_decimals > 0 . + l_format = '#,##0.'. + DO i_decimals TIMES. + CONCATENATE l_format '0' INTO l_format. + ENDDO. + r_format = l_format. + ENDIF. + WHEN cl_abap_typedescr=>typekind_int OR cl_abap_typedescr=>typekind_int1 OR cl_abap_typedescr=>typekind_int2. + r_format = '#,##0'. + ENDCASE. + + endmethod. + + + method SET_FIELDCATALOG. + + DATA: lr_data TYPE REF TO data, + lo_structdescr TYPE REF TO cl_abap_structdescr, + lt_dfies TYPE ddfields, + ls_dfies TYPE dfies, + ls_fieldcatalog TYPE zexcel_s_fieldcatalog. + DATA: ls_fcat TYPE zexcel_s_converter_fcat. + + FIELD-SYMBOLS: <fs_tab> TYPE ANY TABLE. + + ASSIGN wo_data->* TO <fs_tab> . + + CREATE DATA lr_data LIKE LINE OF <fs_tab>. + + lo_structdescr ?= cl_abap_structdescr=>describe_by_data_ref( lr_data ). + + lt_dfies = zcl_excel_common=>describe_structure( io_struct = lo_structdescr ). + + LOOP AT lt_dfies INTO ls_dfies. + MOVE-CORRESPONDING ls_dfies TO ls_fcat. + ls_fcat-columnname = ls_dfies-fieldname. + INSERT ls_fcat INTO TABLE wt_fieldcatalog. + ENDLOOP. + + clean_fieldcatalog( ). + + endmethod. + + + + method SET_OPTION. + + IF ws_indx-begdt IS INITIAL. + ws_indx-begdt = sy-datum. + ENDIF. + + ws_indx-aedat = sy-datum. + ws_indx-usera = sy-uname. + ws_indx-pgmid = sy-cprog. + + EXPORT p1 = is_option TO DATABASE indx(xl) FROM ws_indx ID ws_indx-srtfd. + + IF sy-subrc = 0. + ws_option = is_option. + ENDIF. + + endmethod. + + + + method WRITE_FILE. + data: l_bytecount type i, + lt_file type solix_tab, + l_dir type string. + + field-symbols: <fs_data> type any table. + + assign wo_data->* to <fs_data>. + +* catch zcx_excel . +*endtry. + if wo_excel is bound. + get_file( importing e_bytecount = l_bytecount + et_file = lt_file ) . + if i_path is initial. + l_dir = create_path( ) . + else. + l_dir = i_path. + endif. + cl_gui_frontend_services=>gui_download( exporting bin_filesize = l_bytecount + filename = l_dir + filetype = 'BIN' + changing data_tab = lt_file ). + endif. + endmethod. + + + + *"* 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 + + + + + + + *"* 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 CONSTRUCTOR. + worksheet = io_sheet. + endmethod. + + + + method GET_FILTER_AREA. + + validate_area( ). + + rs_area = filter_area. + + endmethod. + + + + method GET_FILTER_RANGE. + DATA: l_row_start_c TYPE string, + l_row_end_c TYPE string, + l_col_start_c TYPE string, + l_col_end_c TYPE string, + l_value TYPE string. + + validate_area( ). + + l_row_end_c = filter_area-row_end. + CONDENSE l_row_end_c NO-GAPS. + + l_row_start_c = filter_area-row_start. + CONDENSE l_row_start_c NO-GAPS. + + l_col_start_c = zcl_excel_common=>convert_column2alpha( ip_column = filter_area-col_start ) . + l_col_end_c = zcl_excel_common=>convert_column2alpha( ip_column = filter_area-col_end ) . + + CONCATENATE l_col_start_c l_row_start_c ':' l_col_end_c l_row_end_c INTO r_range. + + endmethod. + + + + method GET_FILTER_REFERENCE. + DATA: l_row_start_c TYPE string, + l_row_end_c TYPE string, + l_col_start_c TYPE string, + l_col_end_c TYPE string, + l_value TYPE string. + + validate_area( ). + + l_row_end_c = filter_area-row_end. + CONDENSE l_row_end_c NO-GAPS. + + l_row_start_c = filter_area-row_start. + CONDENSE l_row_start_c NO-GAPS. + + l_col_start_c = zcl_excel_common=>convert_column2alpha( ip_column = filter_area-col_start ) . + l_col_end_c = zcl_excel_common=>convert_column2alpha( ip_column = filter_area-col_end ) . + l_value = worksheet->get_title( ) . + + r_ref = zcl_excel_common=>escape_string( ip_value = l_value ). + + CONCATENATE r_ref '!$' l_col_start_c '$' l_row_start_c ':$' l_col_end_c '$' l_row_end_c INTO r_ref. + + endmethod. + + + + method GET_VALUES. + + rt_filter = values. + + endmethod. + + + + method SET_FILTER_AREA. + + filter_area = is_area. + + endmethod. + + + + + method SET_VALUE. + DATA: ls_values TYPE zexcel_s_autofilter_values. + +* Checks a re missing. + ls_values-column = i_column. + ls_values-value = i_value. + + INSERT ls_values INTO TABLE values. +* Now we need to be sure we don't get the same value again. + DELETE ADJACENT DUPLICATES FROM values COMPARING column value. + + endmethod. + + + + method SET_VALUES. + +* Checks are missing. + values = it_values. + DELETE ADJACENT DUPLICATES FROM values COMPARING column value. + + endmethod. + + + method VALIDATE_AREA. + DATA: l_col TYPE zexcel_cell_column, + l_row TYPE zexcel_cell_row. + + l_row = worksheet->get_highest_row( ) . + l_col = worksheet->get_highest_column( ) . + + IF filter_area IS INITIAL. + filter_area-row_start = 1. + filter_area-col_start = 1. + filter_area-row_end = l_row . + filter_area-col_end = l_col . + ENDIF. + + IF filter_area-row_start < 1. + filter_area-row_start = 1. + ENDIF. + IF filter_area-col_start < 1. + filter_area-col_start = 1. + ENDIF. + IF filter_area-row_end > l_row OR + filter_area-row_end < 1. + filter_area-row_end = l_row. + ENDIF. + IF filter_area-col_end > l_col OR + filter_area-col_end < 1. + filter_area-col_end = l_col. + ENDIF. + IF filter_area-row_start >= filter_area-row_end. + filter_area-row_start = filter_area-row_end - 1. + IF filter_area-row_start < 1. + filter_area-row_start = 1. + filter_area-row_end = 2. + ENDIF. + ENDIF. + IF filter_area-col_start > filter_area-col_end. + filter_area-col_start = filter_area-col_end. + ENDIF. + endmethod. + + + + *"* 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 +TYPES: BEGIN OF ts_objects, + sheet_guid TYPE uuid, + autofilter TYPE REF TO zcl_excel_autofilter, + END OF ts_objects, + + tt_objects TYPE HASHED TABLE OF ts_objects WITH UNIQUE KEY sheet_guid. + *"* use this source file for any macro definitions you need +*"* in the implementation part of the class + + ABAP + + + + + + method ADD. + DATA: ls_autofilters TYPE ts_objects, + l_guid TYPE uuid. + l_guid = io_sheet->get_guid( ) . + READ TABLE autofilters INTO ls_autofilters WITH TABLE KEY sheet_guid = l_guid. + IF sy-subrc = 0. + ro_autofilter = ls_autofilters-autofilter. + ELSE. + CREATE OBJECT ro_autofilter + EXPORTING + io_sheet = io_sheet. + ls_autofilters-autofilter = ro_autofilter. + ls_autofilters-sheet_guid = l_guid. + INSERT ls_autofilters INTO TABLE autofilters . + ENDIF. + endmethod. + + + method CLEAR. + + REFRESH autofilters. + + endmethod. + + + + + method GET. + + DATA: ls_autofilters TYPE ts_objects. + + READ TABLE autofilters INTO ls_autofilters WITH TABLE KEY sheet_guid = i_sheet_guid. + IF sy-subrc = 0. + ro_autofilter = ls_autofilters-autofilter. + ELSE. + CLEAR ro_autofilter. + ENDIF. + + endmethod. + + + + method IS_EMPTY. + IF autofilters IS INITIAL. + r_empty = abap_true. + ENDIF. + endmethod. + + + + method REMOVE. + DATA: ls_autofilters TYPE ts_objects. + + DELETE autofilters WHERE sheet_guid = i_sheet_guid. + + endmethod. + + + + method SIZE. + DESCRIBE TABLE autofilters LINES r_size. + endmethod. + + + + + *"* 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 +TYPES: BEGIN OF ts_col_converter, + col TYPE lvc_col, + int TYPE lvc_int, + inv TYPE lvc_inv, + fontcolor TYPE zexcel_style_color_argb, + fillcolor TYPE zexcel_style_color_argb, + END OF ts_col_converter, + + tt_col_converter TYPE HASHED TABLE OF ts_col_converter WITH UNIQUE KEY col int inv. + *"* use this source file for any macro definitions you need +*"* in the implementation part of the class + + + ABAP + KKBLO + + + + + + + + + + method APPLY_SORT. + DATA: lt_otab TYPE abap_sortorder_tab, + ls_otab TYPE abap_sortorder. + + FIELD-SYMBOLS: <fs_table> TYPE STANDARD TABLE, + <fs_sort> TYPE lvc_s_sort. + + CREATE DATA eo_table LIKE it_table. + ASSIGN eo_table->* TO <fs_table>. + + <fs_table> = it_table. + + SORT wt_sort BY spos. + LOOP AT wt_sort ASSIGNING <fs_sort>. + IF <fs_sort>-up = abap_true. + ls_otab-name = <fs_sort>-fieldname. + ls_otab-descending = abap_false. +* ls_otab-astext = abap_true. " not only text fields + INSERT ls_otab INTO TABLE lt_otab. + ENDIF. + IF <fs_sort>-down = abap_true. + ls_otab-name = <fs_sort>-fieldname. + ls_otab-descending = abap_true. +* ls_otab-astext = abap_true. " not only text fields + INSERT ls_otab INTO TABLE lt_otab. + ENDIF. + ENDLOOP. + IF lt_otab IS NOT INITIAL. + SORT <fs_table> BY (lt_otab). + ENDIF. + + endmethod. + + + method CLASS_CONSTRUCTOR. +* let's fill the color conversion routines. + DATA: ls_color TYPE ts_col_converter. +* 0 all combination the same + ls_color-col = 0. + ls_color-int = 0. + ls_color-inv = 0. + ls_color-fontcolor = 'FF000000'. " 000 000 000 Black + ls_color-fillcolor = 'FFFFFFFF'. " 255 255 255 White + INSERT ls_color INTO TABLE wt_colors. + + ls_color-col = 0. + ls_color-int = 0. + ls_color-inv = 1. + ls_color-fontcolor = 'FF000000'. " 000 000 000 Black + ls_color-fillcolor = 'FFFFFFFF'. " 255 255 255 White + INSERT ls_color INTO TABLE wt_colors. + + ls_color-col = 0. + ls_color-int = 1. + ls_color-inv = 0. + ls_color-fontcolor = 'FF000000'. " 000 000 000 Black + ls_color-fillcolor = 'FFFFFFFF'. " 255 255 255 White + INSERT ls_color INTO TABLE wt_colors. + + ls_color-col = 0. + ls_color-int = 1. + ls_color-inv = 1. + ls_color-fontcolor = 'FF000000'. " 000 000 000 Black + ls_color-fillcolor = 'FFFFFFFF'. " 255 255 255 White + INSERT ls_color INTO TABLE wt_colors. + +* Blue + ls_color-col = 1. + ls_color-int = 0. + ls_color-inv = 0. + ls_color-fontcolor = 'FF000000'. " 000 000 000 Black + ls_color-fillcolor = 'FFB0E4FC'. " 176 228 252 blue + INSERT ls_color INTO TABLE wt_colors. + + ls_color-col = 1. + ls_color-int = 0. + ls_color-inv = 1. + ls_color-fontcolor = 'FFB0E4FC'. " 176 228 252 blue + ls_color-fillcolor = 'FFFFFFFF'. " 255 255 255 White + INSERT ls_color INTO TABLE wt_colors. + + ls_color-col = 1. + ls_color-int = 1. + ls_color-inv = 0. + ls_color-fontcolor = 'FF000000'. " 000 000 000 Black + ls_color-fillcolor = 'FF5FCBFE'. " 095 203 254 Int blue + INSERT ls_color INTO TABLE wt_colors. + + ls_color-col = 1. + ls_color-int = 1. + ls_color-inv = 1. + ls_color-fontcolor = 'FF5FCBFE'. " 095 203 254 + ls_color-fillcolor = 'FFFFFFFF'. " 255 255 255 + INSERT ls_color INTO TABLE wt_colors. + +* Gray + ls_color-col = 2. + ls_color-int = 0. + ls_color-inv = 0. + ls_color-fontcolor = 'FF000000'. + ls_color-fillcolor = 'FFE5EAF0'. " 229 234 240 gray + INSERT ls_color INTO TABLE wt_colors. + + ls_color-col = 2. + ls_color-int = 0. + ls_color-inv = 1. + ls_color-fontcolor = 'FFE5EAF0'. " 229 234 240 gray + ls_color-fillcolor = 'FFFFFFFF'. " 255 255 255 White + INSERT ls_color INTO TABLE wt_colors. + + ls_color-col = 2. + ls_color-int = 1. + ls_color-inv = 0. + ls_color-fontcolor = 'FF000000'. " 000 000 000 Black + ls_color-fillcolor = 'FFD8E8F4'. " 216 234 244 int gray + INSERT ls_color INTO TABLE wt_colors. + + ls_color-col = 2. + ls_color-int = 1. + ls_color-inv = 1. + ls_color-fontcolor = 'FFD8E8F4'. " 216 234 244 int gray + ls_color-fillcolor = 'FFFFFFFF'. " 255 255 255 White + INSERT ls_color INTO TABLE wt_colors. + +*Yellow + ls_color-col = 3. + ls_color-int = 0. + ls_color-inv = 0. + ls_color-fontcolor = 'FF000000'. " 000 000 000 Black + ls_color-fillcolor = 'FFFEFEB8'. " 254 254 184 yellow + INSERT ls_color INTO TABLE wt_colors. + + ls_color-col = 3. + ls_color-int = 0. + ls_color-inv = 1. + ls_color-fontcolor = 'FFFEFEB8'. " 254 254 184 yellow + ls_color-fillcolor = 'FFFFFFFF'. " 255 255 255 White + INSERT ls_color INTO TABLE wt_colors. + + ls_color-col = 3. + ls_color-int = 1. + ls_color-inv = 0. + ls_color-fontcolor = 'FF000000'. " 000 000 000 Black + ls_color-fillcolor = 'FFF9ED5D'. " 249 237 093 int yellow + INSERT ls_color INTO TABLE wt_colors. + + ls_color-col = 3. + ls_color-int = 1. + ls_color-inv = 1. + ls_color-fontcolor = 'FFF9ED5D'. " 249 237 093 int yellow + ls_color-fillcolor = 'FFFFFFFF'. " 255 255 255 White + INSERT ls_color INTO TABLE wt_colors. + +* light blue + ls_color-col = 4. + ls_color-int = 0. + ls_color-inv = 0. + ls_color-fontcolor = 'FF000000'. " 000 000 000 Black + ls_color-fillcolor = 'FFCEE7FB'. " 206 231 251 light blue + INSERT ls_color INTO TABLE wt_colors. + + ls_color-col = 4. + ls_color-int = 0. + ls_color-inv = 1. + ls_color-fontcolor = 'FFCEE7FB'. " 206 231 251 light blue + ls_color-fillcolor = 'FFFFFFFF'. " 255 255 255 White + INSERT ls_color INTO TABLE wt_colors. + + ls_color-col = 4. + ls_color-int = 1. + ls_color-inv = 0. + ls_color-fontcolor = 'FF000000'. " 000 000 000 Black + ls_color-fillcolor = 'FF9ACCEF'. " 154 204 239 int light blue + INSERT ls_color INTO TABLE wt_colors. + + ls_color-col = 4. + ls_color-int = 1. + ls_color-inv = 1. + ls_color-fontcolor = 'FF9ACCEF'. " 154 204 239 int light blue + ls_color-fillcolor = 'FFFFFFFF'. " 255 255 255 White + INSERT ls_color INTO TABLE wt_colors. + +* Green + ls_color-col = 5. + ls_color-int = 0. + ls_color-inv = 0. + ls_color-fontcolor = 'FF000000'. " 000 000 000 Black + ls_color-fillcolor = 'FFCEF8AE'. " 206 248 174 Green + INSERT ls_color INTO TABLE wt_colors. + + ls_color-col = 5. + ls_color-int = 0. + ls_color-inv = 1. + ls_color-fontcolor = 'FFCEF8AE'. " 206 248 174 Green + ls_color-fillcolor = 'FFFFFFFF'. " 255 255 255 White + INSERT ls_color INTO TABLE wt_colors. + + ls_color-col = 5. + ls_color-int = 1. + ls_color-inv = 0. + ls_color-fontcolor = 'FF000000'. " 000 000 000 Black + ls_color-fillcolor = 'FF7AC769'. " 122 199 105 int Green + INSERT ls_color INTO TABLE wt_colors. + + ls_color-col = 5. + ls_color-int = 1. + ls_color-inv = 1. + ls_color-fontcolor = 'FF7AC769'. " 122 199 105 int Green + ls_color-fillcolor = 'FFFFFFFF'. " 255 255 255 White + INSERT ls_color INTO TABLE wt_colors. + +* Red + ls_color-col = 6. + ls_color-int = 0. + ls_color-inv = 0. + ls_color-fontcolor = 'FF000000'. " 000 000 000 Black + ls_color-fillcolor = 'FFFDBBBC'. " 253 187 188 Red + INSERT ls_color INTO TABLE wt_colors. + + ls_color-col = 6. + ls_color-int = 0. + ls_color-inv = 1. + ls_color-fontcolor = 'FFFDBBBC'. " 253 187 188 Red + ls_color-fillcolor = 'FFFFFFFF'. " 255 255 255 White + INSERT ls_color INTO TABLE wt_colors. + + ls_color-col = 6. + ls_color-int = 1. + ls_color-inv = 0. + ls_color-fontcolor = 'FF000000'. " 000 000 000 Black + ls_color-fillcolor = 'FFFB6B6B'. " 251 107 107 int Red + INSERT ls_color INTO TABLE wt_colors. + + ls_color-col = 6. + ls_color-int = 1. + ls_color-inv = 1. + ls_color-fontcolor = 'FFFB6B6B'. " 251 107 107 int Red + ls_color-fillcolor = 'FFFFFFFF'. " 255 255 255 White + INSERT ls_color INTO TABLE wt_colors. + + endmethod. + + + + + method GET_COLOR. + DATA: ls_con_col TYPE zexcel_s_converter_col, + ls_color TYPE ts_col_converter, + l_line TYPE i, + l_color(4) TYPE c. + FIELD-SYMBOLS: <fs_tab> TYPE STANDARD TABLE, + <fs_stab> TYPE ANY, + <fs> TYPE ANY, + <fs_tcol> TYPE lvc_t_scol, + <fs_scol> TYPE lvc_s_scol. + +* Loop trough the table to set the color properties of each line. The color properties field is +* Char 4 and the characters is set as follows: +* Char 1 = C = This is a color property +* Char 2 = 6 = Color code (1 - 7) +* Char 3 = Intensified on/of = 1 = on +* Char 4 = Inverse display = 0 = of + + ASSIGN io_table->* TO <fs_tab>. + + IF ws_layo-info_fname IS NOT INITIAL OR + ws_layo-ctab_fname IS NOT INITIAL. + LOOP AT <fs_tab> ASSIGNING <fs_stab>. + l_line = sy-tabix. + IF ws_layo-info_fname IS NOT INITIAL. + ASSIGN COMPONENT ws_layo-info_fname OF STRUCTURE <fs_stab> TO <fs>. + IF sy-subrc = 0. + IF <fs> IS NOT INITIAL. + l_color = <fs>. + IF l_color(1) = 'C'. + READ TABLE wt_colors INTO ls_color WITH TABLE KEY col = l_color+1(1) + int = l_color+2(1) + inv = l_color+3(1). + IF sy-subrc = 0. + ls_con_col-rownumber = l_line. + ls_con_col-columnname = space. + ls_con_col-fontcolor = ls_color-fontcolor. + ls_con_col-fillcolor = ls_color-fillcolor. + INSERT ls_con_col INTO TABLE et_colors. + ENDIF. + ENDIF. + ENDIF. + ENDIF. + ENDIF. + IF ws_layo-ctab_fname IS NOT INITIAL. + ASSIGN COMPONENT ws_layo-ctab_fname OF STRUCTURE <fs_stab> TO <fs_tcol>. + IF sy-subrc = 0. + LOOP AT <fs_tcol> ASSIGNING <fs_scol>. + READ TABLE wt_colors INTO ls_color WITH TABLE KEY col = <fs_scol>-color-col + int = <fs_scol>-color-int + inv = <fs_scol>-color-inv. + IF sy-subrc = 0. + ls_con_col-rownumber = l_line. + ls_con_col-columnname = <fs_scol>-fname. + ls_con_col-fontcolor = ls_color-fontcolor. + ls_con_col-fillcolor = ls_color-fillcolor. + ls_con_col-nokeycol = <fs_scol>-nokeycol. + INSERT ls_con_col INTO TABLE et_colors. + ENDIF. + ENDLOOP. + ENDIF. + ENDIF. + ENDLOOP. + ENDIF. + endmethod. + + + + + method GET_FILTER. + DATA: ls_filt TYPE lvc_s_filt, + l_line TYPE i, + ls_filter TYPE zexcel_s_converter_fil. + DATA: lo_addit TYPE REF TO cl_abap_elemdescr, + lt_components_tab TYPE cl_abap_structdescr=>component_table, + ls_components TYPE abap_componentdescr, + lo_table TYPE REF TO cl_abap_tabledescr, + lo_struc TYPE REF TO cl_abap_structdescr, + lo_trange TYPE REF TO data, + lo_srange TYPE REF TO data, + lo_ltabdata TYPE REF TO data. + + FIELD-SYMBOLS: <fs_tab> TYPE STANDARD TABLE, + <fs_ltab> TYPE STANDARD TABLE, + <fs_stab> TYPE ANY, + <fs> TYPE ANY, + <fs1> TYPE ANY, + <fs_srange> TYPE ANY, + <fs_trange> TYPE STANDARD TABLE. + + IF ws_option-filter = abap_false. + REFRESH et_filter. + RETURN. + ENDIF. + + ASSIGN xo_table->* TO <fs_tab>. + + CREATE DATA lo_ltabdata LIKE <fs_tab>. + ASSIGN lo_ltabdata->* TO <fs_ltab>. + + LOOP AT wt_filt INTO ls_filt. + LOOP AT <fs_tab> ASSIGNING <fs_stab>. + l_line = sy-tabix. + ASSIGN COMPONENT ls_filt-fieldname OF STRUCTURE <fs_stab> TO <fs>. + IF sy-subrc = 0. + IF l_line = 1. + REFRESH lt_components_tab. + ls_components-name = 'SIGN'. + lo_addit ?= cl_abap_typedescr=>describe_by_data( ls_filt-sign ). + ls_components-type = lo_addit . + INSERT ls_components INTO TABLE lt_components_tab. + ls_components-name = 'OPTION'. + lo_addit ?= cl_abap_typedescr=>describe_by_data( ls_filt-option ). + ls_components-type = lo_addit . + INSERT ls_components INTO TABLE lt_components_tab. + ls_components-name = 'LOW'. + lo_addit ?= cl_abap_typedescr=>describe_by_data( <fs> ). + ls_components-type = lo_addit . + INSERT ls_components INTO TABLE lt_components_tab. + ls_components-name = 'HIGH'. + lo_addit ?= cl_abap_typedescr=>describe_by_data( <fs> ). + ls_components-type = lo_addit . + INSERT ls_components INTO TABLE lt_components_tab. + "create new line type + TRY. + lo_struc = cl_abap_structdescr=>create( p_components = lt_components_tab + p_strict = abap_false ). + CATCH cx_sy_struct_creation. + CONTINUE. + ENDTRY. + lo_table = cl_abap_tabledescr=>create( lo_struc ). + + CREATE DATA lo_trange TYPE HANDLE lo_table. + CREATE DATA lo_srange TYPE HANDLE lo_struc. + + ASSIGN lo_trange->* TO <fs_trange>. + ASSIGN lo_srange->* TO <fs_srange>. + ENDIF. + REFRESH <fs_trange>. + ASSIGN COMPONENT 'SIGN' OF STRUCTURE <fs_srange> TO <fs1>. + <fs1> = ls_filt-sign. + ASSIGN COMPONENT 'OPTION' OF STRUCTURE <fs_srange> TO <fs1>. + <fs1> = ls_filt-option. + ASSIGN COMPONENT 'LOW' OF STRUCTURE <fs_srange> TO <fs1>. + <fs1> = ls_filt-low. + ASSIGN COMPONENT 'HIGH' OF STRUCTURE <fs_srange> TO <fs1>. + <fs1> = ls_filt-high. + INSERT <fs_srange> INTO TABLE <fs_trange>. + IF <fs> IN <fs_trange>. + IF ws_option-filter = abap_true. + ls_filter-rownumber = l_line. + ls_filter-columnname = ls_filt-fieldname. + INSERT ls_filter INTO TABLE et_filter. + ELSE. + INSERT <fs_stab> INTO TABLE <fs_ltab>. + ENDIF. + ENDIF. + ENDIF. + ENDLOOP. + IF ws_option-filter = abap_undefined. + <fs_tab> = <fs_ltab>. + REFRESH <fs_ltab>. + ENDIF. + ENDLOOP. + + endmethod. + + + + + method UPDATE_CATALOG. + DATA: ls_fieldcatalog TYPE zexcel_s_converter_fcat, + ls_ref TYPE salv_s_ddic_reference, + ls_fcat TYPE lvc_s_fcat, + ls_sort TYPE lvc_s_sort, + l_decimals TYPE lvc_decmls. + + FIELD-SYMBOLS: <fs_scat> TYPE zexcel_s_converter_fcat. + + IF ws_layo-zebra IS NOT INITIAL. + cs_layout-is_stripped = abap_true. + ENDIF. + IF ws_layo-no_keyfix IS INITIAL OR + ws_layo-no_keyfix = '0'. + cs_layout-is_fixed = abap_true. + ENDIF. + + LOOP AT wt_fcat INTO ls_fcat. + CLEAR: ls_fieldcatalog, + l_decimals. + CASE ws_option-hidenc. + WHEN abap_false. " We make hiden columns visible + CLEAR ls_fcat-no_out. + WHEN abap_true. +* We convert column and hide it. + WHEN abap_undefined. "We don't convert hiden columns + IF ls_fcat-no_out = abap_true. + ls_fcat-tech = abap_true. + ENDIF. + ENDCASE. + IF ls_fcat-tech = abap_false. + ls_fieldcatalog-tabname = ls_fcat-tabname. + ls_fieldcatalog-fieldname = ls_fcat-fieldname . + ls_fieldcatalog-columnname = ls_fcat-fieldname . + ls_fieldcatalog-position = ls_fcat-col_pos. + ls_fieldcatalog-col_id = ls_fcat-col_id. + ls_fieldcatalog-convexit = ls_fcat-convexit. + ls_fieldcatalog-inttype = ls_fcat-inttype. + ls_fieldcatalog-scrtext_s = ls_fcat-scrtext_s . + ls_fieldcatalog-scrtext_m = ls_fcat-scrtext_m . + ls_fieldcatalog-scrtext_l = ls_fcat-scrtext_l. + l_decimals = ls_fcat-decimals_o. + IF l_decimals IS NOT INITIAL. + ls_fieldcatalog-decimals = l_decimals. + ELSE. + ls_fieldcatalog-decimals = ls_fcat-decimals . + ENDIF. + CASE ws_option-subtot. + WHEN abap_false. " We ignore subtotals + CLEAR ls_fcat-do_sum. + WHEN abap_true. " We convert subtotals and detail + + WHEN abap_undefined. " We should only take subtotals and displayed detail +* for now abap_true + ENDCASE. + CASE ls_fcat-do_sum. + WHEN abap_true. + ls_fieldcatalog-totals_function = zcl_excel_table=>totals_function_sum. + WHEN 'A'. + ls_fieldcatalog-totals_function = zcl_excel_table=>totals_function_min. + WHEN 'B' . + ls_fieldcatalog-totals_function = zcl_excel_table=>totals_function_max. + WHEN 'C' . + ls_fieldcatalog-totals_function = zcl_excel_table=>totals_function_average. + WHEN OTHERS. + CLEAR ls_fieldcatalog-totals_function . + ENDCASE. + ls_fieldcatalog-fix_column = ls_fcat-fix_column. + IF ws_layo-cwidth_opt IS INITIAL. + IF ls_fcat-col_opt IS NOT INITIAL. + ls_fieldcatalog-is_optimized = abap_true. + ENDIF. + ELSE. + ls_fieldcatalog-is_optimized = abap_true. + ENDIF. + IF ls_fcat-no_out IS NOT INITIAL. + ls_fieldcatalog-is_hidden = abap_true. + ls_fieldcatalog-position = ls_fieldcatalog-col_id. " We hide based on orginal data structure + ENDIF. +* Alignment in each cell + CASE ls_fcat-just. + WHEN 'R'. + ls_fieldcatalog-alignment = zcl_excel_style_alignment=>c_horizontal_right. + WHEN 'L'. + ls_fieldcatalog-alignment = zcl_excel_style_alignment=>c_horizontal_left. + WHEN 'C'. + ls_fieldcatalog-alignment = zcl_excel_style_alignment=>c_horizontal_center. + WHEN OTHERS. + CLEAR ls_fieldcatalog-alignment. + ENDCASE. +* Check for subtotals. + READ TABLE wt_sort INTO ls_sort WITH KEY fieldname = ls_fcat-fieldname. + IF sy-subrc = 0 AND ws_option-subtot <> abap_false. + ls_fieldcatalog-sort_level = 0 . +* IF ls_fieldcatalog-totals_function IS INITIAL. " Not clear why not +* CLEAR ls_fieldcatalog-is_subtotalled. +* ELSE. + ls_fieldcatalog-is_subtotalled = ls_sort-subtot. +* ENDIF. + ls_fieldcatalog-is_collapsed = ls_sort-expa. + IF ls_fieldcatalog-is_subtotalled = abap_true. + ls_fieldcatalog-sort_level = ls_sort-spos. + ls_fieldcatalog-totals_function = zcl_excel_table=>totals_function_sum. " we need function for text + ENDIF. + ENDIF. + APPEND ls_fieldcatalog TO ct_fieldcatalog. + ENDIF. + ENDLOOP. + + SORT ct_fieldcatalog BY sort_level ASCENDING. + cs_layout-max_subtotal_level = 0. + LOOP AT ct_fieldcatalog ASSIGNING <fs_scat> WHERE sort_level > 0. + cs_layout-max_subtotal_level = cs_layout-max_subtotal_level + 1. + <fs_scat>-sort_level = cs_layout-max_subtotal_level. + ENDLOOP. + + endmethod. + + + + *"* 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 + + + + + + + *"* 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 GET_TABLE. + DATA: lo_object TYPE REF TO object, + ls_seoclass TYPE seoclass, + l_method TYPE string. + + SELECT SINGLE * INTO ls_seoclass + FROM seoclass + WHERE clsname = 'IF_SALV_BS_DATA_SOURCE'. + + IF sy-subrc = 0. + l_method = 'GET_TABLE_REF'. + lo_object ?= io_object. + CALL METHOD lo_object->(l_method) + RECEIVING + value = ro_data. + ELSE. + l_method = 'GET_REF_TO_TABLE'. + lo_object ?= io_object. + CALL METHOD lo_object->(l_method) + RECEIVING + value = ro_data. + ENDIF. + + endmethod. + + + + *"* 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 CREATE_WT_FCAT. + DATA: lr_data TYPE REF TO data, + lo_structdescr TYPE REF TO cl_abap_structdescr, + lt_dfies TYPE ddfields, + ls_dfies TYPE dfies, + lv_sytabix TYPE sytabix. + + DATA: ls_fcat TYPE lvc_s_fcat. + + FIELD-SYMBOLS: <fs_tab> TYPE ANY TABLE. + + ASSIGN io_table->* TO <fs_tab> . + CREATE DATA lr_data LIKE LINE OF <fs_tab>. + + lo_structdescr ?= cl_abap_structdescr=>describe_by_data_ref( lr_data ). + + lt_dfies = zcl_excel_common=>describe_structure( io_struct = lo_structdescr ). + + loop at lt_dfies into ls_dfies. + MOVE-CORRESPONDING ls_dfies TO ls_fcat. +* ls_fcat-columnname = ls_dfies-fieldname. + ls_fcat-col_pos = ls_dfies-position. + ls_fcat-key = ls_dfies-keyflag. + get_fields_info( CHANGING xs_fcat = ls_fcat ) . + + ls_fcat-col_opt = abap_true. + + get_columns_info( CHANGING xs_fcat = ls_fcat ) . + + INSERT ls_fcat INTO TABLE wt_fcat. + endloop. + + endmethod. + + + method CREATE_WT_FILT. +* No neeed for superclass. +* Only for WD + DATA: lt_otab TYPE abap_sortorder_tab, + ls_otab TYPE abap_sortorder. + DATA: lt_filters TYPE salv_wd_t_filter_rule_ref, + ls_filt TYPE lvc_s_filt. + + FIELD-SYMBOLS: <fs_fields> TYPE salv_wd_s_field_ref, + <fs_filter> TYPE salv_wd_s_filter_rule_ref. + + LOOP AT wt_fields ASSIGNING <fs_fields>. + REFRESH lt_filters. + lt_filters = <fs_fields>-r_field->if_salv_wd_filter~get_filter_rules( ) . + LOOP AT lt_filters ASSIGNING <fs_filter>. + ls_filt-fieldname = <fs_fields>-fieldname. + IF <fs_filter>-r_filter_rule->get_included( ) = abap_true. + ls_filt-sign = 'I'. + ELSE. + ls_filt-sign = 'E'. + ENDIF. + ls_filt-option = <fs_filter>-r_filter_rule->get_operator( ). + ls_filt-high = <fs_filter>-r_filter_rule->get_high_value( ) . + ls_filt-low = <fs_filter>-r_filter_rule->get_low_value( ) . + INSERT ls_filt INTO TABLE wt_filt. + ENDLOOP. + ENDLOOP. + + endmethod. + + + method CREATE_WT_SORT. + DATA: lo_sort TYPE REF TO cl_salv_wd_sort_rule, + l_sort_order TYPE salv_wd_constant, + ls_sort TYPE lvc_s_sort. + + FIELD-SYMBOLS: <fs_fields> TYPE salv_wd_s_field_ref. + + LOOP AT wt_fields ASSIGNING <fs_fields>. + lo_sort = <fs_fields>-r_field->if_salv_wd_sort~get_sort_rule( ) . + IF lo_sort IS BOUND. + l_sort_order = lo_sort->get_sort_order( ). + IF l_sort_order <> if_salv_wd_c_sort=>sort_order. + CLEAR ls_sort. + ls_sort-spos = lo_sort->get_sort_position( ). + ls_sort-fieldname = <fs_fields>-fieldname. +* ls_sort-GROUP + ls_sort-subtot = lo_sort->get_group_aggregation( ). +* ls_sort-COMP +* ls_sort-EXPA +* ls_sort-SELTEXT +* ls_sort-OBLIGATORY +* ls_sort-LEVEL +* ls_sort-NO_OUT + IF l_sort_order = if_salv_wd_c_sort=>sort_order_ascending. + ls_sort-up = abap_true. + ELSE. + ls_sort-down = abap_true. + ENDIF. + INSERT ls_sort INTO TABLE wt_sort. + ENDIF. + ENDIF. + ENDLOOP. + + endmethod. + + + + method GET_COLUMNS_INFO. + DATA: l_numc2 TYPE salv_wd_constant. + + + FIELD-SYMBOLS: <fs_column> TYPE salv_wd_s_column_ref. + + READ TABLE wt_columns ASSIGNING <fs_column> WITH KEY id = xs_fcat-fieldname . + IF sy-subrc = 0. + xs_fcat-col_pos = <fs_column>-r_column->get_position( ) . + l_numc2 = <fs_column>-r_column->get_fixed_position( ). + IF l_numc2 = '02'. + xs_fcat-fix_column = abap_true . + ENDIF. + l_numc2 = <fs_column>-r_column->get_visible( ). + IF l_numc2 = '01'. + xs_fcat-no_out = abap_true . + ENDIF. + ENDIF. + + endmethod. + + + + method GET_FIELDS_INFO. + DATA: lo_aggr TYPE REF TO cl_salv_wd_aggr_rule, + l_aggrtype TYPE salv_wd_constant. + + FIELD-SYMBOLS: <fs_fields> TYPE salv_wd_s_field_ref. + + READ TABLE wt_fields ASSIGNING <fs_fields> WITH KEY fieldname = xs_fcat-fieldname. + IF sy-subrc = 0. + lo_aggr = <fs_fields>-r_field->if_salv_wd_aggr~get_aggr_rule( ) . + IF lo_aggr IS BOUND. + l_aggrtype = lo_aggr->get_aggregation_type( ) . + CASE l_aggrtype. + WHEN if_salv_wd_c_aggregation=>aggrtype_total. + xs_fcat-do_sum = abap_true. + WHEN if_salv_wd_c_aggregation=>aggrtype_minimum. + xs_fcat-do_sum = 'A'. + WHEN if_salv_wd_c_aggregation=>aggrtype_maximum . + xs_fcat-do_sum = 'B'. + WHEN if_salv_wd_c_aggregation=>aggrtype_average . + xs_fcat-do_sum = 'C'. + WHEN OTHERS. + CLEAR xs_fcat-do_sum . + ENDCASE. + ENDIF. + ENDIF. + + endmethod. + + + + *"* use this source file for the definition and implementation of +*"* local helper classes, interface definitions and type +*"* declarations + *"* use this source file for any type of declarations (class +*"* definitions, interfaces or type declarations) you need for +*"* components in the private section + *"* use this source file for any macro definitions you need +*"* in the implementation part of the class + + + + + + + + METHOD load_vbaproject. + + DATA lv_content TYPE xstring. + + lv_content = me->get_from_zip_archive( ip_path ). + + ip_excel->zif_excel_book_vba_project~set_vbaproject( lv_content ). + + ENDMETHOD. + + + method LOAD_WORKBOOK. + super->load_workbook( EXPORTING iv_workbook_full_filename = iv_workbook_full_filename + io_excel = io_excel ). + + CONSTANTS: lc_vba_project TYPE string VALUE 'http://schemas.microsoft.com/office/2006/relationships/vbaProject'. + + DATA: rels_workbook_path TYPE string, + rels_workbook TYPE REF TO if_ixml_document, + path TYPE string, + node TYPE REF TO if_ixml_element, + workbook TYPE REF TO if_ixml_document, + stripped_name TYPE chkfile, + dirname TYPE string, + relationship TYPE t_relationship, + fileversion TYPE t_fileversion, + workbookpr TYPE t_workbookpr. + + FIELD-SYMBOLS: <worksheet> TYPE t_relationship. + + CALL FUNCTION 'TRINT_SPLIT_FILE_AND_PATH' + EXPORTING + full_name = iv_workbook_full_filename + IMPORTING + stripped_name = stripped_name + file_path = dirname. + + " Read Workbook Relationships + CONCATENATE dirname '_rels/' stripped_name '.rels' + INTO rels_workbook_path. + + rels_workbook = me->get_ixml_from_zip_archive( rels_workbook_path ). + + node ?= rels_workbook->find_from_name( 'Relationship' ). + WHILE node IS BOUND. + me->fill_struct_from_attributes( EXPORTING ip_element = node CHANGING cp_structure = relationship ). + + CASE relationship-type. + WHEN lc_vba_project. + " Read VBA binary + CONCATENATE dirname relationship-target INTO path. + me->load_vbaproject( ip_path = path + ip_excel = io_excel ). + WHEN OTHERS. + ENDCASE. + + node ?= node->get_next( ). + ENDWHILE. + + " Read Workbook codeName + workbook = me->get_ixml_from_zip_archive( iv_workbook_full_filename ). + node ?= workbook->find_from_name( 'fileVersion' ). + IF node IS BOUND. + + fill_struct_from_attributes( EXPORTING ip_element = node + CHANGING cp_structure = fileversion ). + + io_excel->zif_excel_book_vba_project~set_codename( fileversion-codename ). + ENDIF. + + " Read Workbook codeName + workbook = me->get_ixml_from_zip_archive( iv_workbook_full_filename ). + node ?= workbook->find_from_name( 'workbookPr' ). + IF node IS BOUND. + + fill_struct_from_attributes( EXPORTING ip_element = node + CHANGING cp_structure = workbookpr ). + + io_excel->zif_excel_book_vba_project~set_codename_pr( workbookpr-codename ). + ENDIF. + + endmethod. + + + method LOAD_WORKSHEET. + + super->load_worksheet( EXPORTING ip_path = ip_path + io_worksheet = io_worksheet ). + + DATA: path TYPE string, + node TYPE REF TO if_ixml_element, + worksheet TYPE REF TO if_ixml_document, + sheetpr TYPE t_sheetpr. + + +* " Read Workbook codeName +* workbook = me->get_ixml_from_zip_archive( ip_path ). +* node ?= workbook->find_from_name( 'fileVersion' ). +* IF node IS BOUND. +* +* fill_struct_from_attributes( EXPORTING ip_element = node +* CHANGING cp_structure = fileversion ). +* +* IO_WORKSHEET->zif_excel_book_vba_project~set_codename( fileversion-codename ). +* ENDIF. + + " Read Workbook codeName + worksheet = me->get_ixml_from_zip_archive( ip_path ). + node ?= worksheet->find_from_name( 'sheetPr' ). + IF node IS BOUND. + + fill_struct_from_attributes( EXPORTING ip_element = node + CHANGING cp_structure = sheetpr ). + + io_worksheet->zif_excel_sheet_vba_project~set_codename_pr( sheetpr-codename ). + ENDIF. + endmethod. + + + + + + + *"* use this source file for the definition and implementation of +*"* local helper classes, interface definitions and type +*"* declarations + +* Signal "not found" +class lcx_not_found implementation. + method constructor. + super->constructor( textid = textid previous = previous ). + me->error = error. + endmethod. + method if_message~get_text. + result = error. + endmethod. +endclass. + *"* use this source file for any type of declarations (class +*"* definitions, interfaces or type declarations) you need for +*"* components in the private section + +* Signal for "Not found" +class lcx_not_found definition inheriting from cx_static_check. + public section. + data error type string. + methods constructor + importing error type string + textid type sotr_conc optional + previous type ref to cx_root optional. + methods if_message~get_text redefinition. +endclass. + *"* use this source file for any macro definitions you need +*"* in the implementation part of the class + *"* use this source file for your ABAP unit test classes +CLASS lcl_test DEFINITION DEFERRED. +CLASS zcl_excel_reader_huge_file DEFINITION LOCAL FRIENDS lcl_test. + +* +CLASS lcl_test DEFINITION FOR TESTING " #AU Risk_Level Harmless + INHERITING FROM cl_aunit_assert. " #AU Duration Short + + PRIVATE SECTION. + DATA: + out TYPE REF TO zcl_excel_reader_huge_file, " object under test + excel TYPE REF TO zcl_excel, + worksheet TYPE REF TO zcl_excel_worksheet. + METHODS: + setup, + test_number FOR TESTING, + test_shared_string FOR TESTING, + test_shared_string_missing FOR TESTING, + test_inline_string FOR TESTING, + test_boolean FOR TESTING, + test_style FOR TESTING, + test_style_missing FOR TESTING, + test_formula FOR TESTING, + test_read_shared_strings FOR TESTING, + test_skip_to_inexistent FOR TESTING, + get_reader IMPORTING iv_xml TYPE string RETURNING VALUE(eo_reader) TYPE REF TO if_sxml_reader, + assert_value_equals IMPORTING iv_row TYPE i DEFAULT 1 iv_col TYPE i DEFAULT 1 iv_value TYPE string, + assert_formula_equals IMPORTING iv_row TYPE i DEFAULT 1 iv_col TYPE i DEFAULT 1 iv_formula TYPE string, + assert_style_equals IMPORTING iv_row TYPE i DEFAULT 1 iv_col TYPE i DEFAULT 1 iv_style TYPE zexcel_cell_style, + assert_datatype_equals IMPORTING iv_row TYPE i DEFAULT 1 iv_col TYPE i DEFAULT 1 iv_datatype TYPE string. + +ENDCLASS. "lcl_test DEFINITION + +* +CLASS lcl_test IMPLEMENTATION. + +* + METHOD test_number. + DATA lo_reader TYPE REF TO if_sxml_reader. + lo_reader = get_reader( + `<c r="A1" t="n"><v>17</v></c>` + ). + out->read_worksheet_data( io_reader = lo_reader io_worksheet = worksheet ). + assert_value_equals( `17` ). + assert_datatype_equals( `n` ). + ENDMETHOD. "test_shared_string + +* + METHOD test_shared_string. + DATA lo_reader TYPE REF TO if_sxml_reader. + APPEND `Test` TO out->shared_strings. + lo_reader = get_reader( + `<c r="A1" t="s"><v>0</v></c>` + ). + out->read_worksheet_data( io_reader = lo_reader io_worksheet = worksheet ). + assert_value_equals( `Test` ). + assert_datatype_equals( `s` ). + ENDMETHOD. "test_shared_string +* + METHOD test_shared_string_missing. + + DATA: lo_reader TYPE REF TO if_sxml_reader, + lo_ex TYPE REF TO lcx_not_found, + lv_text TYPE string. + lo_reader = get_reader( + `<c r="A1" t="s"><v>0</v></c>` + ). + + TRY. + out->read_worksheet_data( io_reader = lo_reader io_worksheet = worksheet ). + fail(`Index to non-existent shared string should give an error`). + CATCH lcx_not_found INTO lo_ex. + lv_text = lo_ex->get_text( ). " >>> May inspect the message in the debugger + ENDTRY. + + ENDMETHOD. +* + METHOD test_inline_string. + DATA lo_reader TYPE REF TO if_sxml_reader. + lo_reader = get_reader( + `<c r="A1" t="inlineStr"><is><t>Alpha</t></is></c>` + ). + out->read_worksheet_data( io_reader = lo_reader io_worksheet = worksheet ). + assert_value_equals( `Alpha` ). + assert_datatype_equals( `inlineStr` ). + ENDMETHOD. "test_inline_string + +* + METHOD test_boolean. + DATA lo_reader TYPE REF TO if_sxml_reader. + lo_reader = get_reader( + `<c r="A1" t="b"><v>1</v></c>` + ). + out->read_worksheet_data( io_reader = lo_reader io_worksheet = worksheet ). + assert_value_equals( `1` ). + assert_datatype_equals( `b` ). + ENDMETHOD. "test_boolean + +* + METHOD test_formula. + DATA lo_reader TYPE REF TO if_sxml_reader. + lo_reader = get_reader( + `<c r="A1" t="n"><f>A2*A2</f></c>` + ). + out->read_worksheet_data( io_reader = lo_reader io_worksheet = worksheet ). + assert_formula_equals( `A2*A2` ). + assert_datatype_equals( `n` ). + ENDMETHOD. "test_formula + +* + METHOD test_style. + DATA: + lo_reader TYPE REF TO if_sxml_reader, + lo_style TYPE REF TO zcl_excel_style, + lv_guid TYPE zexcel_cell_style. + CREATE OBJECT lo_style. + APPEND lo_style TO out->styles. + lv_guid = lo_style->get_guid( ). + + lo_reader = get_reader( + `<c r="A1" s="0"><v>18</v></c>` + ). + out->read_worksheet_data( io_reader = lo_reader io_worksheet = worksheet ). + + assert_style_equals( lv_guid ). + + ENDMETHOD. "test_style + +* + METHOD test_style_missing. + + DATA: + lo_reader TYPE REF TO if_sxml_reader, + lo_ex TYPE REF TO lcx_not_found, + lv_text TYPE string. + + lo_reader = get_reader( + `<c r="A1" s="0"><v>18</v></c>` + ). + + TRY. + out->read_worksheet_data( io_reader = lo_reader io_worksheet = worksheet ). + fail(`Reference to non-existent style should throw an lcx_not_found exception`). + CATCH lcx_not_found INTO lo_ex. + lv_text = lo_ex->get_text( ). " >>> May inspect the message in the debugger + ENDTRY. + + ENDMETHOD. "test_style + +* + METHOD test_read_shared_strings. + DATA: lo_reader TYPE REF TO if_sxml_reader, + lt_act TYPE stringtab, + lt_exp TYPE stringtab. + lo_reader = cl_sxml_string_reader=>create( cl_abap_codepage=>convert_to( + `<sst><si><t/></si><si><t>Alpha</t></si><si><t>Bravo</t></si></sst>` + ) ). + APPEND : + `` TO lt_exp, + `Alpha` TO lt_exp, + `Bravo` TO lt_exp. + + lt_act = out->read_shared_strings( lo_reader ). + + assert_equals( act = lt_act + exp = lt_exp ). + + ENDMETHOD. + +* + METHOD test_skip_to_inexistent. + DATA: lo_reader TYPE REF TO if_sxml_reader, + lo_ex TYPE REF TO lcx_not_found, + lv_text TYPE string. + + lo_reader = cl_sxml_string_reader=>create( cl_abap_codepage=>convert_to( + `<sst><si><t/></si><si><t>Alpha</t></si><si><t>Bravo</t></si></sst>` + ) ). + TRY. + out->skip_to( iv_element_name = `nonExistingElement` io_reader = lo_reader ). + fail(`Skipping to non-existing element must raise lcx_not_found exception`). + CATCH lcx_not_found INTO lo_ex. + lv_text = lo_ex->get_text( ). " May inspect exception text in debugger + ENDTRY. + ENDMETHOD. + +* + METHOD get_reader. + DATA: lv_full TYPE string. + CONCATENATE `<root><sheetData><row>` iv_xml `</row></sheetData></root>` INTO lv_full. + eo_reader = cl_sxml_string_reader=>create( cl_abap_codepage=>convert_to( lv_full ) ). + ENDMETHOD. "get_reader +* + METHOD assert_value_equals. + + FIELD-SYMBOLS: <ls_cell_data> TYPE zexcel_s_cell_data. + + READ TABLE worksheet->sheet_content ASSIGNING <ls_cell_data> + WITH TABLE KEY cell_row = iv_row cell_column = iv_col. + assert_subrc( sy-subrc ). + + assert_equals( act = <ls_cell_data>-cell_value + exp = iv_value ). + + ENDMETHOD. "assert_value_equals +** + METHOD assert_formula_equals. + + FIELD-SYMBOLS: <ls_cell_data> TYPE zexcel_s_cell_data. + + READ TABLE worksheet->sheet_content ASSIGNING <ls_cell_data> + WITH TABLE KEY cell_row = iv_row cell_column = iv_col. + assert_subrc( sy-subrc ). + + assert_equals( act = <ls_cell_data>-cell_formula + exp = iv_formula ). + + ENDMETHOD. "assert_formula_equals +* + METHOD assert_style_equals. + + FIELD-SYMBOLS: <ls_cell_data> TYPE zexcel_s_cell_data. + + READ TABLE worksheet->sheet_content ASSIGNING <ls_cell_data> + WITH TABLE KEY cell_row = iv_row cell_column = iv_col. + assert_subrc( sy-subrc ). + + assert_equals( act = <ls_cell_data>-cell_style + exp = iv_style ). + + ENDMETHOD. +* + METHOD assert_datatype_equals. + + FIELD-SYMBOLS: <ls_cell_data> TYPE zexcel_s_cell_data. + + READ TABLE worksheet->sheet_content ASSIGNING <ls_cell_data> + WITH TABLE KEY cell_row = iv_row cell_column = iv_col. + assert_subrc( sy-subrc ). + + assert_equals( act = <ls_cell_data>-data_type + exp = iv_datatype ). + + ENDMETHOD. "assert_datatype_equals + METHOD setup. + CREATE OBJECT out. + CREATE OBJECT excel. + CREATE OBJECT worksheet + EXPORTING + ip_excel = excel. + ENDMETHOD. "setup +ENDCLASS. "lcl_test IMPLEMENTATION + + + + + + + + + + + + + + + method FILL_CELL_FROM_ATTRIBUTES. + + while io_reader->node_type ne c_end_of_stream. + io_reader->next_attribute( ). + if io_reader->node_type ne c_attribute. + exit. + endif. + case io_reader->name. + when `t`. + es_cell-datatype = io_reader->value. + when `s`. + if io_reader->value is not initial. + es_cell-style = get_style( io_reader->value ). + endif. + when `r`. + es_cell-coord = get_cell_coord( io_reader->value ). + endcase. + endwhile. + + io_reader->current_node( ). + +endmethod. + + + + + method GET_CELL_COORD. + + zcl_excel_common=>convert_columnrow2column_a_row( + exporting + i_columnrow = iv_coord + importing + e_column = es_coord-column + e_row = es_coord-row + ). + +endmethod. + + + + + + method GET_SHARED_STRING. + data: lv_tabix type i. + lv_tabix = iv_index + 1. + read table shared_strings into ev_value index lv_tabix. + if sy-subrc ne 0. + raise exception type lcx_not_found + exporting + error = |Entry { iv_index } not found in Shared String Table|. + endif. +endmethod. + + + + + + method GET_STYLE. + + data: lv_tabix type i, + lo_style type ref to zcl_excel_style. + + if gs_buffer_style-index ne iv_index. + lv_tabix = iv_index + 1. + read table styles into lo_style index lv_tabix. + if sy-subrc ne 0. + raise exception type lcx_not_found + exporting + error = |Entry { iv_index } not found in Style Table|. + else. + gs_buffer_style-index = iv_index. + gs_buffer_style-guid = lo_style->get_guid( ). + endif. + endif. + + ev_style_guid = gs_buffer_style-guid. + +endmethod. + + + + + + method GET_SXML_READER. + + data: lv_xml type xstring. + + lv_xml = get_from_zip_archive( iv_path ). + eo_reader = cl_sxml_string_reader=>create( lv_xml ). + +endmethod. + + + method LOAD_SHARED_STRINGS. + + data: lo_reader type ref to if_sxml_reader. + + lo_reader = get_sxml_reader( ip_path ). + + shared_strings = read_shared_strings( lo_reader ). + +endmethod. + + + method LOAD_WORKSHEET. + + data: lo_reader type ref to if_sxml_reader. + + lo_reader = get_sxml_reader( ip_path ). + + read_worksheet_data( io_reader = lo_reader + io_worksheet = io_worksheet ). + +endmethod. + + + + + method PUT_CELL_TO_WORKSHEET. + call method io_worksheet->set_cell + exporting + ip_column = is_cell-column + ip_row = is_cell-row + ip_value = is_cell-value + ip_formula = is_cell-formula + ip_data_type = is_cell-datatype + ip_style = is_cell-style. +endmethod. + + + + + method READ_SHARED_STRINGS. + + while io_reader->node_type ne c_end_of_stream. + io_reader->next_node( ). + if io_reader->node_type eq c_element_close and + io_reader->name eq `t`. + append io_reader->value to et_shared_strings. + endif. + endwhile. + +endmethod. + + + + + + method READ_WORKSHEET_DATA. + + data: ls_cell type t_cell. + +* Skip to <sheetData> element + skip_to( iv_element_name = `sheetData` io_reader = io_reader ). + +* Main loop: Evaluate the <c> elements and its children + while io_reader->node_type ne c_end_of_stream. + io_reader->next_node( ). + case io_reader->node_type. + when c_element_open. + if io_reader->name eq `c`. + ls_cell = fill_cell_from_attributes( io_reader ). + endif. + when c_element_close. + case io_reader->name. + when `c`. + put_cell_to_worksheet( is_cell = ls_cell io_worksheet = io_worksheet ). + when `f`. + ls_cell-formula = io_reader->value. + when `v`. + if ls_cell-datatype eq `s`. + ls_cell-value = get_shared_string( ls_cell-value ). + else. + ls_cell-value = io_reader->value. + endif. + when `is`. + ls_cell-value = io_reader->value. + when `sheetData`. + exit. + endcase. + endcase. + endwhile. + +endmethod. + + + + + + method SKIP_TO. + +* Skip forward to given element + while io_reader->name ne iv_element_name or + io_reader->node_type ne c_element_open. + io_reader->next_node( ). + if io_reader->node_type = c_end_of_stream. + raise exception type lcx_not_found + exporting + error = |XML error: Didn't find element <{ iv_element_name }>|. + endif. + endwhile. + + +endmethod. + + + + + + *"* use this source file for the definition and implementation of +*"* local helper classes, interface definitions and type +*"* declarations + *"* use this source file for any type of declarations (class +*"* definitions, interfaces or type declarations) you need for +*"* components in the private section + *"* use this source file for any macro definitions you need +*"* in the implementation part of the class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + method CREATE_AX. + DATA ls_ax TYPE s_ax. + ls_ax-type = ip_type. + + IF ip_type = c_catax. + IF ip_axid IS SUPPLIED. + ls_ax-axid = ip_axid. + ELSE. + ls_ax-axid = '1'. + ENDIF. + IF ip_orientation IS SUPPLIED. + ls_ax-orientation = ip_orientation. + ELSE. + ls_ax-orientation = 'minMax'. + ENDIF. + IF ip_delete IS SUPPLIED. + ls_ax-delete = ip_delete. + ELSE. + ls_ax-delete = '0'. + ENDIF. + IF ip_axpos IS SUPPLIED. + ls_ax-axpos = ip_axpos. + ELSE. + ls_ax-axpos = 'b'. + ENDIF. + IF ip_formatcode IS SUPPLIED. + ls_ax-formatcode = ip_formatcode. + ELSE. + ls_ax-formatcode = 'General'. + ENDIF. + IF ip_sourcelinked IS SUPPLIED. + ls_ax-sourcelinked = ip_sourcelinked. + ELSE. + ls_ax-sourcelinked = '1'. + ENDIF. + IF ip_majortickmark IS SUPPLIED. + ls_ax-majortickmark = ip_majortickmark. + ELSE. + ls_ax-majortickmark = 'out'. + ENDIF. + IF ip_minortickmark IS SUPPLIED. + ls_ax-minortickmark = ip_minortickmark. + ELSE. + ls_ax-minortickmark = 'none'. + ENDIF. + IF ip_ticklblpos IS SUPPLIED. + ls_ax-ticklblpos = ip_ticklblpos. + ELSE. + ls_ax-ticklblpos = 'nextTo'. + ENDIF. + IF ip_crossax IS SUPPLIED. + ls_ax-crossax = ip_crossax. + ELSE. + ls_ax-crossax = '2'. + ENDIF. + IF ip_crosses IS SUPPLIED. + ls_ax-crosses = ip_crosses. + ELSE. + ls_ax-crosses = 'autoZero'. + ENDIF. + IF ip_auto IS SUPPLIED. + ls_ax-auto = ip_auto. + ELSE. + ls_ax-auto = '1'. + ENDIF. + IF ip_lblalgn IS SUPPLIED. + ls_ax-lblalgn = ip_lblalgn. + ELSE. + ls_ax-lblalgn = 'ctr'. + ENDIF. + IF ip_lbloffset IS SUPPLIED. + ls_ax-lbloffset = ip_lbloffset. + ELSE. + ls_ax-lbloffset = '100'. + ENDIF. + IF ip_nomultilvllbl IS SUPPLIED. + ls_ax-nomultilvllbl = ip_nomultilvllbl. + ELSE. + ls_ax-nomultilvllbl = '0'. + ENDIF. + ELSEIF ip_type = c_valax. + IF ip_axid IS SUPPLIED. + ls_ax-axid = ip_axid. + ELSE. + ls_ax-axid = '2'. + ENDIF. + IF ip_orientation IS SUPPLIED. + ls_ax-orientation = ip_orientation. + ELSE. + ls_ax-orientation = 'minMax'. + ENDIF. + IF ip_delete IS SUPPLIED. + ls_ax-delete = ip_delete. + ELSE. + ls_ax-delete = '0'. + ENDIF. + IF ip_axpos IS SUPPLIED. + ls_ax-axpos = ip_axpos. + ELSE. + ls_ax-axpos = 'l'. + ENDIF. + IF ip_formatcode IS SUPPLIED. + ls_ax-formatcode = ip_formatcode. + ELSE. + ls_ax-formatcode = 'General'. + ENDIF. + IF ip_sourcelinked IS SUPPLIED. + ls_ax-sourcelinked = ip_sourcelinked. + ELSE. + ls_ax-sourcelinked = '1'. + ENDIF. + IF ip_majortickmark IS SUPPLIED. + ls_ax-majortickmark = ip_majortickmark. + ELSE. + ls_ax-majortickmark = 'out'. + ENDIF. + IF ip_minortickmark IS SUPPLIED. + ls_ax-minortickmark = ip_minortickmark. + ELSE. + ls_ax-minortickmark = 'none'. + ENDIF. + IF ip_ticklblpos IS SUPPLIED. + ls_ax-ticklblpos = ip_ticklblpos. + ELSE. + ls_ax-ticklblpos = 'nextTo'. + ENDIF. + IF ip_crossax IS SUPPLIED. + ls_ax-crossax = ip_crossax. + ELSE. + ls_ax-crossax = '1'. + ENDIF. + IF ip_crosses IS SUPPLIED. + ls_ax-crosses = ip_crosses. + ELSE. + ls_ax-crosses = 'autoZero'. + ENDIF. + IF ip_crossbetween IS SUPPLIED. + ls_ax-crossbetween = ip_crossbetween. + ELSE. + ls_ax-crossbetween = 'between'. + ENDIF. + ENDIF. + + APPEND ls_ax TO me->axes. + SORT me->axes BY axid ASCENDING. + endmethod. + + + + method SET_SHOW_CAT_NAME. + ns_showcatnameval = ip_value. + endmethod. + + + + method SET_SHOW_LEGEND_KEY. + ns_showlegendkeyval = ip_value. + endmethod. + + + + method SET_SHOW_PERCENT. + ns_showpercentval = ip_value. + endmethod. + + + + method SET_SHOW_SER_NAME. + ns_showsernameval = ip_value. + endmethod. + + + + method SET_SHOW_VALUES. + ns_showvalval = ip_value. + endmethod. + + + + method SET_VARYCOLOR. + ns_varycolorsval = ip_value. + endmethod. + + + + + *"* use this source file for the definition and implementation of +*"* local helper classes, interface definitions and type +*"* declarations + *"* use this source file for any type of declarations (class +*"* definitions, interfaces or type declarations) you need for +*"* components in the private section + *"* use this source file for any macro definitions you need +*"* in the implementation part of the class + + + *"* 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 IF_MESSAGE~GET_LONGTEXT. + + IF me->error IS NOT INITIAL + OR me->syst_at_raise IS NOT INITIAL. +*--------------------------------------------------------------------* +* If message was supplied explicitly use this as longtext as well +*--------------------------------------------------------------------* + result = me->get_text( ). + ELSE. +*--------------------------------------------------------------------* +* otherwise use standard method to derive text +*--------------------------------------------------------------------* + super->if_message~get_longtext( EXPORTING + preserve_newlines = preserve_newlines + RECEIVING + result = result ). + ENDIF. + endmethod. + + + method IF_MESSAGE~GET_TEXT. + + IF me->error IS NOT INITIAL. +*--------------------------------------------------------------------* +* If message was supplied explicitly use this +*--------------------------------------------------------------------* + result = me->error . + ELSEIF me->syst_at_raise IS NOT INITIAL. +*--------------------------------------------------------------------* +* If message was supplied by syst create messagetext now +*--------------------------------------------------------------------* + MESSAGE ID syst_at_raise-msgid TYPE syst_at_raise-msgty NUMBER syst_at_raise-msgno + WITH syst_at_raise-msgv1 syst_at_raise-msgv2 syst_at_raise-msgv3 syst_at_raise-msgv4 + INTO result. + ELSE. +*--------------------------------------------------------------------* +* otherwise use standard method to derive text +*--------------------------------------------------------------------* + CALL METHOD super->if_message~get_text + RECEIVING + result = result. + ENDIF. + endmethod. + + + + *"* 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 CONSTRUCTOR. + endmethod. + + + + method GET_STRUCTURE. +*initialize colors to 'not set' + es_fill-left_color-indexed = zcl_excel_style_color=>c_indexed_not_set. + es_fill-left_color-theme = zcl_excel_style_color=>c_theme_not_set. + es_fill-right_color-indexed = zcl_excel_style_color=>c_indexed_not_set. + es_fill-right_color-theme = zcl_excel_style_color=>c_theme_not_set. + es_fill-top_color-indexed = zcl_excel_style_color=>c_indexed_not_set. + es_fill-top_color-theme = zcl_excel_style_color=>c_theme_not_set. + es_fill-bottom_color-indexed = zcl_excel_style_color=>c_indexed_not_set. + es_fill-bottom_color-theme = zcl_excel_style_color=>c_theme_not_set. + es_fill-diagonal_color-indexed = zcl_excel_style_color=>c_indexed_not_set. + es_fill-diagonal_color-theme = zcl_excel_style_color=>c_theme_not_set. + +* Check if all borders is set otherwise check single border + IF me->allborders IS BOUND. + es_fill-left_color = me->allborders->border_color. + es_fill-left_style = me->allborders->border_style. + es_fill-right_color = me->allborders->border_color. + es_fill-right_style = me->allborders->border_style. + es_fill-top_color = me->allborders->border_color. + es_fill-top_style = me->allborders->border_style. + es_fill-bottom_color = me->allborders->border_color. + es_fill-bottom_style = me->allborders->border_style. + ELSE. + IF me->left IS BOUND. + es_fill-left_color = me->left->border_color. + es_fill-left_style = me->left->border_style. + ENDIF. + IF me->right IS BOUND. + es_fill-right_color = me->right->border_color. + es_fill-right_style = me->right->border_style. + ENDIF. + IF me->top IS BOUND. + es_fill-top_color = me->top->border_color. + es_fill-top_style = me->top->border_style. + ENDIF. + IF me->down IS BOUND. + es_fill-bottom_color = me->down->border_color. + es_fill-bottom_style = me->down->border_style. + ENDIF. + ENDIF. + +* Check if diagonal is set + IF me->diagonal IS BOUND. + es_fill-diagonal_color = me->diagonal->border_color. + es_fill-diagonal_style = me->diagonal->border_style. + CASE me->diagonal_mode. + WHEN 1. + es_fill-diagonalup = 1. + es_fill-diagonaldown = 0. + WHEN 2. + es_fill-diagonalup = 0. + es_fill-diagonaldown = 1. + WHEN 3. + es_fill-diagonalup = 1. + es_fill-diagonaldown = 1. + WHEN OTHERS. + es_fill-diagonalup = 0. + es_fill-diagonaldown = 0. + ENDCASE. + ENDIF. + + endmethod. + + + + *"* use this source file for the definition and implementation of +*"* local helper classes, interface definitions and type +*"* declarations + *"* use this source file for any type of declarations (class +*"* definitions, interfaces or type declarations) you need for +*"* components in the private section + *"* use this source file for any macro definitions you need +*"* in the implementation part of the class + + ABAP + + + + method CONSTRUCTOR. + " default Excel palette based on + " http://msdn.microsoft.com/en-us/library/documentformat.openxml.spreadsheet.indexedcolors.aspx + + APPEND '00000000' TO colors. + APPEND '00FFFFFF' TO colors. + APPEND '00FF0000' TO colors. + APPEND '0000FF00' TO colors. + APPEND '000000FF' TO colors. + APPEND '00FFFF00' TO colors. + APPEND '00FF00FF' TO colors. + APPEND '0000FFFF' TO colors. + APPEND '00000000' TO colors. + APPEND '00FFFFFF' TO colors. + + APPEND '00FF0000' TO colors. + APPEND '0000FF00' TO colors. + APPEND '000000FF' TO colors. + APPEND '00FFFF00' TO colors. + APPEND '00FF00FF' TO colors. + APPEND '0000FFFF' TO colors. + APPEND '00800000' TO colors. + APPEND '00008000' TO colors. + APPEND '00000080' TO colors. + APPEND '00808000' TO colors. + + APPEND '00800080' TO colors. + APPEND '00008080' TO colors. + APPEND '00C0C0C0' TO colors. + APPEND '00808080' TO colors. + APPEND '009999FF' TO colors. + APPEND '00993366' TO colors. + APPEND '00FFFFCC' TO colors. + APPEND '00CCFFFF' TO colors. + APPEND '00660066' TO colors. + APPEND '00FF8080' TO colors. + + APPEND '000066CC' TO colors. + APPEND '00CCCCFF' TO colors. + APPEND '00000080' TO colors. + APPEND '00FF00FF' TO colors. + APPEND '00FFFF00' TO colors. + APPEND '0000FFFF' TO colors. + APPEND '00800080' TO colors. + APPEND '00800000' TO colors. + APPEND '00008080' TO colors. + APPEND '000000FF' TO colors. + + APPEND '0000CCFF' TO colors. + APPEND '00CCFFFF' TO colors. + APPEND '00CCFFCC' TO colors. + APPEND '00FFFF99' TO colors. + APPEND '0099CCFF' TO colors. + APPEND '00FF99CC' TO colors. + APPEND '00CC99FF' TO colors. + APPEND '00FFCC99' TO colors. + APPEND '003366FF' TO colors. + APPEND '0033CCCC' TO colors. + + APPEND '0099CC00' TO colors. + APPEND '00FFCC00' TO colors. + APPEND '00FF9900' TO colors. + APPEND '00FF6600' TO colors. + APPEND '00666699' TO colors. + APPEND '00969696' TO colors. + APPEND '00003366' TO colors. + APPEND '00339966' TO colors. + APPEND '00003300' TO colors. + APPEND '00333300' TO colors. + + APPEND '00993300' TO colors. + APPEND '00993366' TO colors. + APPEND '00333399' TO colors. + APPEND '00333333' TO colors. + + endmethod. + + + + + + method GET_COLOR. + DATA: lv_index type i. + + lv_index = ip_index + 1. + READ TABLE colors INTO ep_color INDEX lv_index. + IF sy-subrc <> 0. + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = 'Invalid color index'. + ENDIF. + endmethod. + + + + method GET_COLORS. + ep_colors = colors. + endmethod. + + + + method IS_MODIFIED. + ep_modified = modified. + endmethod. + + + + + method SET_COLOR. + DATA: lv_index TYPE i. + + FIELD-SYMBOLS: <lv_color> LIKE LINE OF colors. + + lv_index = ip_index + 1. + READ TABLE colors ASSIGNING <lv_color> INDEX lv_index. + IF sy-subrc <> 0. + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = 'Invalid color index'. + ENDIF. + + IF <lv_color> <> ip_color. + modified = abap_true. + <lv_color> = ip_color. + ENDIF. + + endmethod. + + + + *"* use this source file for the definition and implementation of +*"* local helper classes, interface definitions and type +*"* declarations + *"* use this source file for any type of declarations (class +*"* definitions, interfaces or type declarations) you need for +*"* components in the private section + *"* use this source file for any macro definitions you need +*"* in the implementation part of the class + + + *"* 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 CONSTRUCTOR. + + + endmethod. + + + + + + + method CREATE_NEW_ARGB. + + + CONCATENATE zcl_excel_style_color=>c_alpha ip_red ip_green ip_blu INTO ep_color_argb. + + endmethod. + + + + *"* 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 CONSTRUCTOR. + + DATA: ls_iconset TYPE zexcel_conditional_iconset. + ls_iconset-iconset = zcl_excel_style_conditional=>c_iconset_3trafficlights. + ls_iconset-cfvo1_type = zcl_excel_style_conditional=>c_cfvo_type_percent. + ls_iconset-cfvo1_value = '0'. + ls_iconset-cfvo2_type = zcl_excel_style_conditional=>c_cfvo_type_percent. + ls_iconset-cfvo2_value = '20'. + ls_iconset-cfvo3_type = zcl_excel_style_conditional=>c_cfvo_type_percent. + ls_iconset-cfvo3_value = '40'. + ls_iconset-cfvo4_type = zcl_excel_style_conditional=>c_cfvo_type_percent. + ls_iconset-cfvo4_value = '60'. + ls_iconset-cfvo5_type = zcl_excel_style_conditional=>c_cfvo_type_percent. + ls_iconset-cfvo5_value = '80'. + + + me->rule = zcl_excel_style_conditional=>c_rule_none. +* me->iconset->operator = zcl_excel_style_conditional=>c_operator_none. + me->mode_iconset = ls_iconset. + me->priority = 1. + +* inizialize dimension range + me->stop_cell-cell_row = 1. + me->stop_cell-cell_column = 1. + me->start_cell-cell_row = 1. + me->start_cell-cell_column = 1. + endmethod. + + + + method GET_DIMENSION_RANGE. + IF stop_cell EQ start_cell. "only one cell + ep_dimension_range = start_cell-cell_coords. + ELSE. + CONCATENATE start_cell-cell_coords ':' stop_cell-cell_coords INTO ep_dimension_range. + ENDIF. + endmethod. + + + + + + + method SET_RANGE. + DATA: lv_column TYPE zexcel_cell_column, + lv_row_alpha TYPE string. + + lv_column = zcl_excel_common=>convert_column2int( ip_stop_column ). + stop_cell-cell_row = 1. + stop_cell-cell_column = lv_column. + lv_row_alpha = ip_stop_row. + SHIFT lv_row_alpha RIGHT DELETING TRAILING space. + SHIFT lv_row_alpha LEFT DELETING LEADING space. + CONCATENATE ip_stop_column lv_row_alpha INTO stop_cell-cell_coords. + + lv_column = zcl_excel_common=>convert_column2int( ip_start_column ). + start_cell-cell_row = 1. + start_cell-cell_column = lv_column. + lv_row_alpha = ip_start_row. + SHIFT lv_row_alpha RIGHT DELETING TRAILING space. + SHIFT lv_row_alpha LEFT DELETING LEADING space. + CONCATENATE ip_start_column lv_row_alpha INTO start_cell-cell_coords. + endmethod. + + + + *"* 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 CONSTRUCTOR. + filltype = zcl_excel_style_fill=>c_fill_none. + fgcolor-theme = zcl_excel_style_color=>c_theme_not_set. + fgcolor-indexed = zcl_excel_style_color=>c_indexed_not_set. + bgcolor-theme = zcl_excel_style_color=>c_theme_not_set. + bgcolor-indexed = zcl_excel_style_color=>c_indexed_sys_foreground. + rotation = 0. + endmethod. + + + + method GET_STRUCTURE. + es_fill-rotation = me->rotation. + es_fill-filltype = me->filltype. + es_fill-fgColor = me->fgColor. + es_fill-bgColor = me->bgColor. + endmethod. + + + + *"* 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 + + ABAP + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + method CALCULATE_TEXT_WIDTH. + " Addition to solve issue #120, contribution by Stefan Schmöcker + r_width = strlen( i_text ). + " use scale factor based on default 11 + " ( don't know where defaultsetting is stored currently ) + r_width = r_width * me->size / 11. + endmethod. + + + method CONSTRUCTOR. + me->color-rgb = zcl_excel_style_color=>c_black. + me->color-theme = zcl_excel_style_color=>c_theme_not_set. + me->color-indexed = zcl_excel_style_color=>c_indexed_not_set. + me->scheme = zcl_excel_style_font=>c_scheme_minor. + me->underline_mode = zcl_excel_style_font=>c_underline_single. + endmethod. + + + + method GET_STRUCTURE. + + es_font-bold = me->bold. + es_font-italic = me->italic. + es_font-underline = me->underline. + es_font-underline_mode = me->underline_mode. + es_font-strikethrough = me->strikethrough. + es_font-size = me->size. + es_font-color = me->color. + es_font-name = me->name. + es_font-family = me->family. + es_font-scheme = me->scheme. + + endmethod. + + + + *"* 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 CONSTRUCTOR. + format_code = me->c_format_general. + endmethod. + + + + method GET_STRUCTURE. + ep_number_format-numfmt = me->format_code. + endmethod. + + + + *"* 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 CONSTRUCTOR. + locked = me->c_protection_locked. + hidden = me->c_protection_unhidden. + endmethod. + + + + method GET_STRUCTURE. + ep_protection-locked = me->locked. + ep_protection-hidden = me->hidden. + endmethod. + + + + *"* 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 + + ABAP + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + method CONSTRUCTOR. + + endmethod. + + + + method GET_BOTTOM_ROW_INTEGER. + DATA: lv_table_lines TYPE i. + FIELD-SYMBOLS: <fs_table> TYPE STANDARD TABLE. + + IF settings-bottom_right_row IS NOT INITIAL. +* ev_row = zcl_excel_common=>convert_column2int( settings-bottom_right_row ). " del issue #246 + ev_row = settings-bottom_right_row . " ins issue #246 + EXIT. + ENDIF. + + ASSIGN table_data->* TO <fs_table>. + DESCRIBE TABLE <fs_table> LINES lv_table_lines. + IF lv_table_lines = 0. + lv_table_lines = 1. "table needs at least 1 data row + ENDIF. + + ev_row = settings-top_left_row + lv_table_lines. + + IF me->has_totals( ) = abap_true." ???? AND ip_include_totals_row = abap_true. + ADD 1 TO ev_row. + ENDIF. + endmethod. + + + + method GET_ID. + ov_id = id. + endmethod. + + + + method GET_NAME. + + IF me->name IS INITIAL. + me->name = zcl_excel_common=>number_to_excel_string( ip_value = me->id ). + CONCATENATE 'table' me->name INTO me->name. + ENDIF. + + ov_name = me->name. + endmethod. + + + + + method GET_REFERENCE. + DATA: lv_column TYPE zexcel_cell_column, + lv_table_lines TYPE i, + lv_right_column TYPE zexcel_cell_column_alpha, + ls_field_catalog TYPE zexcel_s_fieldcatalog, + lv_bottom_row TYPE zexcel_cell_row, + lv_top_row_string(10) TYPE c, + lv_bottom_row_string(10) TYPE c. + + FIELD-SYMBOLS: <fs_table> TYPE STANDARD TABLE. + +*column + lv_column = zcl_excel_common=>convert_column2int( settings-top_left_column ). + lv_table_lines = 0. + LOOP AT fieldcat INTO ls_field_catalog WHERE dynpfld EQ abap_true. + ADD 1 TO lv_table_lines. + ENDLOOP. + lv_column = lv_column + lv_table_lines - 1. + lv_right_column = zcl_excel_common=>convert_column2alpha( lv_column ). + +*row + ASSIGN table_data->* TO <fs_table>. + DESCRIBE TABLE <fs_table> LINES lv_table_lines. + IF lv_table_lines = 0. + lv_table_lines = 1. "table needs at least 1 data row + ENDIF. + lv_bottom_row = settings-top_left_row + lv_table_lines . + + IF me->has_totals( ) = abap_true AND ip_include_totals_row = abap_true. + ADD 1 TO lv_bottom_row. + ENDIF. + + lv_top_row_string = zcl_excel_common=>number_to_excel_string( settings-top_left_row ). + lv_bottom_row_string = zcl_excel_common=>number_to_excel_string( lv_bottom_row ). + + CONCATENATE settings-top_left_column lv_top_row_string + ':' + lv_right_column lv_bottom_row_string INTO ov_reference. + + endmethod. + + + + + method GET_RIGHT_COLUMN_INTEGER. + DATA: lv_column TYPE zexcel_cell_column, + lv_table_lines TYPE i, + ls_field_catalog TYPE zexcel_s_fieldcatalog. + + IF settings-bottom_right_column IS NOT INITIAL. + ev_column = zcl_excel_common=>convert_column2int( settings-bottom_right_column ). + EXIT. + ENDIF. + + ev_column = zcl_excel_common=>convert_column2int( settings-top_left_column ). + LOOP AT fieldcat INTO ls_field_catalog WHERE dynpfld EQ abap_true. + ADD 1 TO ev_column. + ENDLOOP. + + endmethod. + + + + + + method GET_TOTALS_FORMULA. + CONSTANTS: lc_function_id_sum TYPE string VALUE '109', + lc_function_id_min TYPE string VALUE '105', + lc_function_id_max TYPE string VALUE '104', + lc_function_id_count TYPE string VALUE '103', + lc_function_id_average TYPE string VALUE '101'. + + DATA: lv_function_id TYPE string. + + CASE ip_function. + WHEN zcl_excel_table=>totals_function_sum. + lv_function_id = lc_function_id_sum. + + WHEN zcl_excel_table=>totals_function_min. + lv_function_id = lc_function_id_min. + + WHEN zcl_excel_table=>totals_function_max. + lv_function_id = lc_function_id_max. + + WHEN zcl_excel_table=>totals_function_count. + lv_function_id = lc_function_id_count. + + WHEN zcl_excel_table=>totals_function_average. + lv_function_id = lc_function_id_average. + + WHEN zcl_excel_table=>totals_function_custom. " issue #292 + RETURN. + + WHEN OTHERS. + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = 'Invalid totals formula. See ZCL_ for possible values'. + ENDCASE. + + CONCATENATE 'SUBTOTAL(' lv_function_id ',[' ip_column '])' INTO ep_formula. + endmethod. + + + + method HAS_TOTALS. + DATA: ls_field_catalog TYPE zexcel_s_fieldcatalog. + + ep_result = abap_false. + + LOOP AT fieldcat INTO ls_field_catalog. + IF ls_field_catalog-totals_function IS NOT INITIAL. + ep_result = abap_true. + EXIT. + ENDIF. + ENDLOOP. + + endmethod. + + + + method SET_DATA. + GET REFERENCE OF ir_data INTO me->table_data. + endmethod. + + + + method SET_ID. + id = iv_id. + endmethod. + + + + + + + + *"* local class implementation for public class +*"* use this source file for the implementation part of +*"* local helper classes + +*&---------------------------------------------------------------------* +*& Class (Implementation) C_OI_PROXY_ERROR +*&---------------------------------------------------------------------* +CLASS c_oi_proxy_error IMPLEMENTATION. + METHOD constructor. +* IMPORTING object_name TYPE c +* method_name TYPE c. + error_nr = ret_call_not_flushed. + me->i_oi_error~error_code = c_oi_errors=>ret_call_not_flushed. + me->i_oi_error~is_flushed = ' '. + me->i_oi_error~has_failed = 'X'. + me->i_oi_error~has_succeeded = ' '. + me->message_id = 'SOFFICEINTEGRATION'. + me->message_nr = '899'. + me->param1 = object_name. + me->param2 = method_name. + ENDMETHOD. "constructor + + METHOD i_oi_error~flush_error. + IF error_nr EQ 0. + me->i_oi_error~error_code = c_oi_errors=>ret_ok. + me->i_oi_error~is_flushed = 'X'. + me->i_oi_error~has_failed = ' '. + me->i_oi_error~has_succeeded = 'X'. + me->message_id = ''. + me->message_nr = '000'. + CALL METHOD c_oi_errors=>translate_proxy_error_code + EXPORTING + errorcode = error_nr + IMPORTING + retcode = me->i_oi_error~error_code. + ELSEIF error_nr EQ ret_call_not_flushed. + "call still not flushed + CALL METHOD c_oi_errors=>translate_proxy_error_code + EXPORTING + errorcode = error_nr + errorstring = me->param2 "method name + objectname = me->param1 + IMPORTING + retcode = me->i_oi_error~error_code. + ELSE. + me->i_oi_error~is_flushed = 'X'. + me->i_oi_error~has_succeeded = ' '. + me->i_oi_error~has_failed = 'X'. + CALL METHOD c_oi_errors=>translate_proxy_error_code + EXPORTING + errorcode = error_nr + errorstring = error_string + IMPORTING + retcode = me->i_oi_error~error_code. + CALL METHOD c_oi_errors=>get_message + IMPORTING + message_id = me->message_id + message_number = me->message_nr + param1 = me->param1 + param2 = me->param2 + param3 = me->param3 + param4 = me->param4. + ENDIF. + ENDMETHOD. "i_oi_error~flush_error + + METHOD i_oi_error~raise_message. +* IMPORTING type TYPE c. +* EXCEPTIONS message_raised flush_failed. + IF me->i_oi_error~has_succeeded IS INITIAL. + IF NOT me->i_oi_error~is_flushed IS INITIAL. + MESSAGE ID message_id TYPE type + NUMBER message_nr WITH param1 param2 param3 param4 + RAISING message_raised. + ELSE. + RAISE flush_failed. + ENDIF. + ENDIF. + ENDMETHOD. "i_oi_error~raise_message + + METHOD i_oi_error~get_message. +* EXPORTING message_id TYPE c +* message_number TYPE c +* param1 TYPE c +* param2 TYPE c +* param3 TYPE c +* param4 TYPE c. + param1 = me->param1. param2 = me->param2. + param3 = me->param3. param4 = me->param4. + + message_id = me->message_id. + message_number = me->message_nr. + ENDMETHOD. "i_oi_error~get_message +ENDCLASS. "C_OI_PROXY_ERROR + +*&---------------------------------------------------------------------* +*& Class (Implementation) CL_GRID_ACCESSION +*&---------------------------------------------------------------------* +CLASS lcl_gui_alv_grid IMPLEMENTATION. + + METHOD get_alv_attributes. + CREATE DATA et_table LIKE io_grid->mt_outtab. + et_table = io_grid->mt_outtab. + ENDMETHOD. "get_data + +ENDCLASS. "CL_GRID_ACCESSION + *"* use this source file for any type declarations (class +*"* definitions, interfaces or data types) you need for method +*"* implementation or private method's signature +TYPE-POOLS: sydes. +TYPE-POOLS: slis. +*--------------------------------------------------------------------* +* CLASS c_oi_proxy_error +*--------------------------------------------------------------------* +* use for method bind_ALV +*--------------------------------------------------------------------* +CLASS c_oi_proxy_error DEFINITION. + PUBLIC SECTION. + INTERFACES: i_oi_error. + DATA: error_nr TYPE i. + DATA: error_string TYPE sy-msgv1. + + METHODS: constructor IMPORTING object_name TYPE c + method_name TYPE c. + PRIVATE SECTION. + CONSTANTS: + ret_call_not_flushed TYPE i VALUE -999999. + + DATA: message_id TYPE sy-msgid, + message_nr TYPE sy-msgno, + param1 TYPE sy-msgv1, + param2 TYPE sy-msgv2, + param3 TYPE sy-msgv3, + param4 TYPE sy-msgv4. +ENDCLASS. "c_oi_proxy_error DEFINITION + +*--------------------------------------------------------------------* +* CLASS lcl_gui_alv_grid +*--------------------------------------------------------------------* +* to get protected attribute and method of cl_gui_alv_grid +* use for method bind_ALV +*--------------------------------------------------------------------* +CLASS lcl_gui_alv_grid DEFINITION INHERITING FROM cl_gui_alv_grid. + + PUBLIC SECTION. +* get ALV grid data + METHODS: get_alv_attributes + IMPORTING + io_grid TYPE REF TO cl_gui_alv_grid " ALV grid + EXPORTING + et_table TYPE REF TO data. " dta table + +ENDCLASS. "lcl_gui_alv_grid DEFINITION + *"* use this source file for any macro definitions you need +*"* in the implementation part of the class + + + + + + + + + + + + + + + + + + + + ABAP + SLIS + SOI + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + method ZIF_EXCEL_SHEET_PRINTSETTINGS~CLEAR_PRINT_REPEAT_COLUMNS. + +*--------------------------------------------------------------------* +* adjust internal representation +*--------------------------------------------------------------------* + CLEAR: me->print_title_col_from, + me->print_title_col_to . + + +*--------------------------------------------------------------------* +* adjust corresponding range +*--------------------------------------------------------------------* + me->print_title_set_range( ). + + + endmethod. + + + method ZIF_EXCEL_SHEET_PRINTSETTINGS~CLEAR_PRINT_REPEAT_ROWS. + +*--------------------------------------------------------------------* +* adjust internal representation +*--------------------------------------------------------------------* + CLEAR: me->print_title_row_from, + me->print_title_row_to . + + +*--------------------------------------------------------------------* +* adjust corresponding range +*--------------------------------------------------------------------* + me->print_title_set_range( ). + + + endmethod. + + + method ZIF_EXCEL_SHEET_PRINTSETTINGS~GET_PRINT_REPEAT_COLUMNS. + ev_columns_from = me->print_title_col_from. + ev_columns_to = me->print_title_col_to. + endmethod. + + + method ZIF_EXCEL_SHEET_PRINTSETTINGS~GET_PRINT_REPEAT_ROWS. + ev_rows_from = me->print_title_row_from. + ev_rows_to = me->print_title_row_to. + endmethod. + + + method ZIF_EXCEL_SHEET_PRINTSETTINGS~SET_PRINT_REPEAT_COLUMNS. +*--------------------------------------------------------------------* +* issue#235 - repeat rows/columns +* - Stefan Schmöcker, 2012-12-02 +*--------------------------------------------------------------------* + + DATA: lv_col_from_int TYPE i, + lv_col_to_int TYPE i, + lv_errormessage TYPE string. + + DATA: lo_range_iterator TYPE REF TO cl_object_collection_iterator, + lo_range TYPE REF TO zcl_excel_range. + + + lv_col_from_int = zcl_excel_common=>convert_column2int( iv_columns_from ). + lv_col_to_int = zcl_excel_common=>convert_column2int( iv_columns_to ). + +*--------------------------------------------------------------------* +* Check if valid range is supplied +*--------------------------------------------------------------------* + IF lv_col_from_int < 1. + lv_errormessage = 'Invalid range supplied for print-title repeatable columns'(401). + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = lv_errormessage. + ENDIF. + + IF lv_col_from_int > lv_col_to_int. + lv_errormessage = 'Invalid range supplied for print-title repeatable columns'(401). + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = lv_errormessage. + ENDIF. + +*--------------------------------------------------------------------* +* adjust internal representation +*--------------------------------------------------------------------* + me->print_title_col_from = iv_columns_from. + me->print_title_col_to = iv_columns_to. + + +*--------------------------------------------------------------------* +* adjust corresponding range +*--------------------------------------------------------------------* + me->print_title_set_range( ). + + endmethod. + + + method ZIF_EXCEL_SHEET_PRINTSETTINGS~SET_PRINT_REPEAT_ROWS. +*--------------------------------------------------------------------* +* issue#235 - repeat rows/columns +* - Stefan Schmöcker, 2012-12-02 +*--------------------------------------------------------------------* + + DATA: lv_errormessage TYPE string. + + DATA: lo_range_iterator TYPE REF TO cl_object_collection_iterator, + lo_range TYPE REF TO zcl_excel_range. + + + +*--------------------------------------------------------------------* +* Check if valid range is supplied +*--------------------------------------------------------------------* + IF iv_rows_from < 1. + lv_errormessage = 'Invalid range supplied for print-title repeatable rowumns'(401). + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = lv_errormessage. + ENDIF. + + IF iv_rows_from > iv_rows_to. + lv_errormessage = 'Invalid range supplied for print-title repeatable rowumns'(401). + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = lv_errormessage. + ENDIF. + +*--------------------------------------------------------------------* +* adjust internal representation +*--------------------------------------------------------------------* + me->print_title_row_from = iv_rows_from. + me->print_title_row_to = iv_rows_to. + + +*--------------------------------------------------------------------* +* adjust corresponding range +*--------------------------------------------------------------------* + me->print_title_set_range( ). + + + 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. + + zif_excel_sheet_properties~show_zeros = zif_excel_sheet_properties=>c_showzero. + zif_excel_sheet_properties~summarybelow = zif_excel_sheet_properties=>c_below_on. + zif_excel_sheet_properties~summaryright = zif_excel_sheet_properties=>c_right_on. + +* inizialize zoomscale values + ZIF_EXCEL_SHEET_PROPERTIES~zoomscale = 100. + ZIF_EXCEL_SHEET_PROPERTIES~zoomscale_normal = 100. + ZIF_EXCEL_SHEET_PROPERTIES~zoomscale_pagelayoutview = 100 . + ZIF_EXCEL_SHEET_PROPERTIES~zoomscale_sheetlayoutview = 100 . + endmethod. + + + method ZIF_EXCEL_SHEET_PROPERTIES~SET_STYLE. + zif_excel_sheet_properties~style = ip_style. + endmethod. + + + method ZIF_EXCEL_SHEET_PROTECTION~INITIALIZE. + + me->zif_excel_sheet_protection~protected = zif_excel_sheet_protection=>c_unprotected. + CLEAR me->zif_excel_sheet_protection~password. + me->zif_excel_sheet_protection~auto_filter = zif_excel_sheet_protection=>c_noactive. + me->zif_excel_sheet_protection~delete_columns = zif_excel_sheet_protection=>c_noactive. + me->zif_excel_sheet_protection~delete_rows = zif_excel_sheet_protection=>c_noactive. + me->zif_excel_sheet_protection~format_cells = zif_excel_sheet_protection=>c_noactive. + me->zif_excel_sheet_protection~format_columns = zif_excel_sheet_protection=>c_noactive. + me->zif_excel_sheet_protection~format_rows = zif_excel_sheet_protection=>c_noactive. + me->zif_excel_sheet_protection~insert_columns = zif_excel_sheet_protection=>c_noactive. + me->zif_excel_sheet_protection~insert_hyperlinks = zif_excel_sheet_protection=>c_noactive. + me->zif_excel_sheet_protection~insert_rows = zif_excel_sheet_protection=>c_noactive. + me->zif_excel_sheet_protection~objects = zif_excel_sheet_protection=>c_noactive. +* me->zif_excel_sheet_protection~password = zif_excel_sheet_protection=>c_noactive. "issue #68 + me->zif_excel_sheet_protection~pivot_tables = zif_excel_sheet_protection=>c_noactive. + me->zif_excel_sheet_protection~protected = zif_excel_sheet_protection=>c_noactive. + me->zif_excel_sheet_protection~scenarios = zif_excel_sheet_protection=>c_noactive. + me->zif_excel_sheet_protection~select_locked_cells = zif_excel_sheet_protection=>c_noactive. + me->zif_excel_sheet_protection~select_unlocked_cells = zif_excel_sheet_protection=>c_noactive. + me->zif_excel_sheet_protection~sheet = zif_excel_sheet_protection=>c_noactive. + me->zif_excel_sheet_protection~sort = zif_excel_sheet_protection=>c_noactive. + + endmethod. + + + method ZIF_EXCEL_SHEET_VBA_PROJECT~SET_CODENAME. + me->zif_excel_sheet_vba_project~codename = ip_codename. + endmethod. + + + method ZIF_EXCEL_SHEET_VBA_PROJECT~SET_CODENAME_PR. + me->zif_excel_sheet_vba_project~codename_pr = ip_codename_pr. + endmethod. + + + + method ADD_DRAWING. + CASE ip_drawing->get_type( ). + WHEN zcl_excel_drawing=>type_image. + drawings->include( ip_drawing ). + WHEN zcl_excel_drawing=>type_chart. + charts->include( ip_drawing ). + ENDCASE. + endmethod. + + + + method ADD_NEW_CONDITIONAL_STYLE. + + CREATE OBJECT eo_conditional_style. + conditional_styles->add( eo_conditional_style ). + endmethod. + + + + method ADD_NEW_DATA_VALIDATION. + + CREATE OBJECT eo_data_validation. + data_validations->add( eo_data_validation ). + endmethod. + + + + method ADD_NEW_RANGE. +* Create default blank range + CREATE OBJECT eo_range. + ranges->add( eo_range ). + endmethod. + + + + + + + + + method BIND_ALV. + data: lo_converter type ref to zcl_excel_converter. + + create object lo_converter. + + try. + lo_converter->convert( + exporting + io_alv = io_alv + it_table = it_table + i_row_int = i_top + i_column_int = i_left + i_table = abap_true + i_style_table = table_style + io_worksheet = me + changing + co_excel = excel ). + catch zcx_excel . + endtry. + + endmethod. + + + + + + + + + + + + + + + + + + + + + + method BIND_ALV_OLE2. +*--------------------------------------------------------------------* +* Method description: +* Method use to export a CL_GUI_ALV_GRID object to xlsx/xls file +* with list header and characteristics of ALV field catalog such as: +* + Total, group's subtotal +* + Quantity fields, amount fields (dependent fields) +* + No_out, no_zero, ... +* Technique use in method: +* SAP Desktop Office Integration (DOI) +*--------------------------------------------------------------------* + +* Data for session 0: DOI constructor +* ------------------------------------------ + + data: lo_control type ref to I_OI_CONTAINER_CONTROL. + data: lo_proxy type ref to I_OI_DOCUMENT_PROXY. + data: lo_spreadsheet type ref to I_OI_SPREADSHEET. + data: lo_error type ref to I_OI_ERROR. + data: lc_retcode type SOI_RET_STRING. + data: li_has type i. "Proxy has spreadsheet interface? + data: l_is_closed type i. + +* Data for session 1: Get LVC data from ALV object +* ------------------------------------------ + + data: l_has_activex, + l_doctype_excel_sheet(11) type c. + data: wa_DOC_HANDLE Type CNTL_HANDLE. + +* LVC + data: lt_fieldcat_lvc type LVC_T_FCAT. + data: wa_fieldcat_lvc type lvc_s_fcat. + data: lt_sort_lvc type LVC_T_SORT. + data: lt_filter_idx_lvc type LVC_T_FIDX. + data: lt_GROUPLEVELS_LVC type LVC_T_GRPL. + +* KKBLO + DATA: LT_FIELDCAT_KKBLO Type KKBLO_T_FIELDCAT. + DATA: LT_SORT_KKBLO Type KKBLO_T_SORTINFO. + DATA: LT_GROUPLEVELS_KKBLO Type KKBLO_T_GROUPLEVELS. + DATA: LT_FILTER_IDX_KKBLO Type KKBLO_T_SFINFO. + data: wa_listheader like line of it_listheader. + +* Subtotal + data: lt_collect00 type ref to data. + data: lt_collect01 type ref to data. + data: lt_collect02 type ref to data. + data: lt_collect03 type ref to data. + data: lt_collect04 type ref to data. + data: lt_collect05 type ref to data. + data: lt_collect06 type ref to data. + data: lt_collect07 type ref to data. + data: lt_collect08 type ref to data. + data: lt_collect09 type ref to data. + +* data table name + data: l_tabname type kkblo_tabname. + +* local object + data: lo_grid type ref to lcl_gui_alv_grid. + +* data table get from ALV + data: lt_alv type ref to data. + +* total / subtotal data + field-symbols: <f_collect00> type standard table. + field-symbols: <f_collect01> type standard table. + field-symbols: <f_collect02> type standard table. + field-symbols: <f_collect03> type standard table. + field-symbols: <f_collect04> type standard table. + field-symbols: <f_collect05> type standard table. + field-symbols: <f_collect06> type standard table. + field-symbols: <f_collect07> type standard table. + field-symbols: <f_collect08> type standard table. + field-symbols: <f_collect09> type standard table. + +* table before append subtotal lines + field-symbols: <f_alv_tab> type standard table. + +* data for session 2: sort, filter and calculate total/subtotal +* ------------------------------------------ + +* table to save index of subotal / total line in excel tanle +* this ideal to control index of subtotal / total line later +* for ex, when get subtotal / total line to format + types: begin of st_subtot_indexs, + index type i, + end of st_subtot_indexs. + data: lt_subtot_indexs type table of st_subtot_indexs. + data: wa_subtot_indexs like line of lt_subtot_indexs. + +* data table after append subtotal + data: lt_excel type ref to data. + + data: l_tabix type i. + data: l_save_index type i. + +* dyn subtotal table name + data: l_collect type string. + +* subtotal range, to format subtotal (and total) + data: subranges type soi_range_list. + data: subrangeitem type soi_range_item. + data: l_sub_index type i. + + +* table after append subtotal lines + field-symbols: <f_excel_tab> type standard table. + field-symbols: <f_excel_line> type any. + +* dyn subtotal tables + field-symbols: <f_collect_tab> type standard table. + field-symbols: <f_collect_line> type any. + + field-symbols: <f_filter_idx_line> like line of LT_FILTER_IDX_KKBLO. + field-symbols: <f_fieldcat_line> like line of LT_FIELDCAT_KKBLO. + field-symbols: <f_grouplevels_line> like line of LT_GROUPLEVELS_KKBLO. + field-symbols: <f_line> type any. + +* Data for session 3: map data to semantic table +* ------------------------------------------ + + types: begin of st_column_index, + fieldname type kkblo_fieldname, + tabname type kkblo_tabname, + col like sy-index, + end of st_column_index. + +* columns index + data: lt_column_index type table of st_column_index. + data: wa_column_index like line of lt_column_index. + +* table of dependent field ( currency and quantity unit field) + data: lt_fieldcat_depf type kkblo_t_fieldcat. + data: wa_fieldcat_depf type kkblo_fieldcat. + +* XXL interface: +* -XXL: contain exporting columns characteristic + data: lt_sema type table of gxxlt_s initial size 0. + data: wa_sema like line of lt_sema. + +* -XXL interface: header + data: lt_hkey type table of gxxlt_h initial size 0. + data: wa_hkey like line of lt_hkey. + +* -XXL interface: header keys + data: lt_vkey type table of gxxlt_v initial size 0. + data: wa_vkey like line of lt_vkey. + +* Number of H Keys: number of key columns + data: l_n_hrz_keys type i. +* Number of data columns in the list object: non-key columns no + data: l_n_att_cols type i. +* Number of V Keys: number of header row + data: l_n_vrt_keys type i. + +* curency to format amount + data: lt_tcurx type table of tcurx. + data: wa_tcurx like line of lt_tcurx. + data: l_def type flag. " currency / quantity flag + data: wa_t006 type t006. " decimal place of unit + + data: l_num type i. " table columns number + data: l_typ type c. " table type + data: wa type ref to data. + data: l_int type i. + data: l_counter type i. + + field-symbols: <f_excel_column> type any. + field-symbols: <f_fcat_column> type any. + +* Data for session 4: write to excel +* ------------------------------------------ + + data: data_starting_at type i value 1. + data: data_ending_at type i value -1. + data: sema_type type c. + + data l_error type ref to c_oi_proxy_error. + data count type i. + data datac type i. + data datareal type i. " exporting column number + data vkeycount type i. + data all type i. + data mit type i value 1. " index of recent row? + data li_col_pos type i value 1. " column position + data li_col_num type i. " table columns number + field-symbols: <line> type any. + field-symbols: <item> type any. + + data td type sydes_desc. + + data: typ. + data: ranges type soi_range_list. + data: rangeitem type soi_range_item. + data: contents type soi_generic_table. + data: contentsitem type soi_generic_item. + data: semaitem type gxxlt_s. + data: hkeyitem type gxxlt_h. + data: vkeyitem type gxxlt_v. + data: li_commentary_rows type i. "row number of title lines + 1 + data: lo_error_w type ref to i_oi_error. + data: l_retcode type soi_ret_string. + data: no_flush type c value 'X'. + data: li_head_top type i. "header rows position + +* Data for session 5: Save and clode document +* ------------------------------------------ + + data: li_document_size type i. + data: ls_path type RLGRAP-FILENAME. + +* MACRO: Close_document +*------------------------------------------- + + DEFINE close_document. + clear: l_is_closed. + IF lo_proxy is not initial. + +* check proxy detroyed adi + + call method lo_proxy->is_destroyed + IMPORTING + ret_value = l_is_closed. + +* if dun detroyed yet: close -> release proxy + + IF l_is_closed is initial. + call method lo_proxy->close_document +* EXPORTING +* do_save = do_save + IMPORTING + error = lo_error + retcode = lc_retcode. + ENDIF. + + call method lo_proxy->release_document + IMPORTING + error = lo_error + retcode = lC_retcode. + + else. + lc_retcode = c_oi_errors=>ret_document_not_open. + ENDIF. + +* Detroy control container + + IF lo_control is not initial. + CALL METHOD lo_control->destroy_control. + ENDIF. + + clear: + lo_spreadsheet, + lo_proxy, + lo_control. + +* free local + + clear: l_is_closed. + + END-OF-DEFINITION. + +* Macro to catch DOI error +*------------------------------------------- + + DEFINE error_doi. + if lc_retcode ne c_oi_errors=>ret_ok. + close_document. + call method lo_error->raise_message + EXPORTING + type = 'E'. + clear: lo_error. + endif. + END-OF-DEFINITION. + +*--------------------------------------------------------------------* +* SESSION 0: DOI CONSTRUCTOR +*--------------------------------------------------------------------* + +* check active windown + + call function 'GUI_HAS_ACTIVEX' + IMPORTING + return = l_has_activex. + + if l_has_activex is initial. + raise MISS_GUIDE. + endif. + +* Get Container Object of Screen + + call method c_oi_container_control_creator=>get_container_control + IMPORTING + control = lo_control + retcode = lC_retcode. + + error_doi. + +* Initialize Container control + + CALL METHOD lo_control->init_control + EXPORTING + parent = CL_GUI_CONTAINER=>DEFAULT_SCREEN + r3_application_name = '' + inplace_enabled = 'X' + no_flush = 'X' + register_on_close_event = 'X' + register_on_custom_event = 'X' + IMPORTING + error = lO_ERROR + retcode = lc_retcode. + + error_doi. + +* Get Proxy Document: +* check exist of document proxy, if exist -> close first + + if not lo_proxy is initial. + close_document. + endif. + + IF i_xls is not initial. +* xls format, doctype = soi_doctype_excel97_sheet + l_doctype_excel_sheet = 'Excel.Sheet.8'. + else. +* xlsx format, doctype = soi_doctype_excel_sheet + l_doctype_excel_sheet = 'Excel.Sheet'. + ENDIF. + + CALL METHOD lo_control->get_document_proxy + EXPORTING + document_type = l_doctype_excel_sheet + register_container = 'X' + IMPORTING + document_proxy = lo_proxy + error = lO_ERROR + retcode = lc_retcode. + + error_doi. + + IF I_DOCUMENT_URL is initial. + +* create new excel document + + call method lo_proxy->create_document + EXPORTING + create_view_data = 'X' + open_inplace = 'X' + no_flush = 'X' + IMPORTING + ERROR = lO_ERROR + retcode = lc_retcode. + + error_doi. + + else. + +* Read excel template for i_DOCUMENT_URL +* this excel template can be store in local or server + + CALL METHOD lo_proxy->open_document + EXPORTING + document_url = i_document_url + open_inplace = 'X' + no_flush = 'X' + IMPORTING + error = lo_error + retcode = lc_retcode. + + error_doi. + + endif. + +* Check Spreadsheet Interface of Document Proxy + + CALL METHOD lo_proxy->has_spreadsheet_interface + IMPORTING + is_available = li_has + error = lO_ERROR + retcode = lc_retcode. + + error_doi. + +* create Spreadsheet object + + CHECK li_has IS NOT INITIAL. + + CALL METHOD lo_proxy->get_spreadsheet_interface + IMPORTING + sheet_interface = lo_spreadsheet + error = lO_ERROR + retcode = lc_retcode. + + error_doi. + +*--------------------------------------------------------------------* +* SESSION 1: GET LVC DATA FROM ALV OBJECT +*--------------------------------------------------------------------* + +* data table + + create object lo_grid + EXPORTING + i_parent = CL_GUI_CONTAINER=>SCREEN0. + + call method lo_grid->get_alv_attributes + EXPORTING + io_grid = io_alv + IMPORTING + Et_table = lt_alv. + + assign lt_alv->* to <f_alv_tab>. + +* fieldcat + + CALL METHOD iO_alv->GET_FRONTEND_FIELDCATALOG + IMPORTING + ET_FIELDCATALOG = lt_fieldcat_LVC. + +* table name + + loop at lt_fieldcat_LVC into wa_fieldcat_lvc + where not tabname is initial. + l_tabname = wa_fieldcat_lvc-tabname. + exit. + endloop. + + if sy-subrc ne 0. + l_tabname = '1'. + endif. + clear: wa_fieldcat_lvc. + +* sort table + + CALL METHOD IO_ALV->GET_SORT_CRITERIA + IMPORTING + ET_SORT = lt_sort_lvc. + + +* filter index + + CALL METHOD IO_ALV->GET_FILTERED_ENTRIES + IMPORTING + ET_FILTERED_ENTRIES = lt_filter_idx_lvc. + +* group level + subtotal + + CALL METHOD IO_ALV->GET_SUBTOTALS + IMPORTING + EP_COLLECT00 = lt_collect00 + EP_COLLECT01 = lt_collect01 + EP_COLLECT02 = lt_collect02 + EP_COLLECT03 = lt_collect03 + EP_COLLECT04 = lt_collect04 + EP_COLLECT05 = lt_collect05 + EP_COLLECT06 = lt_collect06 + EP_COLLECT07 = lt_collect07 + EP_COLLECT08 = lt_collect08 + EP_COLLECT09 = lt_collect09 + ET_GROUPLEVELS = lt_GROUPLEVELS_LVC. + + assign lt_collect00->* to <f_collect00>. + assign lt_collect01->* to <f_collect01>. + assign lt_collect02->* to <f_collect02>. + assign lt_collect03->* to <f_collect03>. + assign lt_collect04->* to <f_collect04>. + assign lt_collect05->* to <f_collect05>. + assign lt_collect06->* to <f_collect06>. + assign lt_collect07->* to <f_collect07>. + assign lt_collect08->* to <f_collect08>. + assign lt_collect09->* to <f_collect09>. + +* transfer to KKBLO struct + + CALL FUNCTION 'LVC_TRANSFER_TO_KKBLO' + EXPORTING + IT_FIELDCAT_LVC = lt_fieldcat_lvc + IT_SORT_LVC = lt_sort_lvc + IT_FILTER_INDEX_LVC = lt_filter_idx_lvc + IT_GROUPLEVELS_LVC = lt_grouplevels_lvc + IMPORTING + ET_FIELDCAT_KKBLO = lt_fieldcat_kkblo + ET_SORT_KKBLO = lt_sort_kkblo + ET_FILTERED_ENTRIES_KKBLO = lt_filter_idx_kkblo + ET_GROUPLEVELS_KKBLO = lt_grouplevels_kkblo + TABLES + IT_DATA = <f_alv_tab> + EXCEPTIONS + IT_DATA_MISSING = 1 + IT_FIELDCAT_LVC_MISSING = 2 + OTHERS = 3. + IF SY-SUBRC <> 0. + raise ex_transfer_KKBLO_ERROR. + ENDIF. + + clear: + wa_fieldcat_lvc, + lt_fieldcat_lvc, + lt_sort_lvc, + lt_filter_idx_lvc, + lt_GROUPLEVELS_LVC. + + clear: + lo_grid. + + +*--------------------------------------------------------------------* +* SESSION 2: SORT, FILTER AND CALCULATE TOTAL / SUBTOTAL +*--------------------------------------------------------------------* + +* append subtotal & total line + + create data lt_excel like <f_ALV_TAB>. + assign lt_excel->* to <f_excel_tab>. + + loop at <f_alv_tab> assigning <f_line>. + l_save_index = sy-tabix. + +* filter base on filter index table + + read table LT_FILTER_IDX_KKBLO assigning <f_filter_idx_line> + with key index = l_save_index + binary search. + if sy-subrc ne 0. + append <f_line> to <f_excel_tab>. + endif. + +* append subtotal lines + + read table LT_GROUPLEVELS_KKBLO assigning <f_grouplevels_line> + with key index_to = l_save_index + binary search. + if sy-subrc = 0. + l_tabix = sy-tabix. + do. + if <f_grouplevels_line>-subtot eq 'X' and + <f_grouplevels_line>-hide_level is initial and + <f_grouplevels_line>-cindex_from ne 0. + +* dynamic append subtotal line to excel table base on grouplevel table +* ex <f_GROUPLEVELS_line>-level = 1 +* then <f_collect_tab> = '<F_COLLECT01>' + + l_collect = <f_grouplevels_line>-level. + condense l_collect. + concatenate '<F_COLLECT0' + l_collect '>' +* '->*' + into l_collect. + + assign (l_collect) to <f_collect_tab>. + +* incase there're more than 1 total line of group, at the same level +* for example: subtotal of multi currency + + LOOP AT <f_collect_tab> assigning <f_collect_line>. + IF sy-tabix between <f_grouplevels_line>-cindex_from + and <f_grouplevels_line>-cindex_to. + + + append <f_collect_line> to <f_excel_tab>. + +* save subtotal lines index + + wa_subtot_indexs-index = sy-tabix. + append wa_subtot_indexs to lt_subtot_indexs. + +* append sub total ranges table for format later + + add 1 to l_sub_index. + subrangeitem-name = l_sub_index. + condense subrangeitem-name. + concatenate 'SUBTOT' + subrangeitem-name + into subrangeitem-name. + + subrangeitem-rows = wa_subtot_indexs-index. + subrangeitem-columns = 1. " start col + append subrangeitem to subranges. + clear: subrangeitem. + + ENDIF. + ENDLOOP. + unassign: <f_collect_tab>. + unassign: <f_collect_line>. + clear: l_collect. + endif. + +* check next subtotal level of group + + unassign: <f_grouplevels_line>. + add 1 to l_tabix. + + read table LT_GROUPLEVELS_KKBLO assigning <f_grouplevels_line> + index l_tabix. + if sy-subrc ne 0 + or <f_grouplevels_line>-index_to ne l_save_index. + exit. + endif. + + unassign: + <f_collect_tab>, + <f_collect_line>. + + enddo. + endif. + + clear: + l_tabix, + l_save_index. + + unassign: + <f_filter_idx_line>, + <f_grouplevels_line>. + + endloop. + +* free local data + + unassign: + <f_line>, + <f_collect_tab>, + <f_collect_line>, + <f_fieldcat_line>. + +* append grand total line + + IF <f_collect00> is assigned. + assign <f_collect00> to <f_collect_tab>. + if <f_collect_tab> is not initial. + LOOP AT <f_collect_tab> assigning <f_collect_line>. + + append <f_collect_line> to <f_excel_tab>. + +* save total line index + + wa_subtot_indexs-index = sy-tabix. + append wa_subtot_indexs to lt_subtot_indexs. + +* append grand total range (to format) + + add 1 to l_sub_index. + subrangeitem-name = l_sub_index. + condense subrangeitem-name. + concatenate 'TOTAL' + subrangeitem-name + into subrangeitem-name. + + subrangeitem-rows = wa_subtot_indexs-index. + subrangeitem-columns = 1. " start col + append subrangeitem to subranges. + ENDLOOP. + endif. + ENDIF. + + clear: + subrangeitem, + LT_SORT_KKBLO, + <f_collect00>, + <f_collect01>, + <f_collect02>, + <f_collect03>, + <f_collect04>, + <f_collect05>, + <f_collect06>, + <f_collect07>, + <f_collect08>, + <f_collect09>. + + unassign: + <f_collect00>, + <f_collect01>, + <f_collect02>, + <f_collect03>, + <f_collect04>, + <f_collect05>, + <f_collect06>, + <f_collect07>, + <f_collect08>, + <f_collect09>, + <f_collect_tab>, + <f_collect_line>. + +*--------------------------------------------------------------------* +* SESSION 3: MAP DATA TO SEMANTIC TABLE +*--------------------------------------------------------------------* + +* get dependent field field: currency and quantity + + create data wa like line of <f_excel_tab>. + assign wa->* to <f_excel_line>. + + describe field <f_excel_line> type l_typ components l_num. + + do l_num times. + l_save_index = sy-index. + assign component l_save_index of structure <f_excel_line> + to <f_excel_column>. + if sy-subrc ne 0. + message e059(0k) with 'FATAL ERROR' raising fatal_error. + endif. + + loop at LT_FIELDCAT_KKBLO assigning <f_fieldcat_line> + where tabname = l_tabname. + assign component <f_fieldcat_line>-fieldname + of structure <f_excel_line> to <f_fcat_column>. + + describe distance between <f_excel_column> and <f_fcat_column> + into l_int in byte mode. + +* append column index +* this columns index is of table, not fieldcat + + if l_int = 0. + wa_column_index-fieldname = <f_fieldcat_line>-fieldname. + wa_column_index-tabname = <f_fieldcat_line>-tabname. + wa_column_index-col = l_save_index. + append wa_column_index to lt_column_index. + endif. + +* append dependent fields (currency and quantity unit) + + if <f_fieldcat_line>-cfieldname is not initial. + clear wa_fieldcat_depf. + wa_fieldcat_depf-fieldname = <f_fieldcat_line>-cfieldname. + wa_fieldcat_depf-tabname = <f_fieldcat_line>-ctabname. + collect wa_fieldcat_depf into lt_fieldcat_depf. + endif. + + if <f_fieldcat_line>-qfieldname is not initial. + clear wa_fieldcat_depf. + wa_fieldcat_depf-fieldname = <f_fieldcat_line>-qfieldname. + wa_fieldcat_depf-tabname = <f_fieldcat_line>-qtabname. + collect wa_fieldcat_depf into lt_fieldcat_depf. + endif. + +* rewrite field data type + + if <f_fieldcat_line>-inttype = 'X' + and <f_fieldcat_line>-datatype(3) = 'INT'. + <f_fieldcat_line>-inttype = 'I'. + endif. + + endloop. + + clear: l_save_index. + unassign: <f_fieldcat_line>. + + enddo. + +* build semantic tables + + l_n_hrz_keys = 1. + +* Get keyfigures + + loop at LT_FIELDCAT_KKBLO assigning <f_fieldcat_line> + where tabname = l_tabname + and tech ne 'X' + and no_out ne 'X'. + + clear wa_sema. + clear wa_hkey. + +* Units belong to keyfigures -> display as str + + read table lt_fieldcat_depf into wa_fieldcat_depf with key + fieldname = <f_fieldcat_line>-fieldname + tabname = <f_fieldcat_line>-tabname. + + if sy-subrc = 0. + wa_sema-col_typ = 'STR'. + wa_sema-col_ops = 'DFT'. + +* Keyfigures + + else. + case <f_fieldcat_line>-datatype. + when 'QUAN'. + wa_sema-col_typ = 'N03'. + + if <f_fieldcat_line>-no_sum ne 'X'. + wa_sema-col_ops = 'ADD'. + else. + wa_sema-col_ops = 'NOP'. " no dependent field + endif. + + when 'DATS'. + wa_sema-col_typ = 'DAT'. + wa_sema-col_ops = 'NOP'. + + when 'CHAR' OR 'UNIT' OR 'CUKY'. " Added fieldformats UNIT and CUKY - dd. 26-10-2012 Wouter Heuvelmans + wa_sema-col_typ = 'STR'. + wa_sema-col_ops = 'DFT'. " dependent field + +* incase numeric, ex '00120' -> display as '12' + + when 'NUMC'. + wa_sema-col_typ = 'STR'. + wa_sema-col_ops = 'DFT'. + + when others. + wa_sema-col_typ = 'NUM'. + + if <f_fieldcat_line>-no_sum ne 'X'. + wa_sema-col_ops = 'ADD'. + else. + wa_sema-col_ops = 'NOP'. + endif. + endcase. + endif. + + l_counter = l_counter + 1. + l_n_att_cols = l_n_att_cols + 1. + + wa_sema-col_no = l_counter. + + read table lt_column_index into wa_column_index with key + fieldname = <f_fieldcat_line>-fieldname + tabname = <f_fieldcat_line>-tabname. + + if sy-subrc = 0. + wa_sema-col_src = wa_column_index-col. + else. + raise fatal_error. + endif. + +* columns index of ref currency field in table + + if not <f_fieldcat_line>-cfieldname is initial. + read table lt_column_index into wa_column_index with key + fieldname = <f_fieldcat_line>-cfieldname + tabname = <f_fieldcat_line>-ctabname. + + if sy-subrc = 0. + wa_sema-col_cur = wa_column_index-col. + endif. + +* quantities fields +* treat as currency when display on excel + + elseif not <f_fieldcat_line>-qfieldname is initial. + read table lt_column_index into wa_column_index with key + fieldname = <f_fieldcat_line>-qfieldname + tabname = <f_fieldcat_line>-qtabname. + if sy-subrc = 0. + wa_sema-col_cur = wa_column_index-col. + endif. + + endif. + +* Treat of fixed currency in the fieldcatalog for column + + data: l_num_help(2) type n. + + if not <f_fieldcat_line>-currency is initial. + + select * from tcurx into table lt_tcurx. + sort lt_tcurx. + read table lt_tcurx into wa_tcurx + with key currkey = <f_fieldcat_line>-currency. + if sy-subrc = 0. + l_num_help = wa_tcurx-currdec. + concatenate 'N' l_num_help into wa_sema-col_typ. + wa_sema-col_cur = sy-tabix * ( -1 ). + endif. + + endif. + + wa_hkey-col_no = l_n_att_cols. + wa_hkey-row_no = l_n_hrz_keys. + wa_hkey-col_name = <f_fieldcat_line>-reptext. + append wa_hkey to lt_hkey. + append wa_sema to lt_sema. + + endloop. + +* free local data + + clear: + lt_column_index, + wa_column_index, + lt_fieldcat_depf, + wa_fieldcat_depf, + lt_tcurx, + wa_tcurx, + l_num, + l_typ, + wa, + l_int, + l_counter. + + unassign: + <f_fieldcat_line>, + <f_excel_line>, + <f_excel_column>, + <f_fcat_column>. + +*--------------------------------------------------------------------* +* SESSION 4: WRITE TO EXCEL +*--------------------------------------------------------------------* + + clear: wa_tcurx. + refresh: lt_tcurx. + +* if spreadsheet dun have proxy yet + + if li_has is initial. + l_retcode = c_oi_errors=>ret_interface_not_supported. + call method c_oi_errors=>create_error_for_retcode + EXPORTING + retcode = l_retcode + no_flush = no_flush + IMPORTING + error = lo_error_w. + exit. + endif. + + create object l_error + EXPORTING + object_name = 'OLE_DOCUMENT_PROXY' + method_name = 'get_ranges_names'. + + call method c_oi_errors=>add_error + EXPORTING + error = l_error. + + + describe table lt_sema lines datareal. + describe table <f_excel_tab> lines datac. + describe table lt_vkey lines vkeycount. + + if datac = 0. + raise inv_data_range. + endif. + + + if vkeycount ne l_n_vrt_keys. + raise dim_mismatch_vkey. + endif. + + all = l_n_vrt_keys + l_n_att_cols. + + if datareal ne all. + raise dim_mismatch_sema. + endif. + + data: decimal type c. + +* get decimal separator format ('.', ',', ...) in Office config + + call method lo_proxy->get_application_property + EXPORTING + property_name = 'INTERNATIONAL' + subproperty_name = 'DECIMAL_SEPARATOR' + CHANGING + retvalue = decimal. + + data: wa_usr type usr01. + select * from usr01 into wa_usr where bname = sy-uname. + endselect. + + data: comma_elim(4) type c. + data: help6 type i. + field-symbols <g> type any. + data search_item(4) value ' #'. + + concatenate ',' decimal '.' decimal into comma_elim. + + data help type i. " table (with subtotal) line number + + help = datac. + + data: rowmax type i value 1. " header row number + data: columnmax type i value 0. " header columns number + + loop at lt_hkey into hkeyitem. + if hkeyitem-col_no > columnmax. + columnmax = hkeyitem-col_no. + endif. + + if hkeyitem-row_no > rowmax. + rowmax = hkeyitem-row_no. + endif. + endloop. + + data: hkeycolumns type i. " header columns no + + hkeycolumns = columnmax. + + if hkeycolumns < l_n_att_cols. + hkeycolumns = l_n_att_cols. + endif. + + columnmax = 0. + + loop at lt_vkey into vkeyitem. + if vkeyitem-col_no > columnmax. + columnmax = vkeyitem-col_no. + endif. + endloop. + + data overflow type i value 1. + data testname(10) type c. + data temp2 type i. " 1st item row position in excel + data realmit type i value 1. + data realoverflow type i value 1. " row index in content + + call method lo_spreadsheet->screen_update + EXPORTING + updating = ''. + + call method lo_spreadsheet->load_lib. + + data: str(40) type c. " range names of columns range (w/o col header) + data: rows type i. " row postion of 1st item line in ecxel + +* calculate row position of data table + + describe table iT_LISTHEADER lines li_commentary_rows. + +* if grid had title, add 1 empy line between title and table + + if li_commentary_rows ne 0. + add 1 to li_commentary_rows. + endif. + +* add top position of block data + + li_commentary_rows = li_commentary_rows + i_top - 1. + +* write header (commentary rows) + + data: li_commentary_row_index type i value 1. + data: li_content_index type i value 1. + data: ls_index(10) type c. + data ls_commentary_range(40) type c value 'TITLE'. + data: li_font_bold type i. + data: li_font_italic type i. + data: li_font_size type i. + + loop at iT_LISTHEADER into wa_listheader. + li_commentary_row_index = i_top + li_content_index - 1. + ls_index = li_content_index. + condense ls_index. + concatenate ls_commentary_range(5) ls_index + into ls_commentary_range. + condense ls_commentary_range. + +* insert title range + + call method lo_spreadsheet->insert_range_dim + EXPORTING + name = ls_commentary_range + top = li_commentary_row_index + left = i_left + rows = 1 + columns = 1 + no_flush = no_flush. + +* format range + + case wa_listheader-typ. + when 'H'. "title + li_font_size = 16. + li_font_bold = 1. + li_font_italic = -1. + when 'S'. "subtile + li_font_size = -1. + li_font_bold = 1. + li_font_italic = -1. + when others. "'A' comment + li_font_size = -1. + li_font_bold = -1. + li_font_italic = 1. + endcase. + + call method lo_spreadsheet->set_font + EXPORTING + rangename = ls_commentary_range + family = '' + size = li_font_size + bold = li_font_bold + italic = li_font_italic + align = 0 + no_flush = no_flush. + +* title: range content + + rangeitem-name = ls_commentary_range. + rangeitem-columns = 1. + rangeitem-rows = 1. + append rangeitem to ranges. + + contentsitem-row = li_content_index. + contentsitem-column = 1. + concatenate wa_listheader-key + wa_listheader-info + into contentsitem-value + separated by space. + condense contentsitem-value. + append contentsitem to contents. + + add 1 to li_content_index. + + clear: + rangeitem, + contentsitem, + ls_index. + + endloop. + +* set range data title + + call method lo_spreadsheet->set_ranges_data + EXPORTING + ranges = ranges + contents = contents + no_flush = no_flush. + + refresh: + ranges, + contents. + + rows = rowmax + li_commentary_rows + 1. + + all = wa_usr-datfm. + all = all + 3. + + loop at lt_sema into semaitem. + if semaitem-col_typ = 'DAT' or semaitem-col_typ = 'MON' or + semaitem-col_typ = 'N00' or semaitem-col_typ = 'N01' or + semaitem-col_typ = 'N01' or semaitem-col_typ = 'N02' or + semaitem-col_typ = 'N03' or semaitem-col_typ = 'PCT' or + semaitem-col_typ = 'STR' or semaitem-col_typ = 'NUM'. + clear str. + str = semaitem-col_no. + condense str. + concatenate 'DATA' str into str. + mit = semaitem-col_no. + li_col_pos = semaitem-col_no + i_left - 1. + +* range from data1 to data(n), for each columns of table + + call method lo_spreadsheet->insert_range_dim + EXPORTING + name = str + top = rows + left = li_col_pos + rows = help + columns = 1 + no_flush = no_flush. + + data dec type i value -1. + data typeinfo type sydes_typeinfo. + loop at <f_excel_tab> assigning <line>. + assign component semaitem-col_no of structure <line> to <item>. + describe field <item> into td. + read table td-types index 1 into typeinfo. + if typeinfo-type = 'P'. + dec = typeinfo-decimals. + elseif typeinfo-type = 'I'. + dec = 0. + endif. + + describe field <line> type typ components count. + mit = 1. + do count times. + if mit = semaitem-col_src. + assign component sy-index of structure <line> to <item>. + describe field <item> into td. + read table td-types index 1 into typeinfo. + if typeinfo-type = 'P'. + dec = typeinfo-decimals. + endif. + exit. + endif. + mit = mit + 1. + enddo. + exit. + endloop. + +* format for each columns of table (w/o columns headers) + + if semaitem-col_typ = 'DAT'. + if semaitem-col_no > vkeycount. + call method lo_spreadsheet->set_format + EXPORTING + rangename = str + currency = '' + typ = all + no_flush = no_flush. + else. + call method lo_spreadsheet->set_format + EXPORTING + rangename = str + currency = '' + typ = 0 + no_flush = no_flush. + endif. + elseif semaitem-col_typ = 'STR'. + call method lo_spreadsheet->set_format + EXPORTING + rangename = str + currency = '' + typ = 0 + no_flush = no_flush. + elseif semaitem-col_typ = 'MON'. + call method lo_spreadsheet->set_format + EXPORTING + rangename = str + currency = '' + typ = 10 + no_flush = no_flush. + elseif semaitem-col_typ = 'N00'. + call method lo_spreadsheet->set_format + EXPORTING + rangename = str + currency = '' + typ = 1 + decimals = 0 + no_flush = no_flush. + elseif semaitem-col_typ = 'N01'. + call method lo_spreadsheet->set_format + EXPORTING + rangename = str + currency = '' + typ = 1 + decimals = 1 + no_flush = no_flush. + elseif semaitem-col_typ = 'N02'. + call method lo_spreadsheet->set_format + EXPORTING + rangename = str + currency = '' + typ = 1 + decimals = 2 + no_flush = no_flush. + elseif semaitem-col_typ = 'N03'. + call method lo_spreadsheet->set_format + EXPORTING + rangename = str + currency = '' + typ = 1 + decimals = 3 + no_flush = no_flush. + elseif semaitem-col_typ = 'N04'. + call method lo_spreadsheet->set_format + EXPORTING + rangename = str + currency = '' + typ = 1 + decimals = 4 + no_flush = no_flush. + elseif semaitem-col_typ = 'NUM'. + if dec eq -1. + call method lo_spreadsheet->set_format + EXPORTING + rangename = str + currency = '' + typ = 1 + decimals = 2 + no_flush = no_flush. + else. + call method lo_spreadsheet->set_format + EXPORTING + rangename = str + currency = '' + typ = 1 + decimals = dec + no_flush = no_flush. + endif. + elseif semaitem-col_typ = 'PCT'. + call method lo_spreadsheet->set_format + EXPORTING + rangename = str + currency = '' + typ = 3 + decimals = 0 + no_flush = no_flush. + endif. + + endif. + endloop. + +* get item contents for set_range_data method +* get currency cell also + + mit = 1. + + data: currcells type soi_cell_table. + data: curritem type soi_cell_item. + + curritem-rows = 1. + curritem-columns = 1. + curritem-front = -1. + curritem-back = -1. + curritem-font = ''. + curritem-size = -1. + curritem-bold = -1. + curritem-italic = -1. + curritem-align = -1. + curritem-frametyp = -1. + curritem-framecolor = -1. + curritem-currency = ''. + curritem-number = 1. + curritem-input = -1. + + data: conv_exit(10) type c. + data: const type i. + +* Change for Correction request +* Initial 10000 lines are missing in Excel Export +* if there are only 2 columns in exported List object. + + if datareal gt 2. + const = 20000 / datareal. + else. + const = 20000 / ( datareal + 2 ). + endif. + + data: lines type i. + data: innerlines type i. + data: counter type i. + data: curritem2 like curritem. + data: curritem3 like curritem. + data: length type i. + data: found. + +* append content table (for method set_range_content) + + loop at <f_excel_tab> assigning <line>. + +* save line index to compare with lt_subtot_indexs, +* to discover line is a subtotal / totale line or not +* ex use to set 'dun display zero in subtotal / total line' + + l_save_index = sy-tabix. + + do datareal times. + read table lt_sema into semaitem with key col_no = sy-index. + if semaitem-col_src ne 0. + assign component semaitem-col_src + of structure <line> to <item>. + else. + assign component sy-index + of structure <line> to <item>. + endif. + + contentsitem-row = realoverflow. + + if sy-subrc = 0. + move semaitem-col_ops to search_item(3). + search 'ADD#CNT#MIN#MAX#AVG#NOP#DFT#' + for search_item. + if sy-subrc ne 0. + raise error_in_sema. + endif. + move semaitem-col_typ to search_item(3). + search 'NUM#N00#N01#N02#N03#N04#PCT#DAT#MON#STR#' + for search_item. + if sy-subrc ne 0. + raise error_in_sema. + endif. + contentsitem-column = sy-index. + if semaitem-col_typ eq 'DAT' or semaitem-col_typ eq 'MON'. + if semaitem-col_no > vkeycount. + + " Hinweis 512418 + " EXCEL bezieht Datumsangaben + " auf den 31.12.1899, behandelt + " aber 1900 als ein Schaltjahr + " d.h. ab 1.3.1900 korrekt + " 1.3.1900 als Zahl = 61 + + data: genesis type d value '18991230'. + data: number_of_days type p. +* change for date in char format & sema_type = X + data: temp_date type d. + + if not <item> is initial and not <item> co ' ' and not + <item> co '0'. +* change for date in char format & sema_type = X starts + if sema_type = 'X'. + describe field <item> type typ. + if typ = 'C'. + temp_date = <item>. + number_of_days = temp_date - genesis. + else. + number_of_days = <item> - genesis. + endif. + else. + number_of_days = <item> - genesis. + endif. +* change for date in char format & sema_type = X ends + if number_of_days < 61. + number_of_days = number_of_days - 1. + endif. + + set country 'DE'. + write number_of_days to contentsitem-value + no-grouping + left-justified. + set country space. + translate contentsitem-value using comma_elim. + else. + clear contentsitem-value. + endif. + else. + move <item> to contentsitem-value. + endif. + elseif semaitem-col_typ eq 'NUM' or + semaitem-col_typ eq 'N00' or + semaitem-col_typ eq 'N01' or + semaitem-col_typ eq 'N02' or + semaitem-col_typ eq 'N03' or + semaitem-col_typ eq 'N04' or + semaitem-col_typ eq 'PCT'. + set country 'DE'. + describe field <item> type typ. + + if semaitem-col_cur is initial. + if typ ne 'F'. + write <item> to contentsitem-value no-grouping + no-sign decimals 14. + else. + write <item> to contentsitem-value no-grouping + no-sign. + endif. + else. +* Treat of fixed curreny for column >>Y9CK007319 + if semaitem-col_cur < 0. + semaitem-col_cur = semaitem-col_cur * ( -1 ). + select * from tcurx into table lt_tcurx. + sort lt_tcurx. + read table lt_tcurx into + wa_tcurx index semaitem-col_cur. + if sy-subrc = 0. + if typ ne 'F'. + write <item> to contentsitem-value no-grouping + currency wa_tcurx-currkey no-sign decimals 14. + else. + write <item> to contentsitem-value no-grouping + currency wa_tcurx-currkey no-sign. + endif. + endif. + else. + assign component semaitem-col_cur + of structure <line> to <g>. +* mit = index of recent row + curritem-top = rowmax + mit + li_commentary_rows. + + li_col_pos = sy-index + i_left - 1. + curritem-left = li_col_pos. + +* if filed is quantity field (qfieldname ne space) +* or amount field (cfieldname ne space), then format decimal place +* corresponding with config + + clear: l_def. + read table LT_FIELDCAT_KKBLO assigning <f_fieldcat_line> + with key tabname = l_tabname + tech = space + no_out = space + col_pos = semaitem-col_no. + IF sy-subrc = 0. + IF <f_fieldcat_line>-cfieldname is not initial. + l_def = 'C'. + else."if <f_fieldcat_line>-qfieldname is not initial. + l_def = 'Q'. + ENDIF. + ENDIF. + +* if field is amount field +* exporting of amount field base on currency decimal table: TCURX + IF l_def = 'C'. "field is amount field + select single * from tcurx into wa_tcurx + where currkey = <g>. +* if amount ref to un-know currency -> default decimal = 2 + if sy-subrc eq 0. + curritem-decimals = wa_tcurx-currdec. + else. + curritem-decimals = 2. + endif. + + append curritem to currcells. + if typ ne 'F'. + write <item> to contentsitem-value + currency <g> + no-sign no-grouping. + else. + write <item> to contentsitem-value + decimals 14 currency <g> + no-sign no-grouping. + endif. + +* if field is quantity field +* exporting of quantity field base on quantity decimal table: T006 + + else."if l_def = 'Q'. " field is quantity field + clear: wa_t006. + select single * from t006 into wa_t006 + where MSEHI = <g>. +* if quantity ref to un-know unit-> default decimal = 2 + if sy-subrc eq 0. + curritem-decimals = wa_t006-decan. + else. + curritem-decimals = 2. + endif. + append curritem to currcells. + + write <item> to contentsitem-value + unit <g> + no-sign no-grouping. + condense contentsitem-value. + + ENDIF. + + endif. "Y9CK007319 + endif. + condense contentsitem-value. + +* add function fieldcat-no zero display + + loop at LT_FIELDCAT_KKBLO assigning <f_fieldcat_line> + where tabname = l_tabname + and tech ne 'X' + and no_out ne 'X'. + if <f_fieldcat_line>-col_pos = semaitem-col_no. + if <f_fieldcat_line>-no_zero = 'X'. + if <item> = '0'. + clear: contentsitem-value. + endif. + +* dun display zero in total/subtotal line too + + else. + clear: wa_subtot_indexs. + read table lt_subtot_indexs into wa_subtot_indexs + with key index = l_save_index. + IF sy-subrc = 0. + if <item> = '0'. + clear: contentsitem-value. + endif. + ENDIF. + endif. + endif. + endloop. + unassign: <f_fieldcat_line>. + + if <item> lt 0. + search contentsitem-value for 'E'. + if sy-fdpos eq 0. + +* bring negative sign to front of amount + + translate contentsitem-value using '- '. + condense contentsitem-value no-gaps. + concatenate '-' contentsitem-value + into contentsitem-value. + else. + concatenate '-' contentsitem-value + into contentsitem-value. + endif. + endif. + set country space. +* Hier wird nur die korrekte Kommaseparatierung gemacht, wenn die +* Zeichen einer +* Zahl enthalten sind. Das ist f#ƒÂ#r Timestamps, die auch ":" enthalten. +* F#ƒÂ#r die +* darf keine Kommaseparierung stattfinden. +* Changing for correction request - Y6BK041073 + if contentsitem-value co '0123456789.,-+E '. + translate contentsitem-value using comma_elim. + endif. + else. + clear contentsitem-value. + +* if type is not numeric -> dun display with zero + + write <item> to contentsitem-value no-zero. + + shift contentsitem-value left deleting leading space. + + endif. + append contentsitem to contents. + endif. + enddo. + + realmit = realmit + 1. + realoverflow = realoverflow + 1. + + mit = mit + 1. +* overflow = current row index in content table + overflow = overflow + 1. + endloop. + + unassign: <f_fieldcat_line>. + +* set item range for set_range_data method + + testname = mit / const. + condense testname. + + concatenate 'TEST' testname into testname. + + realoverflow = realoverflow - 1. + realmit = realmit - 1. + help = realoverflow. + + rangeitem-name = testname. + rangeitem-columns = datareal. + rangeitem-rows = help. + append rangeitem to ranges. + +* insert item range dim + + temp2 = rowmax + 1 + li_commentary_rows + realmit - realoverflow. + +* items data + + call method lo_spreadsheet->insert_range_dim + EXPORTING + name = testname + top = temp2 + left = i_left + rows = help + columns = datareal + no_flush = no_flush. + +* get columns header contents for set_range_data method +* export columns header only if no columns header option = space + + data: rowcount type i. + data: columncount type i. + + if i_columns_header = 'X'. + +* append columns header to contents: hkey + + rowcount = 1. + do rowmax times. + columncount = 1. + do hkeycolumns times. + loop at lt_hkey into hkeyitem where col_no = columncount + and row_no = rowcount. + endloop. + if sy-subrc = 0. + str = hkeyitem-col_name. + contentsitem-value = hkeyitem-col_name. + else. + contentsitem-value = str. + endif. + contentsitem-column = columncount. + contentsitem-row = rowcount. + append contentsitem to contents. + columncount = columncount + 1. + enddo. + rowcount = rowcount + 1. + enddo. + +* incase columns header in multiline + + data: rowmaxtemp type i. + if rowmax > 1. + rowmaxtemp = rowmax - 1. + rowcount = 1. + do rowmaxtemp times. + columncount = 1. + do columnmax times. + contentsitem-column = columncount. + contentsitem-row = rowcount. + contentsitem-value = ''. + append contentsitem to contents. + columncount = columncount + 1. + enddo. + rowcount = rowcount + 1. + enddo. + endif. + +* append columns header to contents: vkey + + columncount = 1. + do columnmax times. + loop at lt_vkey into vkeyitem where col_no = columncount. + endloop. + contentsitem-value = vkeyitem-col_name. + contentsitem-row = rowmax. + contentsitem-column = columncount. + append contentsitem to contents. + columncount = columncount + 1. + enddo. +*--------------------------------------------------------------------* +* set header range for method set_range_data +* insert header keys range dim + + li_head_top = li_commentary_rows + 1. + li_col_pos = i_left. + +* insert range headers + + if hkeycolumns ne 0. + rangeitem-name = 'TESTHKEY'. + rangeitem-rows = rowmax. + rangeitem-columns = hkeycolumns. + append rangeitem to ranges. + clear: rangeitem. + + call method lo_spreadsheet->insert_range_dim + EXPORTING + name = 'TESTHKEY' + top = li_head_top + left = li_col_pos + rows = rowmax + columns = hkeycolumns + no_flush = no_flush. + endif. + endif. + +* format for columns header + total + subtotal +* ------------------------------------------ + + help = rowmax + realmit. " table + header lines + + data: item type colxxl_t. + data: lt_format type soi_format_table. + data: wa_format like line of lt_format. + data: wa_format_temp like line of lt_format. + + field-symbols: <f_source> type any. + field-symbols: <f_des> type any. + +* columns header format + + wa_format-front = -1. + wa_format-back = 15. "grey + wa_format-font = space. + wa_format-size = -1. + wa_format-bold = 1. + wa_format-align = 0. + wa_format-frametyp = -1. + wa_format-framecolor = -1. + +* get column header format from input record +* -> map input format + + if i_columns_header = 'X'. + wa_format-name = 'TESTHKEY'. + if i_format_col_header is not initial. + describe field i_format_col_header type l_typ components + li_col_num. + do li_col_num times. + if sy-index ne 1. " dun map range name + assign component sy-index of structure i_format_col_header + to <f_source>. + if <f_source> is not initial. + assign component sy-index of structure wa_format to <f_des>. + <f_des> = <f_source>. + unassign: <f_des>. + endif. + unassign: <f_source>. + endif. + enddo. + + clear: li_col_num. + endif. + + append wa_format to lt_format. + endif. + +* Zusammenfassen der Spalten mit gleicher Nachkommastellenzahl +* collect vertical cells (col) with the same number of decimal places +* to increase perfomance in currency cell format + + describe table currcells lines lines. + lines = lines - 1. + do lines times. + describe table currcells lines innerlines. + innerlines = innerlines - 1. + sort currcells by left top. + clear found. + do innerlines times. + read table currcells index sy-index into curritem. + counter = sy-index + 1. + read table currcells index counter into curritem2. + if curritem-left eq curritem2-left. + length = curritem-top + curritem-rows. + if length eq curritem2-top. + if curritem-decimals eq curritem2-decimals. + move curritem to curritem3. + curritem3-rows = curritem3-rows + curritem2-rows. + curritem-left = -1. + modify currcells index sy-index from curritem. + curritem2-left = -1. + modify currcells index counter from curritem2. + append curritem3 to currcells. + found = 'X'. + endif. + endif. + endif. + enddo. + if found is initial. + exit. + endif. + delete currcells where left = -1. + enddo. + +* Zusammenfassen der Zeilen mit gleicher Nachkommastellenzahl +* collect horizontal cells (row) with the same number of decimal places +* to increase perfomance in currency cell format + + describe table currcells lines lines. + lines = lines - 1. + do lines times. + describe table currcells lines innerlines. + innerlines = innerlines - 1. + sort currcells by top left. + clear found. + do innerlines times. + read table currcells index sy-index into curritem. + counter = sy-index + 1. + read table currcells index counter into curritem2. + if curritem-top eq curritem2-top and curritem-rows eq + curritem2-rows. + length = curritem-left + curritem-columns. + if length eq curritem2-left. + if curritem-decimals eq curritem2-decimals. + move curritem to curritem3. + curritem3-columns = curritem3-columns + curritem2-columns. + curritem-left = -1. + modify currcells index sy-index from curritem. + curritem2-left = -1. + modify currcells index counter from curritem2. + append curritem3 to currcells. + found = 'X'. + endif. + endif. + endif. + enddo. + if found is initial. + exit. + endif. + delete currcells where left = -1. + enddo. +* Ende der Zusammenfassung + + +* item data: format for currency cell, corresponding with currency + + call method lo_spreadsheet->cell_format + EXPORTING + cells = currcells + no_flush = no_flush. + +* item data: write item table content + + call method lo_spreadsheet->set_ranges_data + EXPORTING + ranges = ranges + contents = contents + no_flush = no_flush. + +* whole table range to format all table + + if i_columns_header = 'X'. + li_head_top = li_commentary_rows + 1. + else. + li_head_top = li_commentary_rows + 2. + help = help - 1. + endif. + + call method lo_spreadsheet->insert_range_dim + EXPORTING + name = 'WHOLE_TABLE' + top = li_head_top + left = i_left + rows = help + columns = datareal + no_flush = no_flush. + +* columns width auto fix +* this parameter = space in case use with exist template + + IF i_columns_autofit = 'X'. + call method lo_spreadsheet->fit_widest + EXPORTING + name = 'WHOLE_TABLE' + no_flush = no_flush. + ENDIF. + +* frame +* The parameter has 8 bits +*0 Left margin +*1 Top marginT +*2 Bottom margin +*3 Right margin +*4 Horizontal line +*5 Vertical line +*6 Thinness +*7 Thickness +* here 127 = 1111111 6-5-4-3-2-1 mean Thin-ver-hor-right-bot-top-left + +* ( final DOI method call, set no_flush = space +* equal to call method CL_GUI_CFW=>FLUSH ) + + call method lo_spreadsheet->set_frame + EXPORTING + rangename = 'WHOLE_TABLE' + typ = 127 + color = 1 + no_flush = space + IMPORTING + error = lo_error + retcode = lc_retcode. + + error_doi. + +* reformat subtotal / total line after format wholw table + + loop at subranges into subrangeitem. + l_sub_index = subrangeitem-rows + li_commentary_rows + rowmax. + + call method lo_spreadsheet->insert_range_dim + EXPORTING + name = subrangeitem-name + left = i_left + top = l_sub_index + rows = 1 + columns = datareal + no_flush = no_flush. + + wa_format-name = subrangeitem-name. + +* default format: +* - clolor: subtotal = light yellow, subtotal = yellow +* - frame: box + + IF subrangeitem-name(3) = 'SUB'. + wa_format-back = 36. "subtotal line + wa_format_temp = i_format_subtotal. + else. + wa_format-back = 27. "total line + wa_format_temp = i_format_total. + endif. + wa_format-FRAMETYP = 79. + wa_format-FRAMEcolor = 1. + wa_format-number = -1. + wa_format-align = -1. + +* get subtoal + total format from intput parameter +* overwrite default format + + if wa_format_temp is not initial. + describe field wa_format_temp type l_typ components li_col_num. + do li_col_num times. + if sy-index ne 1. " dun map range name + assign component sy-index of structure wa_format_temp + to <f_source>. + if <f_source> is not initial. + assign component sy-index of structure wa_format to <f_des>. + <f_des> = <f_source>. + unassign: <f_des>. + endif. + unassign: <f_source>. + endif. + enddo. + + clear: li_col_num. + endif. + + append wa_format to lt_format. + clear: wa_format-name. + clear: l_sub_index. + clear: wa_format_temp. + + endloop. + + if lt_format[] is not initial. + call method lo_spreadsheet->set_ranges_format + EXPORTING + formattable = lt_format + no_flush = no_flush. + refresh: lt_format. + endif. +*--------------------------------------------------------------------* + call method lo_spreadsheet->screen_update + EXPORTING + updating = 'X'. + + call method c_oi_errors=>flush_errors. + + lo_error_w = l_error. + lc_retcode = lo_error_w->error_code. + +** catch no_flush -> led to dump ( optional ) +* go_error = l_error. +* gc_retcode = go_error->error_code. +* error_doi. + + clear: + lt_sema, + wa_sema, + lt_hkey, + wa_hkey, + lt_vkey, + wa_vkey, + l_n_hrz_keys, + l_n_att_cols, + l_n_vrt_keys, + count, + datac, + datareal, + vkeycount, + all, + mit, + li_col_pos, + li_col_num, + ranges, + rangeitem, + contents, + contentsitem, + semaitem, + hkeyitem, + vkeyitem, + li_commentary_rows, + l_retcode, + li_head_top, + <f_excel_tab>. + + clear: + lo_error_w. + + unassign: + <line>, + <item>, + <f_excel_tab>. + +*--------------------------------------------------------------------* +* SESSION 5: SAVE AND CLOSE FILE +*--------------------------------------------------------------------* + +* ex of save path: 'FILE://C:\temp\test.xlsx' + concatenate 'FILE://' I_save_path + into ls_path. + + call method lo_proxy->save_document_to_url + EXPORTING + no_flush = 'X' + url = ls_path + IMPORTING + error = lo_error + retcode = lc_retcode + CHANGING + document_size = li_document_size. + + error_doi. + +* if save successfully -> raise successful message +* message i499(sy) with 'Document is Exported to ' p_path. + message i499(sy) with 'Data has been exported successfully'. + + clear: + ls_path, + li_document_size. + + close_document. + endmethod. + + + + + + + + method BIND_TABLE. +*--------------------------------------------------------------------* +* issue #230 - Pimp my Code +* - Stefan Schmöcker, (wi p) 2012-12-01 +* - ... +* aligning code +* message made to support multilinguality +*--------------------------------------------------------------------* +* issue #237 - Check if overlapping areas exist +* - Alessandro Iannacci 2012-12-01 +* changes: - Added raise if overlaps are detected +*--------------------------------------------------------------------* + + CONSTANTS: + lc_top_left_column TYPE zexcel_cell_column_alpha VALUE 'B', + lc_top_left_row TYPE zexcel_cell_row VALUE '3'. + + DATA: + lv_row_int TYPE zexcel_cell_row, + lv_first_row TYPE zexcel_cell_row, + lv_last_row TYPE zexcel_cell_row, + lv_column_int TYPE zexcel_cell_column, + lv_column_alpha TYPE zexcel_cell_column_alpha, + lt_field_catalog TYPE zexcel_t_fieldcatalog, + lv_id TYPE i, + lv_rows TYPE i, + lv_formula TYPE string, + ls_settings TYPE zexcel_s_table_settings, + lo_table TYPE REF TO zcl_excel_table, + lt_column_name_buffer TYPE SORTED TABLE OF string WITH UNIQUE KEY table_line, + lv_value TYPE string, + lv_syindex TYPE char3, + lv_errormessage TYPE string, "ins issue #237 + + lv_columns TYPE i, + lt_columns TYPE zexcel_t_fieldcatalog, + lv_maxcol TYPE i, + lv_maxrow TYPE i, + lo_iterator TYPE REF TO cl_object_collection_iterator, + lo_curtable TYPE REF TO zcl_excel_table. + + FIELD-SYMBOLS: + <ls_field_catalog> TYPE zexcel_s_fieldcatalog, + <ls_field_catalog_custom> TYPE zexcel_s_fieldcatalog, + <fs_table_line> TYPE ANY, + <fs_fldval> TYPE ANY. + + ls_settings = is_table_settings. + + IF ls_settings-top_left_column IS INITIAL. + ls_settings-top_left_column = lc_top_left_column. + ENDIF. + + IF ls_settings-table_style IS INITIAL. + ls_settings-table_style = zcl_excel_table=>builtinstyle_medium2. + ENDIF. + + IF ls_settings-top_left_row IS INITIAL. + ls_settings-top_left_row = lc_top_left_row. + ENDIF. + + IF it_field_catalog IS NOT SUPPLIED. + lt_field_catalog = zcl_excel_common=>get_fieldcatalog( ip_table = ip_table ). + ELSE. + lt_field_catalog = it_field_catalog. + ENDIF. + + SORT lt_field_catalog BY position. + +*--------------------------------------------------------------------* +* issue #237 Check if overlapping areas exist Start +*--------------------------------------------------------------------* + "Get the number of columns for the current table + lt_columns = lt_field_catalog. + DELETE lt_columns WHERE dynpfld NE abap_true. + DESCRIBE TABLE lt_columns LINES lv_columns. + + "Calculate the top left row of the current table + lv_column_int = zcl_excel_common=>convert_column2int( ls_settings-top_left_column ). + lv_row_int = ls_settings-top_left_row. + + "Get number of row for the current table + DESCRIBE TABLE ip_table LINES lv_rows. + + "Calculate the bottom right row for the current table + lv_maxcol = lv_column_int + lv_columns - 1. + lv_maxrow = lv_row_int + lv_rows - 1. + ls_settings-bottom_right_column = zcl_excel_common=>convert_column2alpha( lv_maxcol ). + ls_settings-bottom_right_row = lv_maxrow. + + lv_column_int = zcl_excel_common=>convert_column2int( ls_settings-top_left_column ). + + lo_iterator = me->tables->if_object_collection~get_iterator( ). + WHILE lo_iterator->if_object_collection_iterator~has_next( ) EQ abap_true. + + lo_curtable ?= lo_iterator->if_object_collection_iterator~get_next( ). + IF ( ( ls_settings-top_left_row GE lo_curtable->settings-top_left_row AND ls_settings-top_left_row LE lo_curtable->settings-bottom_right_row ) + OR + ( ls_settings-bottom_right_row GE lo_curtable->settings-top_left_row AND ls_settings-bottom_right_row LE lo_curtable->settings-bottom_right_row ) + ) + AND + ( ( lv_column_int GE zcl_excel_common=>convert_column2int( lo_curtable->settings-top_left_column ) AND lv_column_int LE zcl_excel_common=>convert_column2int( lo_curtable->settings-bottom_right_column ) ) + OR + ( lv_maxcol GE zcl_excel_common=>convert_column2int( lo_curtable->settings-top_left_column ) AND lv_maxcol LE zcl_excel_common=>convert_column2int( lo_curtable->settings-bottom_right_column ) ) + ). + lv_errormessage = 'Table overlaps with previously bound table and will not be added to worksheet.'(400). + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = lv_errormessage. + ENDIF. + + ENDWHILE. +*--------------------------------------------------------------------* +* issue #237 Check if overlapping areas exist End +*--------------------------------------------------------------------* + + CREATE OBJECT lo_table. + lo_table->settings = ls_settings. + lo_table->set_data( ir_data = ip_table ). + lv_id = me->excel->get_next_table_id( ). + lo_table->set_id( iv_id = lv_id ). +* lo_table->fieldcat = lt_field_catalog[]. + + me->tables->add( lo_table ). + +* It is better to loop column by column (only visible column) + LOOP AT lt_field_catalog ASSIGNING <ls_field_catalog> WHERE dynpfld EQ abap_true. + + lv_column_alpha = zcl_excel_common=>convert_column2alpha( lv_column_int ). + + " Due restrinction of new table object we cannot have two column with the same name + " Check if a column with the same name exists, if exists add a counter + " If no medium description is provided we try to use small or long +* lv_value = <ls_field_catalog>-scrtext_m. + IF <ls_field_catalog>-scrtext_m IS NOT INITIAL. + lv_value = <ls_field_catalog>-scrtext_m. + <ls_field_catalog>-scrtext_l = lv_value. + ELSEIF <ls_field_catalog>-scrtext_s IS NOT INITIAL. + lv_value = <ls_field_catalog>-scrtext_s. + <ls_field_catalog>-scrtext_l = lv_value. + ELSEIF <ls_field_catalog>-scrtext_l IS NOT INITIAL. + lv_value = <ls_field_catalog>-scrtext_l. + ELSE. + lv_value = 'Column'. " default value as Excel does + <ls_field_catalog>-scrtext_l = lv_value. + ENDIF. + WHILE 1 = 1. + + READ TABLE lt_column_name_buffer TRANSPORTING NO FIELDS WITH KEY table_line = lv_value BINARY SEARCH. + IF sy-subrc <> 0. + <ls_field_catalog>-scrtext_l = lv_value. + INSERT lv_value INTO TABLE lt_column_name_buffer. + EXIT. + ELSE. + lv_syindex = sy-index. + CONCATENATE <ls_field_catalog>-scrtext_l lv_syindex INTO lv_value. + ENDIF. + + ENDWHILE. + " First of all write column header + IF <ls_field_catalog>-style_header IS NOT INITIAL. + me->set_cell( ip_column = lv_column_alpha + ip_row = lv_row_int + ip_value = lv_value + ip_style = <ls_field_catalog>-style_header ). + ELSE. + me->set_cell( ip_column = lv_column_alpha + ip_row = lv_row_int + ip_value = lv_value ). + ENDIF. + + ADD 1 TO lv_row_int. + LOOP AT ip_table ASSIGNING <fs_table_line>. + + ASSIGN COMPONENT <ls_field_catalog>-fieldname OF STRUCTURE <fs_table_line> TO <fs_fldval>. + " issue #290 Add formula support in table + IF <ls_field_catalog>-formula EQ abap_true. + IF <ls_field_catalog>-style IS NOT INITIAL. + me->set_cell( ip_column = lv_column_alpha + ip_row = lv_row_int + ip_formula = <fs_fldval> + ip_style = <ls_field_catalog>-style ). + ELSE. + me->set_cell( ip_column = lv_column_alpha + ip_row = lv_row_int + ip_formula = <fs_fldval> ). + ENDIF. + ELSE. + IF <ls_field_catalog>-style IS NOT INITIAL. + me->set_cell( ip_column = lv_column_alpha + ip_row = lv_row_int + ip_value = <fs_fldval> + ip_style = <ls_field_catalog>-style ). + ELSE. + me->set_cell( ip_column = lv_column_alpha + ip_row = lv_row_int + ip_value = <fs_fldval> ). + ENDIF. + ENDIF. + ADD 1 TO lv_row_int. + + ENDLOOP. + IF sy-subrc <> 0. "create empty row if table has no data + me->set_cell( ip_column = lv_column_alpha + ip_row = lv_row_int + ip_value = space ). + ADD 1 TO lv_row_int. + ENDIF. + +*--------------------------------------------------------------------* + " totals +*--------------------------------------------------------------------* + IF <ls_field_catalog>-totals_function IS NOT INITIAL. + lv_formula = lo_table->get_totals_formula( ip_column = <ls_field_catalog>-scrtext_l ip_function = <ls_field_catalog>-totals_function ). + IF <ls_field_catalog>-style_total IS NOT INITIAL. + me->set_cell( ip_column = lv_column_alpha + ip_row = lv_row_int + ip_formula = lv_formula + ip_style = <ls_field_catalog>-style_total ). + ELSE. + me->set_cell( ip_column = lv_column_alpha + ip_row = lv_row_int + ip_formula = lv_formula ). + ENDIF. + ENDIF. + + lv_row_int = ls_settings-top_left_row. + ADD 1 TO lv_column_int. + +*--------------------------------------------------------------------* + " conditional formatting +*--------------------------------------------------------------------* + IF <ls_field_catalog>-cond_style IS NOT INITIAL. + lv_first_row = ls_settings-top_left_row + 1. " +1 to exclude header + lv_last_row = ls_settings-top_left_row + lv_rows. + <ls_field_catalog>-cond_style->set_range( ip_start_column = lv_column_alpha + ip_start_row = lv_first_row + ip_stop_column = lv_column_alpha + ip_stop_row = lv_last_row ). + ENDIF. + + ENDLOOP. + +*--------------------------------------------------------------------* + " Set field catalog +*--------------------------------------------------------------------* + lo_table->fieldcat = lt_field_catalog[]. + + es_table_settings = ls_settings. + es_table_settings-bottom_right_column = lv_column_alpha. + " >> Issue #291 + IF ip_table IS INITIAL. + es_table_settings-bottom_right_row = ls_settings-top_left_row + 2. "Last rows + ELSE. + es_table_settings-bottom_right_row = ls_settings-top_left_row + lv_rows + 1. "Last rows + ENDIF. + " << Issue #291 + + endmethod. + + + + + + + method CALCULATE_CELL_WIDTH. + DATA: cell_value TYPE zexcel_cell_value, + guid TYPE zexcel_cell_style, + stylemapping TYPE zexcel_s_stylemapping. + + me->get_cell( EXPORTING ip_column = ip_column " Cell Column + ip_row = ip_row " Cell Row + IMPORTING ep_value = cell_value + ep_guid = guid )." Cell Value ). + + + ep_width = STRLEN( cell_value ). + TRY. + stylemapping = me->excel->get_style_to_guid( guid ). + CATCH zcx_excel. + EXIT. " Do nothing if no style was found + ENDTRY. + + IF stylemapping-complete_stylex-font-size = 'X'. + ep_width = ep_width * stylemapping-complete_style-font-size / 11. + ENDIF. + + endmethod. + + + + method CALCULATE_COLUMN_WIDTHS. + TYPES: + BEGIN OF t_auto_size, + col_index TYPE int4, + width TYPE float, + END OF t_auto_size. + TYPES: tt_auto_size TYPE TABLE OF t_auto_size. + + DATA: column_dimensions TYPE zexcel_t_worksheet_columndime. + DATA: column_dimension TYPE REF TO zcl_excel_worksheet_columndime. + + DATA: auto_size TYPE flag. + DATA: auto_sizes TYPE tt_auto_size. +* DATA: col_alpha TYPE zexcel_cell_column_alpha." issue #155 - less restrictive typing for ip_column + DATA: cell_value TYPE zexcel_cell_value. + DATA: cell_style TYPE REF TO zcl_excel_style. + DATA: count TYPE int4. + DATA: highest_row TYPE int4. + DATA: width TYPE i. + + FIELD-SYMBOLS: <column_dimension> LIKE LINE OF column_dimensions. + FIELD-SYMBOLS: <auto_size> LIKE LINE OF auto_sizes. + + column_dimensions[] = me->get_column_dimensions( ). + LOOP AT column_dimensions ASSIGNING <column_dimension>. + auto_size = <column_dimension>-column_dimension->get_auto_size( ). + IF auto_size = abap_true. + APPEND INITIAL LINE TO auto_sizes ASSIGNING <auto_size>. + <auto_size>-col_index = <column_dimension>-column_dimension->get_column_index( ). + <auto_size>-width = -1. + ENDIF. + ENDLOOP. + + " There is only something to do if there are some auto-size columns + IF NOT auto_sizes IS INITIAL. + highest_row = me->get_highest_row( ). + LOOP AT auto_sizes ASSIGNING <auto_size>. +* col_alpha = zcl_excel_common=>convert_column2alpha( <auto_size>-col_index )." issue #155 - less restrictive typing for ip_column + count = 1. + WHILE count <= highest_row. +* Start of change # issue 139 - Dateretention of cellstyles +* IF cell_style IS BOUND. +* CREATE OBJECT cell_style. +* ENDIF. +* me->get_cell( +* EXPORTING +* ip_column = col_alpha " Cell Column +* ip_row = count " Cell Row +* IMPORTING +* ep_value = cell_value " Cell Value +* ep_style = cell_style " Request Cell Style as well +* ). +* " For an easy start we just take the number of characters as the width +* width = strlen( cell_value ). +* " Addition to solve issue #120, contribution by Stefan Schm#ƒÂ#cker +* " Calculate width using Font Size and Font Type +* IF cell_style IS BOUND +* AND cell_style->font IS BOUND. +* width = cell_style->font->calculate_text_width( cell_value ). +* ENDIF. +* width = calculate_cell_width( ip_column = col_alpha " issue #155 - less restrictive typing for ip_column + width = calculate_cell_width( ip_column = <auto_size>-col_index " issue #155 - less restrictive typing for ip_column + ip_row = count ). +* End of change # issue 139 - Dateretention of cellstyles + IF width > <auto_size>-width. + <auto_size>-width = width. + ENDIF. + count = count + 1. + ENDWHILE. +* column_dimension = me->get_column_dimension( col_alpha ). " issue #155 - less restrictive typing for ip_column + column_dimension = me->get_column_dimension( <auto_size>-col_index ). " issue #155 - less restrictive typing for ip_column + column_dimension->set_width( <auto_size>-width ). + ENDLOOP. + ENDIF. + + endmethod. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + method CHANGE_CELL_STYLE. + " issue # 139 + 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, + l_guid TYPE zexcel_cell_style. "issue # 177 + +* 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 = l_guid )." Cell Value ). "issue # 177 + + + stylemapping = me->excel->get_style_to_guid( l_guid ). "issue # 177 + complete_style = stylemapping-complete_style. + complete_stylex = stylemapping-complete_stylex. + CATCH zcx_excel. +* Error --> use submitted style + ENDTRY. + +* 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->excel->get_static_cellstyle_guid( ip_cstyle_complete = complete_style + ip_cstylex_complete = complete_stylex ). + me->set_cell_style( ip_column = ip_column + ip_row = ip_row + ip_style = ep_guid ). + + endmethod. + + + + + + method CONSTRUCTOR. + DATA: lv_title TYPE zexcel_sheet_title. + + me->excel = ip_excel. + + CALL FUNCTION 'GUID_CREATE' + IMPORTING + ev_guid_16 = me->guid. + + IF ip_title IS NOT INITIAL. + lv_title = ip_title. + ELSE. +* 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 ). + + CREATE OBJECT sheet_setup. + CREATE OBJECT conditional_styles. + CREATE OBJECT data_validations. + CREATE OBJECT tables. + CREATE OBJECT ranges. " issue #163 + CREATE OBJECT drawings + EXPORTING + ip_type = zcl_excel_drawing=>type_image. + CREATE OBJECT charts + EXPORTING + ip_type = zcl_excel_drawing=>type_chart. + me->zif_excel_sheet_protection~initialize( ). + me->zif_excel_sheet_properties~initialize( ). + CREATE OBJECT hyperlinks. + +* initialize active cell coordinates + active_cell-cell_row = 1. + active_cell-cell_column = 1. + +* inizialize dimension range + lower_cell-cell_row = 1. + lower_cell-cell_column = 1. + upper_cell-cell_row = 1. + upper_cell-cell_column = 1. + + endmethod. + + + method DELETE_MERGE. + + DELETE sheet_content_merge INDEX 1. + DELETE sheet_content_merge INDEX 1. + + endmethod. + + + + + + method FREEZE_PANES. + data: lv_xsplit type i, + lv_ysplit type i. + + IF ip_num_columns IS NOT SUPPLIED AND ip_num_rows IS NOT SUPPLIED. + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = 'Pleas provide number of rows and/or columns to freeze'. + ENDIF. + + IF ip_num_columns IS SUPPLIED AND ip_num_columns <= 0. + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = 'Number of columns to freeze should be positive'. + ENDIF. + + IF ip_num_rows IS SUPPLIED AND ip_num_rows <= 0. + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = 'Number of rows to freeze should be positive'. + ENDIF. + + 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( ) = abap_true. + 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. + CONCATENATE 'Sheet'(001) title INTO ep_title. + 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. + + + + + method GET_ACTIVE_CELL. + + DATA: lv_active_column TYPE zexcel_cell_column_alpha, + lv_active_row TYPE string. + + lv_active_column = zcl_excel_common=>convert_column2alpha( active_cell-cell_column ). + lv_active_row = active_cell-cell_row. + SHIFT lv_active_row RIGHT DELETING TRAILING space. + SHIFT lv_active_row LEFT DELETING LEADING space. + CONCATENATE lv_active_column lv_active_row INTO ep_active_cell. + + endmethod. + + + + + + + + + + method GET_CELL. + + DATA: lv_column TYPE zexcel_cell_column, + ls_sheet_content TYPE zexcel_s_cell_data. + + FIELD-SYMBOLS: <fs_sheet_content> TYPE zexcel_s_cell_data. + + lv_column = zcl_excel_common=>convert_column2int( ip_column ). + + READ TABLE sheet_content INTO ls_sheet_content WITH TABLE KEY cell_row = ip_row + cell_column = lv_column. + + ep_rc = sy-subrc. + ep_value = ls_sheet_content-cell_value. + ep_guid = ls_sheet_content-cell_style. " issue 139 - added this to be used for columnwidth calculation + + " Addition to solve issue #120, contribution by Stefan Schm#ƒÂ#cker + DATA: style_iterator TYPE REF TO cl_object_collection_iterator, + style TYPE REF TO zcl_excel_style. + IF ep_style IS REQUESTED. + style_iterator = me->excel->get_styles_iterator( ). + WHILE style_iterator->has_next( ) = 'X'. + style ?= style_iterator->get_next( ). + IF style->get_guid( ) = ls_sheet_content-cell_style. + ep_style = style. + EXIT. + ENDIF. + ENDWHILE. + ENDIF. + endmethod. + + + + + + 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 + + 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> + WITH KEY column = lv_column_alpha. " issue #155 - less restrictive typing for ip_column + + 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_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. + ELSE. + r_column_dimension = <fs_column_dimension>-column_dimension. + ENDIF. + + endmethod. + + + + method GET_COLUMN_DIMENSIONS. + r_column_dimension[] = me->column_dimensions[]. + endmethod. + + + + method GET_COND_STYLES_ITERATOR. + + eo_iterator = me->conditional_styles->get_iterator( ). + endmethod. + + + + method GET_DATA_VALIDATIONS_ITERATOR. + + eo_iterator = me->data_validations->get_iterator( ). + endmethod. + + + + method GET_DATA_VALIDATIONS_SIZE. + ep_size = me->data_validations->size( ). + endmethod. + + + + method GET_DEFAULT_COLUMN_DIMENSION. + IF me->default_column_dimension IS NOT BOUND. + CREATE OBJECT me->default_column_dimension + EXPORTING + ip_index = 'A' " ???? + ip_worksheet = me + ip_excel = me->excel. + ENDIF. + + r_column_dimension = me->default_column_dimension. + endmethod. + + + + method GET_DEFAULT_EXCEL_DATE_FORMAT. + CONSTANTS: c_lang_e TYPE lang VALUE 'E'. + + IF default_excel_date_format IS NOT INITIAL. + ep_default_excel_date_format = default_excel_date_format. + RETURN. + ENDIF. + + "try to get defaults + TRY. + cl_abap_datfm=>get_date_format_des( EXPORTING im_langu = c_lang_e + IMPORTING ex_dateformat = default_excel_date_format ). + CATCH cx_abap_datfm_format_unknown. + + ENDTRY. + + " and fallback to fixed format + IF default_excel_date_format IS INITIAL. + default_excel_date_format = zcl_excel_style_number_format=>c_format_date_ddmmyyyydot. + ENDIF. + + ep_default_excel_date_format = default_excel_date_format. + endmethod. + + + + method GET_DEFAULT_EXCEL_TIME_FORMAT. + DATA: l_timefm TYPE xutimefm. + + IF default_excel_time_format IS NOT INITIAL. + ep_default_excel_time_format = default_excel_time_format. + RETURN. + ENDIF. + +* Let's get default + l_timefm = cl_abap_timefm=>get_environment_timefm( ). + CASE l_timefm. + WHEN 0. +*0 24 Hour Format (Example: 12:05:10) + default_excel_time_format = zcl_excel_style_number_format=>c_format_date_time6. + WHEN 1. +*1 12 Hour Format (Example: 12:05:10 PM) + default_excel_time_format = zcl_excel_style_number_format=>c_format_date_time2. + WHEN 2. +*2 12 Hour Format (Example: 12:05:10 pm) for now all the same. no chnage upper lower + default_excel_time_format = zcl_excel_style_number_format=>c_format_date_time2. + WHEN 3. +*3 Hours from 0 to 11 (Example: 00:05:10 PM) for now all the same. no chnage upper lower + default_excel_time_format = zcl_excel_style_number_format=>c_format_date_time2. + WHEN 4. +*4 Hours from 0 to 11 (Example: 00:05:10 pm) for now all the same. no chnage upper lower + default_excel_time_format = zcl_excel_style_number_format=>c_format_date_time2. + WHEN OTHERS. + " and fallback to fixed format + default_excel_time_format = zcl_excel_style_number_format=>c_format_date_time6. + ENDCASE. + + ep_default_excel_time_format = default_excel_time_format. + endmethod. + + + + method GET_DEFAULT_ROW_DIMENSION. + IF me->default_row_dimension IS NOT BOUND. + CREATE OBJECT me->default_row_dimension. + ENDIF. + + r_row_dimension = me->default_row_dimension. + endmethod. + + + + + method GET_DIMENSION_RANGE. + + me->update_dimension_range( ). + IF upper_cell EQ lower_cell. "only one cell + " Worksheet not filled +* IF upper_cell-cell_coords = '0'. + IF upper_cell-cell_coords IS INITIAL. + ep_dimension_range = 'A1'. + ELSE. + ep_dimension_range = upper_cell-cell_coords. + ENDIF. + ELSE. + CONCATENATE upper_cell-cell_coords ':' lower_cell-cell_coords INTO ep_dimension_range. + ENDIF. + + endmethod. + + + + + method GET_DRAWINGS. + + DATA: lo_drawing TYPE REF TO zcl_excel_drawing, + lo_iterator TYPE REF TO cl_object_collection_iterator. + + CASE ip_type. + WHEN zcl_excel_drawing=>type_image. + r_drawings = drawings. + WHEN zcl_excel_drawing=>type_chart. + r_drawings = charts. + WHEN space. + CREATE OBJECT r_drawings + EXPORTING + ip_type = ''. + + lo_iterator = drawings->get_iterator( ). + WHILE lo_iterator->has_next( ) = abap_true. + lo_drawing ?= lo_iterator->get_next( ). + r_drawings->include( lo_drawing ). + ENDWHILE. + lo_iterator = charts->get_iterator( ). + WHILE lo_iterator->has_next( ) = abap_true. + lo_drawing ?= lo_iterator->get_next( ). + r_drawings->include( lo_drawing ). + ENDWHILE. + WHEN OTHERS. + ENDCASE. + endmethod. + + + + + method GET_DRAWINGS_ITERATOR. + CASE ip_type. + WHEN zcl_excel_drawing=>type_image. + eo_iterator = drawings->get_iterator( ). + WHEN zcl_excel_drawing=>type_chart. + eo_iterator = charts->get_iterator( ). + ENDCASE. + endmethod. + + + + + method GET_FREEZE_CELL. + ep_row = me->freeze_pane_cell_row. + ep_column = me->freeze_pane_cell_column. + endmethod. + + + + method GET_GUID. + + ep_guid = me->guid. + + endmethod. + + + + + method GET_HIGHEST_COLUMN. + me->update_dimension_range( ). + r_highest_column = me->lower_cell-cell_column. + endmethod. + + + + + method GET_HIGHEST_ROW. + me->update_dimension_range( ). + r_highest_row = me->lower_cell-cell_row. + endmethod. + + + + method GET_HYPERLINKS_ITERATOR. + eo_iterator = hyperlinks->get_iterator( ). + endmethod. + + + + method GET_HYPERLINKS_SIZE. + ep_size = hyperlinks->size( ). + endmethod. + + + + + method GET_MERGE. + + DATA: lv_column_start TYPE string, + lv_column_end TYPE string, + lv_row TYPE string, + lv_index TYPE sy-tabix, + ls_sheet_content TYPE zexcel_s_cell_data, + range_from TYPE string, + range_to TYPE string, + lv_merge_range TYPE string, + lv_count TYPE string. + + FIELD-SYMBOLS: <fs_sheet_content> TYPE zexcel_s_cell_data. + + DESCRIBE TABLE sheet_content_merge LINES lv_count. + + WHILE lv_count GT lv_index. +* LOOP AT sheet_content_merge ASSIGNING <fs_sheet_content>. + lv_index = lv_index + 1. + READ TABLE sheet_content_merge ASSIGNING <fs_sheet_content> INDEX lv_index. + lv_column_start = zcl_excel_common=>convert_column2alpha( <fs_sheet_content>-cell_column ). + lv_row = <fs_sheet_content>-cell_row. + SHIFT lv_column_start RIGHT DELETING TRAILING space. + SHIFT lv_column_start LEFT DELETING LEADING space. + SHIFT lv_row RIGHT DELETING TRAILING space. + SHIFT lv_row LEFT DELETING LEADING space. + CONCATENATE lv_column_start lv_row + INTO range_from. + + lv_index = lv_index + 1. + READ TABLE sheet_content_merge ASSIGNING <fs_sheet_content> INDEX lv_index. + lv_column_end = zcl_excel_common=>convert_column2alpha( <fs_sheet_content>-cell_column ). + lv_row = <fs_sheet_content>-cell_row. + SHIFT lv_column_end RIGHT DELETING TRAILING space. + SHIFT lv_column_end LEFT DELETING LEADING space. + SHIFT lv_row RIGHT DELETING TRAILING space. + SHIFT lv_row LEFT DELETING LEADING space. + CONCATENATE lv_column_end lv_row + INTO range_to. + + CONCATENATE range_from range_to INTO lv_merge_range + SEPARATED BY ':'. + APPEND lv_merge_range TO merge_range. + ENDWHILE. +* ENDLOOP. + +* READ TABLE sheet_content_merge ASSIGNING <fs_sheet_content> INDEX 1. +* IF sy-subrc EQ 0 AND <fs_sheet_content> IS ASSIGNED. +* lv_column_start = zcl_excel_common=>convert_column2alpha( <fs_sheet_content>-cell_column ). +* lv_row = <fs_sheet_content>-cell_row. +* SHIFT lv_column_start RIGHT DELETING TRAILING space. +* SHIFT lv_column_start LEFT DELETING LEADING space. +* SHIFT lv_row RIGHT DELETING TRAILING space. +* SHIFT lv_row LEFT DELETING LEADING space. +* CONCATENATE lv_column_start lv_row +* INTO range_from. +* ENDIF. +* READ TABLE sheet_content_merge ASSIGNING <fs_sheet_content> INDEX 2. +* IF sy-subrc EQ 0 AND <fs_sheet_content> IS ASSIGNED. +* lv_column_end = zcl_excel_common=>convert_column2alpha( <fs_sheet_content>-cell_column ). +* SHIFT lv_column_end RIGHT DELETING TRAILING space. +* SHIFT lv_column_end LEFT DELETING LEADING space. +* CONCATENATE lv_column_end lv_row +* INTO range_to. +* ENDIF. + +* IF range_from NE space AND range_to NE space. +* CONCATENATE range_from range_to INTO ep_merge_range +* SEPARATED BY ':'. +* ENDIF. + + endmethod. + + + + method GET_RANGES_ITERATOR. + + eo_iterator = me->ranges->get_iterator( ). + + endmethod. + + + + + method GET_ROW_DIMENSION. + FIELD-SYMBOLS: <fs_row_dimension> LIKE LINE OF row_dimensions. + + READ TABLE me->row_dimensions ASSIGNING <fs_row_dimension> + WITH KEY row = ip_row. + + IF NOT <fs_row_dimension> IS ASSIGNED. + CREATE OBJECT r_row_dimension + EXPORTING + ip_index = ip_row. + APPEND INITIAL LINE TO me->row_dimensions ASSIGNING <fs_row_dimension>. + <fs_row_dimension>-row = ip_row. + <fs_row_dimension>-row_dimension = r_row_dimension. + ELSE. + r_row_dimension = <fs_row_dimension>-row_dimension. + ENDIF. + + endmethod. + + + + method GET_ROW_DIMENSIONS. + r_row_dimension[] = me->row_dimensions[]. + endmethod. + + + + method GET_TABCOLOR. + ev_tabcolor = me->tabcolor. + endmethod. + + + + method GET_TABLES_ITERATOR. + eo_iterator = tables->if_object_collection~get_iterator( ). + endmethod. + + + + method GET_TABLES_SIZE. + ep_size = tables->if_object_collection~size( ). + endmethod. + + + + + method GET_TITLE. + DATA lv_value TYPE string. + IF ip_escaped EQ abap_true. + lv_value = me->title. + ep_title = zcl_excel_common=>escape_string( lv_value ). + ELSE. + ep_title = me->title. + ENDIF. + endmethod. + + + + + + method GET_VALUE_TYPE. + DATA: lo_addit TYPE REF TO cl_abap_elemdescr, + ls_dfies TYPE dfies, + l_function TYPE funcname, + l_value(50) TYPE c. + + ep_value = ip_value. + ep_value_type = cl_abap_typedescr=>typekind_string. " Thats our default if something goes wrong. + + TRY. + lo_addit ?= cl_abap_typedescr=>describe_by_data( ip_value ). + CATCH cx_sy_move_cast_error. + CLEAR lo_addit. + ENDTRY. + IF lo_addit IS BOUND. + lo_addit->get_ddic_field( RECEIVING p_flddescr = ls_dfies + EXCEPTIONS not_found = 1 + no_ddic_type = 2 + OTHERS = 3 ) . + IF sy-subrc = 0. + ep_value_type = ls_dfies-inttype. + + IF ls_dfies-convexit IS NOT INITIAL. +* We need to convert with output conversion function + CONCATENATE 'CONVERSION_EXIT_' ls_dfies-convexit '_OUTPUT' INTO l_function. + SELECT SINGLE funcname INTO l_function + FROM tfdir + WHERE funcname = l_function. + IF sy-subrc = 0. + CALL FUNCTION l_function + EXPORTING + input = ip_value + IMPORTING +* LONG_TEXT = + output = l_value +* SHORT_TEXT = + EXCEPTIONS + OTHERS = 1. + IF sy-subrc <> 0. +* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO +* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. + ELSE. + ep_value = l_value. + ENDIF. + ENDIF. + ENDIF. + ELSE. + ep_value_type = lo_addit->get_data_type_kind( ip_value ). + ENDIF. + ENDIF. + + endmethod. + + + method PRINT_TITLE_SET_RANGE. +*--------------------------------------------------------------------* +* issue#235 - repeat rows/columns +* - Stefan Schmöcker, 2012-12-02 +*--------------------------------------------------------------------* + + + DATA: lo_range_iterator TYPE REF TO cl_object_collection_iterator, + lo_range TYPE REF TO zcl_excel_range, + lv_repeat_range_sheetname TYPE string, + lv_repeat_range_col TYPE string, + lv_row_char_from TYPE char10, + lv_row_char_to TYPE char10, + lv_repeat_range_row TYPE string, + lv_repeat_range TYPE string. + + +*--------------------------------------------------------------------* +* Get range that represents printarea +* if non-existant, create it +*--------------------------------------------------------------------* + lo_range_iterator = me->get_ranges_iterator( ). + WHILE lo_range_iterator->has_next( ) = abap_true. + + lo_range ?= lo_range_iterator->get_next( ). + IF lo_range->name = zif_excel_sheet_printsettings=>gcv_print_title_name. + EXIT. " Found it + ENDIF. + CLEAR lo_range. + + ENDWHILE. + + + IF me->print_title_col_from IS INITIAL AND + me->print_title_row_from IS INITIAL. +*--------------------------------------------------------------------* +* No print titles are present, +*--------------------------------------------------------------------* + IF lo_range IS BOUND. + me->ranges->remove( lo_range ). + ENDIF. + ELSE. +*--------------------------------------------------------------------* +* Print titles are present, +*--------------------------------------------------------------------* + IF lo_range IS NOT BOUND. + lo_range = me->add_new_range( ). + lo_range->name = zif_excel_sheet_printsettings=>gcv_print_title_name. + ENDIF. + + lv_repeat_range_sheetname = me->get_title( ). + lv_repeat_range_sheetname = zcl_excel_common=>escape_string( lv_repeat_range_sheetname ). + +*--------------------------------------------------------------------* +* Repeat-columns +*--------------------------------------------------------------------* + IF me->print_title_col_from IS NOT INITIAL. + CONCATENATE lv_repeat_range_sheetname + '!$' me->print_title_col_from + ':$' me->print_title_col_to + INTO lv_repeat_range_col. + ENDIF. + +*--------------------------------------------------------------------* +* Repeat-rows +*--------------------------------------------------------------------* + IF me->print_title_row_from IS NOT INITIAL. + lv_row_char_from = me->print_title_row_from. + lv_row_char_to = me->print_title_row_to. + CONCATENATE '!$' lv_row_char_from + ':$' lv_row_char_to + INTO lv_repeat_range_row. + CONDENSE lv_repeat_range_row NO-GAPS. + CONCATENATE lv_repeat_range_sheetname + lv_repeat_range_row + INTO lv_repeat_range_row. + ENDIF. + +*--------------------------------------------------------------------* +* Concatenate repeat-rows and columns +*--------------------------------------------------------------------* + IF lv_repeat_range_col IS INITIAL. + lv_repeat_range = lv_repeat_range_row. + ELSEIF lv_repeat_range_row IS INITIAL. + lv_repeat_range = lv_repeat_range_col. + ELSE. + CONCATENATE lv_repeat_range_col lv_repeat_range_row + INTO lv_repeat_range SEPARATED BY ','. + ENDIF. + + + lo_range->set_range_value( lv_repeat_range ). + ENDIF. + + + + endmethod. + + + + + + + + + + + + method SET_CELL. + + DATA: lv_column TYPE zexcel_cell_column, + ls_sheet_content TYPE zexcel_s_cell_data, + lv_row_alpha TYPE string, + lv_col_alpha TYPE zexcel_cell_column_alpha, + lv_value TYPE zexcel_cell_value, + lv_data_type TYPE zexcel_cell_data_type, + lv_value_type TYPE abap_typekind, + lo_style TYPE REF TO zcl_excel_style, + lv_style_guid TYPE zexcel_cell_style, + lo_addit TYPE REF TO cl_abap_elemdescr, + lo_value TYPE REF TO data, + lo_value_new TYPE REF TO data. + + FIELD-SYMBOLS: <fs_sheet_content> TYPE zexcel_s_cell_data, + <fs_numeric> TYPE numeric, + <fs_date> TYPE d, + <fs_time> TYPE t, + <fs_value> TYPE simple. + + IF ip_value IS NOT SUPPLIED AND ip_formula IS NOT SUPPLIED. + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = 'Please provide the value or formula'. + ENDIF. + +* Begin of change issue #152 - don't touch exisiting style if only value is passed +* lv_style_guid = ip_style. + lv_column = zcl_excel_common=>convert_column2int( ip_column ). + READ TABLE sheet_content ASSIGNING <fs_sheet_content> WITH TABLE KEY cell_row = ip_row " Changed to access via table key , Stefan Schmöcker, 2013-08-03 + cell_column = lv_column. + IF sy-subrc = 0. + IF ip_style IS INITIAL. + " If no style is provided as method-parameter and cell is found use cell's current style + lv_style_guid = <fs_sheet_content>-cell_style. + ELSE. + " Style provided as method-parameter --> use this + lv_style_guid = ip_style. + ENDIF. + ELSE. + " No cell found --> use supplied style even if empty + lv_style_guid = ip_style. + ENDIF. +* End of change issue #152 - don't touch exisiting style if only value is passed + + IF ip_value IS SUPPLIED. + "if data type is passed just write the value. Otherwise map abap type to excel and perform conversion + "IP_DATA_TYPE is passed by excel reader so source types are preserved +*First we get reference into local var. + CREATE DATA lo_value LIKE ip_value. + ASSIGN lo_value->* TO <fs_value>. + <fs_value> = ip_value. + IF ip_data_type IS SUPPLIED. + IF ip_abap_type IS NOT SUPPLIED. + get_value_type( EXPORTING ip_value = ip_value + IMPORTING ep_value = <fs_value> ) . + ENDIF. + lv_value = <fs_value>. + lv_data_type = ip_data_type. + ELSE. + IF ip_abap_type IS SUPPLIED. + lv_value_type = ip_abap_type. + ELSE. + get_value_type( EXPORTING ip_value = ip_value + IMPORTING ep_value = <fs_value> + ep_value_type = lv_value_type ). + ENDIF. + CASE lv_value_type. + WHEN cl_abap_typedescr=>typekind_int OR cl_abap_typedescr=>typekind_int1 OR cl_abap_typedescr=>typekind_int2. + lo_addit = cl_abap_elemdescr=>get_i( ). + CREATE DATA lo_value_new TYPE HANDLE lo_addit. + ASSIGN lo_value_new->* TO <fs_numeric>. + IF sy-subrc = 0. + <fs_numeric> = <fs_value>. + lv_value = zcl_excel_common=>number_to_excel_string( ip_value = <fs_numeric> ). + ENDIF. + + WHEN cl_abap_typedescr=>typekind_float OR cl_abap_typedescr=>typekind_packed. + lo_addit = cl_abap_elemdescr=>get_f( ). + CREATE DATA lo_value_new TYPE HANDLE lo_addit. + ASSIGN lo_value_new->* TO <fs_numeric>. + IF sy-subrc = 0. + <fs_numeric> = <fs_value>. + lv_value = zcl_excel_common=>number_to_excel_string( ip_value = <fs_numeric> ). + ENDIF. + + WHEN cl_abap_typedescr=>typekind_char OR cl_abap_typedescr=>typekind_string OR cl_abap_typedescr=>typekind_num OR + cl_abap_typedescr=>typekind_hex. + lv_value = <fs_value>. + lv_data_type = 's'. + + WHEN cl_abap_typedescr=>typekind_date. + lo_addit = cl_abap_elemdescr=>get_d( ). + CREATE DATA lo_value_new TYPE HANDLE lo_addit. + ASSIGN lo_value_new->* TO <fs_date>. + IF sy-subrc = 0. + <fs_date> = <fs_value>. + lv_value = zcl_excel_common=>date_to_excel_string( ip_value = <fs_date> ) . + ENDIF. +* Begin of change issue #152 - don't touch exisiting style if only value is passed +* Moved to end of routine - apply date-format even if other styleinformation is passed +* IF ip_style IS NOT SUPPLIED. "get default date format in case parameter is initial +* lo_style = excel->add_new_style( ). +* lo_style->number_format->format_code = get_default_excel_date_format( ). +* lv_style_guid = lo_style->get_guid( ). +* ENDIF. +* End of change issue #152 - don't touch exisiting style if only value is passed + + WHEN cl_abap_typedescr=>typekind_time. + lo_addit = cl_abap_elemdescr=>get_t( ). + CREATE DATA lo_value_new TYPE HANDLE lo_addit. + ASSIGN lo_value_new->* TO <fs_time>. + IF sy-subrc = 0. + <fs_time> = <fs_value>. + lv_value = zcl_excel_common=>time_to_excel_string( ip_value = <fs_time> ). + ENDIF. +* Begin of change issue #152 - don't touch exisiting style if only value is passed +* Moved to end of routine - apply time-format even if other styleinformation is passed +* IF ip_style IS NOT SUPPLIED. "get default time format for user in case parameter is initial +* lo_style = excel->add_new_style( ). +* lo_style->number_format->format_code = zcl_excel_style_number_format=>c_format_date_time6. +* lv_style_guid = lo_style->get_guid( ). +* ENDIF. +* End of change issue #152 - don't touch exisiting style if only value is passed + + WHEN OTHERS. + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = 'Invalid data type of input value'. + ENDCASE. + ENDIF. + + ENDIF. + + IF ip_hyperlink IS BOUND. + ip_hyperlink->set_cell_reference( ip_column = ip_column + ip_row = ip_row ). + me->hyperlinks->add( ip_hyperlink ). + ENDIF. + +* Begin of change issue #152 - don't touch exisiting style if only value is passed +* Read table moved up, so that current style may be evaluated +* lv_column = zcl_excel_common=>convert_column2int( ip_column ). + +* READ TABLE sheet_content ASSIGNING <fs_sheet_content> WITH KEY cell_row = ip_row +* cell_column = lv_column. +* +* IF sy-subrc EQ 0. + IF <fs_sheet_content> IS ASSIGNED. +* End of change issue #152 - don't touch exisiting style if only value is passed + <fs_sheet_content>-cell_value = lv_value. + <fs_sheet_content>-cell_formula = ip_formula. + <fs_sheet_content>-cell_style = lv_style_guid. + <fs_sheet_content>-data_type = lv_data_type. + ELSE. + ls_sheet_content-cell_row = ip_row. + ls_sheet_content-cell_column = lv_column. + ls_sheet_content-cell_value = lv_value. + ls_sheet_content-cell_formula = ip_formula. + ls_sheet_content-cell_style = lv_style_guid. + ls_sheet_content-data_type = lv_data_type. + lv_row_alpha = ip_row. +* SHIFT lv_row_alpha RIGHT DELETING TRAILING space."del #152 - replaced with condense - should be faster +* SHIFT lv_row_alpha LEFT DELETING LEADING space. "del #152 - replaced with condense - should be faster + CONDENSE lv_row_alpha NO-GAPS. "ins #152 - replaced 2 shifts - should be faster + lv_col_alpha = zcl_excel_common=>convert_column2alpha( ip_column ). " issue #155 - less restrictive typing for ip_column + CONCATENATE lv_col_alpha lv_row_alpha INTO ls_sheet_content-cell_coords. " issue #155 - less restrictive typing for ip_column + INSERT ls_sheet_content INTO TABLE sheet_content ASSIGNING <fs_sheet_content>. "ins #152 - Now <fs_sheet_content> always holds the data +* APPEND ls_sheet_content TO sheet_content. +* SORT sheet_content BY cell_row cell_column. + " me->update_dimension_range( ). + + ENDIF. + +* Begin of change issue #152 - don't touch exisiting style if only value is passed +* For Date- or Timefields change the formatcode if nothing is set yet +* Enhancement option: Check if existing formatcode is a date/ or timeformat +* If not, use default + DATA: lo_format_code_datetime TYPE zexcel_number_format. + DATA: stylemapping TYPE zexcel_s_stylemapping. + CASE lv_value_type. + WHEN cl_abap_typedescr=>typekind_date. + TRY. + stylemapping = me->excel->get_style_to_guid( <fs_sheet_content>-cell_style ). + CATCH zcx_excel . + ENDTRY. + IF stylemapping-complete_stylex-number_format-format_code IS INITIAL OR + stylemapping-complete_style-number_format-format_code IS INITIAL. + lo_format_code_datetime = zcl_excel_style_number_format=>c_format_date_std. + ELSE. + lo_format_code_datetime = stylemapping-complete_style-number_format-format_code. + ENDIF. + me->change_cell_style( ip_column = ip_column + ip_row = ip_row + ip_number_format_format_code = lo_format_code_datetime ). + + WHEN cl_abap_typedescr=>typekind_time. + TRY. + stylemapping = me->excel->get_style_to_guid( <fs_sheet_content>-cell_style ). + CATCH zcx_excel . + ENDTRY. + IF stylemapping-complete_stylex-number_format-format_code IS INITIAL OR + stylemapping-complete_style-number_format-format_code IS INITIAL. + lo_format_code_datetime = zcl_excel_style_number_format=>c_format_date_time6. + ELSE. + lo_format_code_datetime = stylemapping-complete_style-number_format-format_code. + ENDIF. + me->change_cell_style( ip_column = ip_column + ip_row = ip_row + ip_number_format_format_code = lo_format_code_datetime ). + + ENDCASE. +* End of change issue #152 - don't touch exisiting style if only value is passed + +* Fix issue #162 + lv_value = ip_value. + IF lv_value CS cl_abap_char_utilities=>cr_lf. + me->change_cell_style( ip_column = ip_column + ip_row = ip_row + ip_alignment_wraptext = abap_true ). + ENDIF. +* End of Fix issue #162 + + endmethod. + + + + + + + method SET_CELL_FORMULA. + DATA: + lv_column TYPE zexcel_cell_column, + ls_sheet_content LIKE LINE OF me->sheet_content. + + FIELD-SYMBOLS: + <sheet_content> LIKE LINE OF me->sheet_content. + +*--------------------------------------------------------------------* +* Get cell to set formula into +*--------------------------------------------------------------------* + lv_column = zcl_excel_common=>convert_column2int( ip_column ). + READ TABLE me->sheet_content ASSIGNING <sheet_content> WITH TABLE KEY cell_row = ip_row + cell_column = lv_column. + IF sy-subrc <> 0. " Create new entry in sheet_content if necessary + CHECK ip_formula IS INITIAL. " no need to create new entry in sheet_content when no formula is passed + ls_sheet_content-cell_row = ip_row. + ls_sheet_content-cell_column = lv_column. + INSERT ls_sheet_content INTO TABLE me->sheet_content ASSIGNING <sheet_content>. + ENDIF. + +*--------------------------------------------------------------------* +* Fieldsymbol now holds the relevant cell +*--------------------------------------------------------------------* + <sheet_content>-cell_formula = ip_formula. + + + endmethod. + + + + + + + method SET_CELL_STYLE. + + DATA: lv_column TYPE zexcel_cell_column, + ls_sheet_content TYPE zexcel_s_cell_data, + lv_row_alpha TYPE string, + lo_style TYPE REF TO zcl_excel_style, + lv_style_guid TYPE zexcel_cell_style. + + FIELD-SYMBOLS: <fs_sheet_content> TYPE zexcel_s_cell_data. + + lv_style_guid = ip_style. + + lv_column = zcl_excel_common=>convert_column2int( ip_column ). + + READ TABLE sheet_content ASSIGNING <fs_sheet_content> WITH KEY cell_row = ip_row + cell_column = lv_column. + + IF sy-subrc EQ 0. + <fs_sheet_content>-cell_style = lv_style_guid. + ELSE. + set_cell( ip_column = ip_column ip_row = ip_row ip_value = '' ip_style = ip_style ). + ENDIF. + + endmethod. + + + + + + + method SET_COLUMN_WIDTH. + DATA: column_dimension TYPE REF TO zcl_excel_worksheet_columndime. + DATA: width TYPE float. + + column_dimension = me->get_column_dimension( ip_column ). + +* if a fix size is supplied use this + IF ip_width_fix IS SUPPLIED. + TRY. + width = ip_width_fix. + IF width <= 0. + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = 'Please supply a positive number as column-width'. + ENDIF. + column_dimension->set_width( width ). + EXIT. + CATCH cx_sy_conversion_no_number. +* Strange stuff passed --> raise error + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = 'Unable to interpret supplied input as number'. + ENDTRY. + ENDIF. + +* If we get down to here, we have to use whatever is found in autosize. + column_dimension->set_auto_size( ip_width_autosize ). + + + endmethod. + + + + + method SET_DEFAULT_EXCEL_DATE_FORMAT. + + IF ip_default_excel_date_format IS INITIAL. + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = 'Default date format cannot be blank'. + ENDIF. + + default_excel_date_format = ip_default_excel_date_format. + endmethod. + + + + + + + + method SET_MERGE. + + DATA: lv_column_start TYPE zexcel_cell_column, + lv_column_end TYPE zexcel_cell_column, + ls_sheet_content TYPE zexcel_s_cell_data, + lv_row_alpha TYPE string. + + FIELD-SYMBOLS: <fs_sheet_content> TYPE zexcel_s_cell_data. + + lv_column_start = zcl_excel_common=>convert_column2int( ip_column_start ). + lv_column_end = zcl_excel_common=>convert_column2int( ip_column_end ). + + ls_sheet_content-cell_row = ip_row. + ls_sheet_content-cell_column = lv_column_start. + lv_row_alpha = ip_row. + SHIFT lv_row_alpha RIGHT DELETING TRAILING space. + SHIFT lv_row_alpha LEFT DELETING LEADING space. + CONCATENATE ip_column_start lv_row_alpha INTO ls_sheet_content-cell_coords. + INSERT ls_sheet_content INTO TABLE sheet_content_merge. + + ls_sheet_content-cell_column = lv_column_end. + IF ip_row_to IS SUPPLIED. + ls_sheet_content-cell_row = ip_row_to. + lv_row_alpha = ip_row_to. + ELSE. + lv_row_alpha = ip_row. + ls_sheet_content-cell_row = ip_row. + ENDIF. + + SHIFT lv_row_alpha RIGHT DELETING TRAILING space. + SHIFT lv_row_alpha LEFT DELETING LEADING space. + CONCATENATE ip_column_end lv_row_alpha INTO ls_sheet_content-cell_coords. + INSERT ls_sheet_content INTO TABLE sheet_content_merge. + + endmethod. + + + + method SET_PRINT_GRIDLINES. + me->print_gridlines = i_print_gridlines. + endmethod. + + + + + + method SET_ROW_HEIGHT. + DATA: row_dimension TYPE REF TO zcl_excel_worksheet_rowdimensi. + DATA: height TYPE float. + + row_dimension = me->get_row_dimension( ip_row ). + +* if a fix size is supplied use this + TRY. + height = ip_height_fix. + IF height <= 0. + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = 'Please supply a positive number as row-height'. + ENDIF. + row_dimension->set_row_height( height ). + EXIT. + CATCH cx_sy_conversion_no_number. +* Strange stuff passed --> raise error + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = 'Unable to interpret supplied input as number'. + ENDTRY. + + + + endmethod. + + + + method SET_SHOW_GRIDLINES. + me->show_gridlines = i_show_gridlines. + endmethod. + + + + method SET_SHOW_ROWCOLHEADERS. + me->show_rowcolheaders = i_show_rowcolheaders. + endmethod. + + + + method SET_TABCOLOR. + me->tabcolor = iv_tabcolor. + endmethod. + + + + + + + + + + + + method SET_TABLE. + + DATA: lo_tabdescr TYPE REF TO cl_abap_structdescr, + lr_data TYPE REF TO data, + ls_newline TYPE REF TO data, + ls_header TYPE x030l, + lt_dfies TYPE ddfields, + lv_row_header TYPE zexcel_cell_row VALUE '2', + lv_col_header TYPE zexcel_cell_column_alpha VALUE 'B', + lv_row_int TYPE zexcel_cell_row, + lv_column_int TYPE zexcel_cell_column, + lv_column_alpha TYPE zexcel_cell_column_alpha, + lv_cell_value TYPE zexcel_cell_value. + + + FIELD-SYMBOLS: <fs_table_line> TYPE ANY, + <fs_fldval> TYPE ANY, + <fs_dfies> TYPE dfies, + <fs_cell_value> TYPE zexcel_cell_value. + + lv_column_int = zcl_excel_common=>convert_column2int( ip_top_left_column ). + lv_row_int = ip_top_left_row. + + CREATE DATA lr_data LIKE LINE OF ip_table. + + lo_tabdescr ?= cl_abap_structdescr=>describe_by_data_ref( lr_data ). + + ls_header = lo_tabdescr->get_ddic_header( ). + + lt_dfies = lo_tabdescr->get_ddic_field_list( ). + +* It is better to loop column by column + LOOP AT lt_dfies ASSIGNING <fs_dfies>. + lv_column_alpha = zcl_excel_common=>convert_column2alpha( lv_column_int ). + + IF ip_no_header = abap_false. + " First of all write column header + lv_cell_value = <fs_dfies>-scrtext_m. + me->set_cell( ip_column = lv_column_alpha + ip_row = lv_row_int + ip_value = lv_cell_value + ip_style = ip_hdr_style ). + IF ip_transpose = abap_true. + ADD 1 TO lv_column_int. + ELSE. + ADD 1 TO lv_row_int. + ENDIF. + ENDIF. + + LOOP AT ip_table ASSIGNING <fs_table_line>. + lv_column_alpha = zcl_excel_common=>convert_column2alpha( lv_column_int ). + ASSIGN COMPONENT <fs_dfies>-fieldname OF STRUCTURE <fs_table_line> TO <fs_fldval>. + MOVE <fs_fldval> TO lv_cell_value. + me->set_cell( ip_column = lv_column_alpha + ip_row = lv_row_int + ip_value = <fs_fldval> "lv_cell_value + ip_style = ip_body_style ). + IF ip_transpose = abap_true. + ADD 1 TO lv_column_int. + ELSE. + ADD 1 TO lv_row_int. + ENDIF. + ENDLOOP. + IF ip_transpose = abap_true. + lv_column_int = zcl_excel_common=>convert_column2int( ip_top_left_column ). + ADD 1 TO lv_row_int. + ELSE. + lv_row_int = ip_top_left_row. + ADD 1 TO lv_column_int. + ENDIF. + ENDLOOP. + + endmethod. + + + + + method SET_TITLE. +*--------------------------------------------------------------------* +* ToDos: +* 2do§1 The current coding for replacing a named ranges name +* after renaming a sheet should be checked if it is +* really working if sheetname should be escaped +*--------------------------------------------------------------------* + +*--------------------------------------------------------------------* +* issue #230 - Pimp my Code +* - Stefan Schmöcker, (wip ) 2012-12-08 +* - ... +* changes: aligning code +* message made to support multilinguality +*--------------------------------------------------------------------* +* issue#243 - ' is not allowed as first character in sheet title +* - Stefan Schmöcker, 2012-12-02 +* changes: added additional check for ' as first character +*--------------------------------------------------------------------* + DATA: lo_worksheets_iterator TYPE REF TO cl_object_collection_iterator, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + errormessage TYPE string, + lv_rangesheetname_old TYPE string, + lv_rangesheetname_new TYPE string, + lo_ranges_iterator TYPE REF TO cl_object_collection_iterator, + lo_range TYPE REF TO zcl_excel_range, + lv_range_value TYPE zexcel_range_value, + lv_errormessage TYPE string. " Can't pass '...'(abc) to exception-class + + +*--------------------------------------------------------------------* +* Check whether title consists only of allowed characters +* Illegal characters are: / \ [ ] * ? : --> http://msdn.microsoft.com/en-us/library/ff837411.aspx +* Illegal characters not in documentation: ' as first character +*--------------------------------------------------------------------* + IF ip_title CA '/\[]*?:'. + lv_errormessage = 'Found illegal character in sheetname. List of forbidden characters: /\[]*?:'(402). + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = lv_errormessage. + ENDIF. + + IF ip_title IS NOT INITIAL AND ip_title(1) = `'`. + lv_errormessage = 'Sheetname may not start with &'(403). " & used instead of ' to allow fallbacklanguage + REPLACE '&' IN lv_errormessage WITH `'`. + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = lv_errormessage. + ENDIF. + + +*--------------------------------------------------------------------* +* Check whether title is unique in workbook +*--------------------------------------------------------------------* + 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. + +*--------------------------------------------------------------------* +* Remember old sheetname and rename sheet to desired name +*--------------------------------------------------------------------* + CONCATENATE me->title '!' INTO lv_rangesheetname_old. + me->title = ip_title. + +*--------------------------------------------------------------------* +* After changing this worksheet's title we have to adjust +* all ranges that are referring to this worksheet. +*--------------------------------------------------------------------* +* 2do§1 - Check if the following quickfix is solid +* I fear it isn't - but this implementation is better then +* nothing at all since it handles a supposed majority of cases +*--------------------------------------------------------------------* + CONCATENATE me->title '!' INTO lv_rangesheetname_new. + + lo_ranges_iterator = me->excel->get_ranges_iterator( ). + WHILE lo_ranges_iterator->has_next( ) = 'X'. + + lo_range ?= lo_ranges_iterator->get_next( ). + lv_range_value = lo_range->get_value( ). + REPLACE ALL OCCURRENCES OF lv_rangesheetname_old IN lv_range_value WITH lv_rangesheetname_new. + IF sy-subrc = 0. + lo_range->set_range_value( lv_range_value ). + ENDIF. + + ENDWHILE. + + + endmethod. + + + + method UPDATE_DIMENSION_RANGE. + + DATA: ls_sheet_content TYPE zexcel_s_cell_data, + lt_sheet_content TYPE zexcel_t_cell_data_unsorted, + lv_row_alpha TYPE string, + lv_column_alpha TYPE zexcel_cell_column_alpha. + + CHECK sheet_content IS NOT INITIAL. + +* update dimension range + lt_sheet_content = sheet_content. + "upper left corner + SORT lt_sheet_content BY cell_row. + READ TABLE lt_sheet_content INDEX 1 INTO ls_sheet_content. + upper_cell-cell_row = ls_sheet_content-cell_row. + SORT lt_sheet_content BY cell_column. + READ TABLE lt_sheet_content INDEX 1 INTO ls_sheet_content. + upper_cell-cell_column = ls_sheet_content-cell_column. + + lv_row_alpha = upper_cell-cell_row. + lv_column_alpha = zcl_excel_common=>convert_column2alpha( upper_cell-cell_column ). + SHIFT lv_row_alpha RIGHT DELETING TRAILING space. + SHIFT lv_row_alpha LEFT DELETING LEADING space. + CONCATENATE lv_column_alpha lv_row_alpha INTO upper_cell-cell_coords. + + "bottom right corner + SORT lt_sheet_content BY cell_row DESCENDING. + READ TABLE lt_sheet_content INDEX 1 INTO ls_sheet_content. + lower_cell-cell_row = ls_sheet_content-cell_row. + SORT lt_sheet_content BY cell_column DESCENDING. + READ TABLE lt_sheet_content INDEX 1 INTO ls_sheet_content. + lower_cell-cell_column = ls_sheet_content-cell_column. + + lv_row_alpha = lower_cell-cell_row. + lv_column_alpha = zcl_excel_common=>convert_column2alpha( lower_cell-cell_column ). + SHIFT lv_row_alpha RIGHT DELETING TRAILING space. + SHIFT lv_row_alpha LEFT DELETING LEADING space. + CONCATENATE lv_column_alpha lv_row_alpha INTO lower_cell-cell_coords. + + endmethod. + + + + *"* 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 ADD. + + worksheets->add( ip_worksheet ). + + endmethod. + + + method CLEAR. + + worksheets->clear( ). + + endmethod. + + + method CONSTRUCTOR. + + CREATE OBJECT worksheets. + + endmethod. + + + + + method GET. + + DATA lv_index TYPE i. + lv_index = ip_index. + eo_worksheet ?= worksheets->if_object_collection~get( lv_index ). + + endmethod. + + + + method GET_ITERATOR. + + eo_iterator ?= worksheets->if_object_collection~get_iterator( ). + + endmethod. + + + + method IS_EMPTY. + + is_empty = worksheets->if_object_collection~is_empty( ). + + endmethod. + + + + method REMOVE. + + worksheets->remove( ip_worksheet ). + + endmethod. + + + + method SIZE. + + ep_size = worksheets->if_object_collection~size( ). + + endmethod. + + + + *"* 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 + + ABAP + + + + + + + + + + + + + + + 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. + + + + 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. + 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 width as number'. + ENDTRY. + endmethod. + + + + + method SET_XF_INDEX. + me->XF_INDEX = ip_XF_INDEX. + r_worksheet_columndime = me. + endmethod. + + + + *"* 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 + + ABAP + + + + + + + + + method CONSTRUCTOR. + " Initialise values + me->row_index = ip_index. + me->row_height = -1. + me->visible = abap_true. + me->outline_level = 0. + me->collapsed = abap_false. + + " set row dimension as unformatted by default + me->xf_index = 0. + endmethod. + + + + method GET_COLLAPSED. + r_collapsed = me->collapsed. + endmethod. + + + + method GET_OUTLINE_LEVEL. + r_outline_level = me->outline_level. + endmethod. + + + + method GET_ROW_HEIGHT. + r_row_height = me->row_height. + endmethod. + + + + method GET_ROW_INDEX. + r_row_index = me->row_index. + endmethod. + + + + method GET_VISIBLE. + r_visible = me->visible. + endmethod. + + + + method GET_XF_INDEX. + r_xf_index = me->xf_index. + endmethod. + + + + method SET_COLLAPSED. + me->collapsed = ip_collapsed. + endmethod. + + + + + method SET_OUTLINE_LEVEL. + IF ip_outline_level < 0 + OR ip_outline_level > 7. + + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = 'Outline level must range between 0 and 7.'. + + ENDIF. + me->outline_level = ip_outline_level. + endmethod. + + + + + method SET_ROW_HEIGHT. + TRY. + me->row_height = ip_row_height. + CATCH cx_sy_conversion_no_number. + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = 'Unable to interpret ip_row_height as number'. + ENDTRY. + endmethod. + + + + method SET_ROW_INDEX. + me->row_index = ip_index. + endmethod. + + + + method SET_VISIBLE. + me->visible = ip_visible. + endmethod. + + + + method SET_XF_INDEX. + me->XF_INDEX = ip_XF_INDEX. + endmethod. + + - + *"* local class implementation for public class *"* use this source file for the implementation part of *"* local helper classes @@ -36,7 +12611,7 @@ me->excel = io_excel. ep_file = me->create( ). -endmethod. + endmethod. @@ -233,7 +12808,7 @@ endmethod. * STEP 12: Create the final zip ep_excel = lo_zip->save( ). -endmethod. + endmethod. @@ -508,7 +13083,7 @@ endmethod. lo_renderer = lo_ixml->create_renderer( ostream = lo_ostream document = lo_document ). lo_renderer->render( ). -endmethod. + endmethod. @@ -731,7 +13306,7 @@ endmethod. lo_renderer = lo_ixml->create_renderer( ostream = lo_ostream document = lo_document ). lo_renderer->render( ). -endmethod. + endmethod. @@ -856,7 +13431,7 @@ endmethod. lo_renderer = lo_ixml->create_renderer( ostream = lo_ostream document = lo_document ). lo_renderer->render( ). -endmethod. + endmethod. @@ -955,12 +13530,12 @@ endmethod. lo_renderer = lo_ixml->create_renderer( ostream = lo_ostream document = lo_document ). lo_renderer->render( ). -endmethod. + endmethod. - METHOD create_xl_charts. + method CREATE_XL_CHARTS. ** Constant node name @@ -1860,7 +14435,7 @@ endmethod. lo_renderer = lo_ixml->create_renderer( ostream = lo_ostream document = lo_document ). lo_renderer->render( ). -ENDMETHOD. + endmethod. @@ -1940,7 +14515,7 @@ ENDMETHOD. lo_renderer = lo_ixml->create_renderer( ostream = lo_ostream document = lo_document ). lo_renderer->render( ). -endmethod. + endmethod. @@ -2039,7 +14614,7 @@ endmethod. lo_renderer = lo_ixml->create_renderer( ostream = lo_ostream document = lo_document ). lo_renderer->render( ). -endmethod. + endmethod. @@ -2353,7 +14928,7 @@ endmethod. parent = io_document ). ep_anchor->append_child( new_child = lo_element_clientdata ). -endmethod. + endmethod. @@ -2501,7 +15076,7 @@ endmethod. lo_renderer = lo_ixml->create_renderer( ostream = lo_ostream document = lo_document ). lo_renderer->render( ). -endmethod. + endmethod. @@ -2618,17 +15193,17 @@ endmethod. lo_renderer = lo_ixml->create_renderer( ostream = lo_ostream document = lo_document ). lo_renderer->render( ). -endmethod. + endmethod. - METHOD create_xl_sheet. + method CREATE_XL_SHEET. *--------------------------------------------------------------------* * issue #237 - Error writing column-style -* - Stefan Schmöcker, 2012-11-01 +* - Stefan Schmöcker, 2012-11-01 *--------------------------------------------------------------------* TYPES: BEGIN OF cfvo, @@ -4276,7 +16851,7 @@ endmethod. lo_renderer = lo_ixml->create_renderer( ostream = lo_ostream document = lo_document ). lo_renderer->render( ). -ENDMETHOD. + endmethod. @@ -4446,7 +17021,7 @@ ENDMETHOD. lo_renderer = lo_ixml->create_renderer( ostream = lo_ostream document = lo_document ). lo_renderer->render( ). -endmethod. + endmethod. @@ -4454,919 +17029,957 @@ endmethod. ** Constant node name - CONSTANTS: lc_xml_node_stylesheet TYPE string VALUE 'styleSheet', - " font - lc_xml_node_fonts TYPE string VALUE 'fonts', - lc_xml_node_font TYPE string VALUE 'font', - lc_xml_node_b TYPE string VALUE 'b', "bold - lc_xml_node_i TYPE string VALUE 'i', "italic - lc_xml_node_u TYPE string VALUE 'u', "underline - lc_xml_node_strike TYPE string VALUE 'strike', "strikethrough - lc_xml_node_sz TYPE string VALUE 'sz', - lc_xml_node_color TYPE string VALUE 'color', - lc_xml_node_name TYPE string VALUE 'name', - lc_xml_node_family TYPE string VALUE 'family', - lc_xml_node_scheme TYPE string VALUE 'scheme', - " fill - lc_xml_node_fills TYPE string VALUE 'fills', - lc_xml_node_fill TYPE string VALUE 'fill', - lc_xml_node_patternfill TYPE string VALUE 'patternFill', - lc_xml_node_fgcolor TYPE string VALUE 'fgColor', - lc_xml_node_bgcolor TYPE string VALUE 'bgColor', - lc_xml_node_gradientfill TYPE string VALUE 'gradientFill', - lc_xml_node_stop TYPE string VALUE 'stop', - " borders - lc_xml_node_borders TYPE string VALUE 'borders', - lc_xml_node_border TYPE string VALUE 'border', - lc_xml_node_left TYPE string VALUE 'left', - lc_xml_node_right TYPE string VALUE 'right', - lc_xml_node_top TYPE string VALUE 'top', - lc_xml_node_bottom TYPE string VALUE 'bottom', - lc_xml_node_diagonal TYPE string VALUE 'diagonal', - " numfmt - lc_xml_node_numfmts TYPE string VALUE 'numFmts', - lc_xml_node_numfmt TYPE string VALUE 'numFmt', - " Styles - lc_xml_node_cellstylexfs TYPE string VALUE 'cellStyleXfs', - lc_xml_node_xf TYPE string VALUE 'xf', - lc_xml_node_cellxfs TYPE string VALUE 'cellXfs', - lc_xml_node_cellstyles TYPE string VALUE 'cellStyles', - lc_xml_node_cellstyle TYPE string VALUE 'cellStyle', - lc_xml_node_dxfs TYPE string VALUE 'dxfs', - lc_xml_node_dxf TYPE string VALUE 'dxf', - lc_xml_node_tablestyles TYPE string VALUE 'tableStyles', - " Colors - lc_xml_node_colors TYPE string VALUE 'colors', - lc_xml_node_indexedcolors TYPE string VALUE 'indexedColors', - lc_xml_node_rgbcolor TYPE string VALUE 'rgbColor', - lc_xml_node_mrucolors TYPE string VALUE 'mruColors', - " Alignment - lc_xml_node_alignment TYPE string VALUE 'alignment', - " Protection - lc_xml_node_protection TYPE string VALUE 'protection', - " Node attributes - lc_xml_attr_count TYPE string VALUE 'count', - lc_xml_attr_val TYPE string VALUE 'val', - lc_xml_attr_theme TYPE string VALUE 'theme', - lc_xml_attr_rgb TYPE string VALUE 'rgb', - lc_xml_attr_indexed TYPE string VALUE 'indexed', - lc_xml_attr_tint TYPE string VALUE 'tint', - lc_xml_attr_style TYPE string VALUE 'style', - lc_xml_attr_position TYPE string VALUE 'position', - lc_xml_attr_degree TYPE string VALUE 'degree', - lc_xml_attr_patterntype TYPE string VALUE 'patternType', - lc_xml_attr_numfmtid TYPE string VALUE 'numFmtId', - lc_xml_attr_fontid TYPE string VALUE 'fontId', - lc_xml_attr_fillid TYPE string VALUE 'fillId', - lc_xml_attr_borderid TYPE string VALUE 'borderId', - lc_xml_attr_xfid TYPE string VALUE 'xfId', - lc_xml_attr_applynumberformat TYPE string VALUE 'applyNumberFormat', - lc_xml_attr_applyprotection TYPE string VALUE 'applyProtection', - lc_xml_attr_applyfont TYPE string VALUE 'applyFont', - lc_xml_attr_applyfill TYPE string VALUE 'applyFill', - lc_xml_attr_applyborder TYPE string VALUE 'applyBorder', - lc_xml_attr_name TYPE string VALUE 'name', - lc_xml_attr_builtinid TYPE string VALUE 'builtinId', - lc_xml_attr_defaulttablestyle TYPE string VALUE 'defaultTableStyle', - lc_xml_attr_defaultpivotstyle TYPE string VALUE 'defaultPivotStyle', - lc_xml_attr_applyalignment TYPE string VALUE 'applyAlignment', - lc_xml_attr_horizontal TYPE string VALUE 'horizontal', - lc_xml_attr_formatcode TYPE string VALUE 'formatCode', - lc_xml_attr_vertical TYPE string VALUE 'vertical', - lc_xml_attr_wraptext TYPE string VALUE 'wrapText', - lc_xml_attr_textrotation TYPE string VALUE 'textRotation', - lc_xml_attr_shrinktofit TYPE string VALUE 'shrinkToFit', - lc_xml_attr_indent TYPE string VALUE 'indent', - lc_xml_attr_locked TYPE string VALUE 'locked', - lc_xml_attr_hidden TYPE string VALUE 'hidden', - lc_xml_attr_diagonalup TYPE string VALUE 'diagonalUp', - lc_xml_attr_diagonaldown TYPE string VALUE 'diagonalDown', - " Node namespace - lc_xml_node_ns TYPE string VALUE 'http://schemas.openxmlformats.org/spreadsheetml/2006/main'. + CONSTANTS: lc_xml_node_stylesheet TYPE string VALUE 'styleSheet', + " font + lc_xml_node_fonts TYPE string VALUE 'fonts', + lc_xml_node_font TYPE string VALUE 'font', + lc_xml_node_b TYPE string VALUE 'b', "bold + lc_xml_node_i TYPE string VALUE 'i', "italic + lc_xml_node_u TYPE string VALUE 'u', "underline + lc_xml_node_strike TYPE string VALUE 'strike', "strikethrough + lc_xml_node_sz TYPE string VALUE 'sz', + lc_xml_node_color TYPE string VALUE 'color', + lc_xml_node_name TYPE string VALUE 'name', + lc_xml_node_family TYPE string VALUE 'family', + lc_xml_node_scheme TYPE string VALUE 'scheme', + " fill + lc_xml_node_fills TYPE string VALUE 'fills', + lc_xml_node_fill TYPE string VALUE 'fill', + lc_xml_node_patternfill TYPE string VALUE 'patternFill', + lc_xml_node_fgcolor TYPE string VALUE 'fgColor', + lc_xml_node_bgcolor TYPE string VALUE 'bgColor', + lc_xml_node_gradientfill TYPE string VALUE 'gradientFill', + lc_xml_node_stop TYPE string VALUE 'stop', + " borders + lc_xml_node_borders TYPE string VALUE 'borders', + lc_xml_node_border TYPE string VALUE 'border', + lc_xml_node_left TYPE string VALUE 'left', + lc_xml_node_right TYPE string VALUE 'right', + lc_xml_node_top TYPE string VALUE 'top', + lc_xml_node_bottom TYPE string VALUE 'bottom', + lc_xml_node_diagonal TYPE string VALUE 'diagonal', + " numfmt + lc_xml_node_numfmts TYPE string VALUE 'numFmts', + lc_xml_node_numfmt TYPE string VALUE 'numFmt', + " Styles + lc_xml_node_cellstylexfs TYPE string VALUE 'cellStyleXfs', + lc_xml_node_xf TYPE string VALUE 'xf', + lc_xml_node_cellxfs TYPE string VALUE 'cellXfs', + lc_xml_node_cellstyles TYPE string VALUE 'cellStyles', + lc_xml_node_cellstyle TYPE string VALUE 'cellStyle', + lc_xml_node_dxfs TYPE string VALUE 'dxfs', + lc_xml_node_dxf TYPE string VALUE 'dxf', + lc_xml_node_tablestyles TYPE string VALUE 'tableStyles', + " Colors + lc_xml_node_colors TYPE string VALUE 'colors', + lc_xml_node_indexedcolors TYPE string VALUE 'indexedColors', + lc_xml_node_rgbcolor TYPE string VALUE 'rgbColor', + lc_xml_node_mrucolors TYPE string VALUE 'mruColors', + " Alignment + lc_xml_node_alignment TYPE string VALUE 'alignment', + " Protection + lc_xml_node_protection TYPE string VALUE 'protection', + " Node attributes + lc_xml_attr_count TYPE string VALUE 'count', + lc_xml_attr_val TYPE string VALUE 'val', + lc_xml_attr_theme TYPE string VALUE 'theme', + lc_xml_attr_rgb TYPE string VALUE 'rgb', + lc_xml_attr_indexed TYPE string VALUE 'indexed', + lc_xml_attr_tint TYPE string VALUE 'tint', + lc_xml_attr_style TYPE string VALUE 'style', + lc_xml_attr_position TYPE string VALUE 'position', + lc_xml_attr_degree TYPE string VALUE 'degree', + lc_xml_attr_patterntype TYPE string VALUE 'patternType', + lc_xml_attr_numfmtid TYPE string VALUE 'numFmtId', + lc_xml_attr_fontid TYPE string VALUE 'fontId', + lc_xml_attr_fillid TYPE string VALUE 'fillId', + lc_xml_attr_borderid TYPE string VALUE 'borderId', + lc_xml_attr_xfid TYPE string VALUE 'xfId', + lc_xml_attr_applynumberformat TYPE string VALUE 'applyNumberFormat', + lc_xml_attr_applyprotection TYPE string VALUE 'applyProtection', + lc_xml_attr_applyfont TYPE string VALUE 'applyFont', + lc_xml_attr_applyfill TYPE string VALUE 'applyFill', + lc_xml_attr_applyborder TYPE string VALUE 'applyBorder', + lc_xml_attr_name TYPE string VALUE 'name', + lc_xml_attr_builtinid TYPE string VALUE 'builtinId', + lc_xml_attr_defaulttablestyle TYPE string VALUE 'defaultTableStyle', + lc_xml_attr_defaultpivotstyle TYPE string VALUE 'defaultPivotStyle', + lc_xml_attr_applyalignment TYPE string VALUE 'applyAlignment', + lc_xml_attr_horizontal TYPE string VALUE 'horizontal', + lc_xml_attr_formatcode TYPE string VALUE 'formatCode', + lc_xml_attr_vertical TYPE string VALUE 'vertical', + lc_xml_attr_wraptext TYPE string VALUE 'wrapText', + lc_xml_attr_textrotation TYPE string VALUE 'textRotation', + lc_xml_attr_shrinktofit TYPE string VALUE 'shrinkToFit', + lc_xml_attr_indent TYPE string VALUE 'indent', + lc_xml_attr_locked TYPE string VALUE 'locked', + lc_xml_attr_hidden TYPE string VALUE 'hidden', + lc_xml_attr_diagonalup TYPE string VALUE 'diagonalUp', + lc_xml_attr_diagonaldown TYPE string VALUE 'diagonalDown', + " Node namespace + lc_xml_node_ns TYPE string VALUE 'http://schemas.openxmlformats.org/spreadsheetml/2006/main'. - DATA: lo_ixml TYPE REF TO if_ixml, - lo_document TYPE REF TO if_ixml_document, - lo_element_root TYPE REF TO if_ixml_element, - lo_element_fonts TYPE REF TO if_ixml_element, - lo_element_font TYPE REF TO if_ixml_element, - lo_element_fills TYPE REF TO if_ixml_element, - lo_element_fill TYPE REF TO if_ixml_element, - lo_element_borders TYPE REF TO if_ixml_element, - lo_element_border TYPE REF TO if_ixml_element, - lo_element_numfmts TYPE REF TO if_ixml_element, - lo_element_numfmt TYPE REF TO if_ixml_element, - lo_element_cellxfs TYPE REF TO if_ixml_element, - lo_element TYPE REF TO if_ixml_element, - lo_sub_element TYPE REF TO if_ixml_element, - lo_sub_element_2 TYPE REF TO if_ixml_element, - lo_encoding TYPE REF TO if_ixml_encoding, - lo_streamfactory TYPE REF TO if_ixml_stream_factory, - lo_ostream TYPE REF TO if_ixml_ostream, - lo_renderer TYPE REF TO if_ixml_renderer, - lo_iterator TYPE REF TO cl_object_collection_iterator, - lo_iterator2 TYPE REF TO cl_object_collection_iterator, - lo_worksheet TYPE REF TO zcl_excel_worksheet, - lo_style_conditional TYPE REF TO zcl_excel_style_conditional, - lo_style TYPE REF TO zcl_excel_style. + DATA: lo_ixml TYPE REF TO if_ixml, + lo_document TYPE REF TO if_ixml_document, + lo_element_root TYPE REF TO if_ixml_element, + lo_element_fonts TYPE REF TO if_ixml_element, + lo_element_font TYPE REF TO if_ixml_element, + lo_element_fills TYPE REF TO if_ixml_element, + lo_element_fill TYPE REF TO if_ixml_element, + lo_element_borders TYPE REF TO if_ixml_element, + lo_element_border TYPE REF TO if_ixml_element, + lo_element_numfmts TYPE REF TO if_ixml_element, + lo_element_numfmt TYPE REF TO if_ixml_element, + lo_element_cellxfs TYPE REF TO if_ixml_element, + lo_element TYPE REF TO if_ixml_element, + lo_sub_element TYPE REF TO if_ixml_element, + lo_sub_element_2 TYPE REF TO if_ixml_element, + lo_encoding TYPE REF TO if_ixml_encoding, + lo_streamfactory TYPE REF TO if_ixml_stream_factory, + lo_ostream TYPE REF TO if_ixml_ostream, + lo_renderer TYPE REF TO if_ixml_renderer, + lo_iterator TYPE REF TO cl_object_collection_iterator, + lo_iterator2 TYPE REF TO cl_object_collection_iterator, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + lo_style_conditional TYPE REF TO zcl_excel_style_conditional, + lo_style TYPE REF TO zcl_excel_style. - DATA: lt_fonts TYPE zexcel_t_style_font, - ls_font TYPE zexcel_s_style_font, - lt_fills TYPE zexcel_t_style_fill, - ls_fill TYPE zexcel_s_style_fill, - lt_borders TYPE zexcel_t_style_border, - ls_border TYPE zexcel_s_style_border, - lt_numfmts TYPE zexcel_t_style_numfmt, - ls_numfmt TYPE zexcel_s_style_numfmt, - lt_protections TYPE zexcel_t_style_protection, - ls_protection TYPE zexcel_s_style_protection, - lt_alignments TYPE zexcel_t_style_alignment, - ls_alignment TYPE zexcel_s_style_alignment, - lt_cellxfs TYPE zexcel_t_cellxfs, - ls_cellxfs TYPE zexcel_s_cellxfs, - ls_styles_mapping TYPE zexcel_s_styles_mapping, - ls_style_cond_mapping TYPE zexcel_s_styles_cond_mapping, - ls_cellis TYPE zexcel_conditional_cellis, - ls_expression TYPE zexcel_conditional_expression, - lt_colors TYPE zexcel_t_style_color_argb, - ls_color LIKE LINE OF lt_colors. + DATA: lt_fonts TYPE zexcel_t_style_font, + ls_font TYPE zexcel_s_style_font, + lt_fills TYPE zexcel_t_style_fill, + ls_fill TYPE zexcel_s_style_fill, + lt_borders TYPE zexcel_t_style_border, + ls_border TYPE zexcel_s_style_border, + lt_numfmts TYPE zexcel_t_style_numfmt, + ls_numfmt TYPE zexcel_s_style_numfmt, + lt_protections TYPE zexcel_t_style_protection, + ls_protection TYPE zexcel_s_style_protection, + lt_alignments TYPE zexcel_t_style_alignment, + ls_alignment TYPE zexcel_s_style_alignment, + lt_cellxfs TYPE zexcel_t_cellxfs, + ls_cellxfs TYPE zexcel_s_cellxfs, + ls_styles_mapping TYPE zexcel_s_styles_mapping, + ls_style_cond_mapping TYPE zexcel_s_styles_cond_mapping, + ls_cellis TYPE zexcel_conditional_cellis, + ls_expression TYPE zexcel_conditional_expression, + lt_colors TYPE zexcel_t_style_color_argb, + ls_color LIKE LINE OF lt_colors. - DATA: lv_value TYPE string, - lv_dfx_count TYPE i, - lv_fonts_count TYPE i, - lv_fills_count TYPE i, - lv_borders_count TYPE i, - lv_cellxfs_count TYPE i, - lv_align_flag TYPE c. + DATA: lv_value TYPE string, + lv_dfx_count TYPE i, + lv_fonts_count TYPE i, + lv_fills_count TYPE i, + lv_borders_count TYPE i, + lv_cellxfs_count TYPE i, + lv_align_flag TYPE c. ********************************************************************** * STEP 1: Create [Content_Types].xml into the root of the ZIP - lo_ixml = cl_ixml=>create( ). + lo_ixml = cl_ixml=>create( ). ********************************************************************** * STEP 2: Set document attributes - lo_encoding = lo_ixml->create_encoding( byte_order = if_ixml_encoding=>co_platform_endian - character_set = 'utf-8' ). - lo_document = lo_ixml->create_document( ). - lo_document->set_encoding( lo_encoding ). - lo_document->set_standalone( abap_true ). + lo_encoding = lo_ixml->create_encoding( byte_order = if_ixml_encoding=>co_platform_endian + character_set = 'utf-8' ). + lo_document = lo_ixml->create_document( ). + lo_document->set_encoding( lo_encoding ). + lo_document->set_standalone( abap_true ). *********************************************************************** * STEP 3: Create main node relationships - lo_element_root = lo_document->create_simple_element( name = lc_xml_node_stylesheet - parent = lo_document ). - lo_element_root->set_attribute_ns( name = 'xmlns' - value = lc_xml_node_ns ). + lo_element_root = lo_document->create_simple_element( name = lc_xml_node_stylesheet + parent = lo_document ). + lo_element_root->set_attribute_ns( name = 'xmlns' + value = lc_xml_node_ns ). ********************************************************************** * STEP 4: Create subnodes - lo_element_fonts = lo_document->create_simple_element( name = lc_xml_node_fonts - parent = lo_document ). - - lo_element_fills = lo_document->create_simple_element( name = lc_xml_node_fills - parent = lo_document ). - - lo_element_borders = lo_document->create_simple_element( name = lc_xml_node_borders + lo_element_fonts = lo_document->create_simple_element( name = lc_xml_node_fonts parent = lo_document ). - lo_element_cellxfs = lo_document->create_simple_element( name = lc_xml_node_cellxfs + lo_element_fills = lo_document->create_simple_element( name = lc_xml_node_fills parent = lo_document ). - lo_element_numfmts = lo_document->create_simple_element( name = lc_xml_node_numfmts - parent = lo_document ). + lo_element_borders = lo_document->create_simple_element( name = lc_xml_node_borders + parent = lo_document ). + + lo_element_cellxfs = lo_document->create_simple_element( name = lc_xml_node_cellxfs + parent = lo_document ). + + lo_element_numfmts = lo_document->create_simple_element( name = lc_xml_node_numfmts + parent = lo_document ). * Compress styles - lo_iterator = excel->get_styles_iterator( ). - WHILE lo_iterator->if_object_collection_iterator~has_next( ) EQ abap_true. - lo_style ?= lo_iterator->if_object_collection_iterator~get_next( ). - ls_font = lo_style->font->get_structure( ). - ls_fill = lo_style->fill->get_structure( ). - ls_border = lo_style->borders->get_structure( ). - ls_alignment = lo_style->alignment->get_structure( ). - ls_protection = lo_style->protection->get_structure( ). - ls_numfmt = lo_style->number_format->get_structure( ). + lo_iterator = excel->get_styles_iterator( ). + WHILE lo_iterator->if_object_collection_iterator~has_next( ) EQ abap_true. + lo_style ?= lo_iterator->if_object_collection_iterator~get_next( ). + ls_font = lo_style->font->get_structure( ). + ls_fill = lo_style->fill->get_structure( ). + ls_border = lo_style->borders->get_structure( ). + ls_alignment = lo_style->alignment->get_structure( ). + ls_protection = lo_style->protection->get_structure( ). + ls_numfmt = lo_style->number_format->get_structure( ). - CLEAR ls_cellxfs. + CLEAR ls_cellxfs. * Compress fonts - READ TABLE lt_fonts FROM ls_font TRANSPORTING NO FIELDS. - IF sy-subrc EQ 0. - ls_cellxfs-fontid = sy-tabix. - ELSE. - APPEND ls_font TO lt_fonts. - DESCRIBE TABLE lt_fonts LINES ls_cellxfs-fontid. - ENDIF. - SUBTRACT 1 FROM ls_cellxfs-fontid. + READ TABLE lt_fonts FROM ls_font TRANSPORTING NO FIELDS. + IF sy-subrc EQ 0. + ls_cellxfs-fontid = sy-tabix. + ELSE. + APPEND ls_font TO lt_fonts. + DESCRIBE TABLE lt_fonts LINES ls_cellxfs-fontid. + ENDIF. + SUBTRACT 1 FROM ls_cellxfs-fontid. * Compress alignment - READ TABLE lt_alignments FROM ls_alignment TRANSPORTING NO FIELDS. - IF sy-subrc EQ 0. - ls_cellxfs-alignmentid = sy-tabix. - ELSE. - APPEND ls_alignment TO lt_alignments. - DESCRIBE TABLE lt_alignments LINES ls_cellxfs-alignmentid. - ENDIF. - SUBTRACT 1 FROM ls_cellxfs-alignmentid. + READ TABLE lt_alignments FROM ls_alignment TRANSPORTING NO FIELDS. + IF sy-subrc EQ 0. + ls_cellxfs-alignmentid = sy-tabix. + ELSE. + APPEND ls_alignment TO lt_alignments. + DESCRIBE TABLE lt_alignments LINES ls_cellxfs-alignmentid. + ENDIF. + SUBTRACT 1 FROM ls_cellxfs-alignmentid. * Compress fills - READ TABLE lt_fills FROM ls_fill TRANSPORTING NO FIELDS. - IF sy-subrc EQ 0. - ls_cellxfs-fillid = sy-tabix. - ELSE. - APPEND ls_fill TO lt_fills. - DESCRIBE TABLE lt_fills LINES ls_cellxfs-fillid. - ENDIF. - SUBTRACT 1 FROM ls_cellxfs-fillid. + READ TABLE lt_fills FROM ls_fill TRANSPORTING NO FIELDS. + IF sy-subrc EQ 0. + ls_cellxfs-fillid = sy-tabix. + ELSE. + APPEND ls_fill TO lt_fills. + DESCRIBE TABLE lt_fills LINES ls_cellxfs-fillid. + ENDIF. + SUBTRACT 1 FROM ls_cellxfs-fillid. * Compress borders - READ TABLE lt_borders FROM ls_border TRANSPORTING NO FIELDS. - IF sy-subrc EQ 0. - ls_cellxfs-borderid = sy-tabix. - ELSE. - APPEND ls_border TO lt_borders. - DESCRIBE TABLE lt_borders LINES ls_cellxfs-borderid. - ENDIF. - SUBTRACT 1 FROM ls_cellxfs-borderid. + READ TABLE lt_borders FROM ls_border TRANSPORTING NO FIELDS. + IF sy-subrc EQ 0. + ls_cellxfs-borderid = sy-tabix. + ELSE. + APPEND ls_border TO lt_borders. + DESCRIBE TABLE lt_borders LINES ls_cellxfs-borderid. + ENDIF. + SUBTRACT 1 FROM ls_cellxfs-borderid. * Compress protection - IF ls_protection-locked EQ c_on AND ls_protection-hidden EQ c_off. - ls_cellxfs-applyprotection = 0. - ELSE. - READ TABLE lt_protections FROM ls_protection TRANSPORTING NO FIELDS. - IF sy-subrc EQ 0. - ls_cellxfs-protectionid = sy-tabix. + IF ls_protection-locked EQ c_on AND ls_protection-hidden EQ c_off. + ls_cellxfs-applyprotection = 0. ELSE. - APPEND ls_protection TO lt_protections. - DESCRIBE TABLE lt_protections LINES ls_cellxfs-protectionid. + READ TABLE lt_protections FROM ls_protection TRANSPORTING NO FIELDS. + IF sy-subrc EQ 0. + ls_cellxfs-protectionid = sy-tabix. + ELSE. + APPEND ls_protection TO lt_protections. + DESCRIBE TABLE lt_protections LINES ls_cellxfs-protectionid. + ENDIF. + ls_cellxfs-applyprotection = 1. ENDIF. - ls_cellxfs-applyprotection = 1. - ENDIF. - SUBTRACT 1 FROM ls_cellxfs-protectionid. + SUBTRACT 1 FROM ls_cellxfs-protectionid. * Compress number formats - "----------- - IF ls_numfmt-numfmt NE zcl_excel_style_number_format=>c_format_date_std." and ls_numfmt-NUMFMT ne 'STD_NDEC'. " ALE Changes on going - "--- - IF ls_numfmt IS NOT INITIAL. + "----------- + IF ls_numfmt-numfmt NE zcl_excel_style_number_format=>c_format_date_std." and ls_numfmt-NUMFMT ne 'STD_NDEC'. " ALE Changes on going + "--- + IF ls_numfmt IS NOT INITIAL. - READ TABLE lt_numfmts FROM ls_numfmt TRANSPORTING NO FIELDS. - IF sy-subrc EQ 0. - ls_cellxfs-numfmtid = sy-tabix. + READ TABLE lt_numfmts FROM ls_numfmt TRANSPORTING NO FIELDS. + IF sy-subrc EQ 0. + ls_cellxfs-numfmtid = sy-tabix. + ELSE. + APPEND ls_numfmt TO lt_numfmts. + DESCRIBE TABLE lt_numfmts LINES ls_cellxfs-numfmtid. + ENDIF. + ADD zcl_excel_common=>c_excel_numfmt_offset TO ls_cellxfs-numfmtid. " Add OXML offset for custom styles + ls_cellxfs-applynumberformat = 1. ELSE. - APPEND ls_numfmt TO lt_numfmts. - DESCRIBE TABLE lt_numfmts LINES ls_cellxfs-numfmtid. + ls_cellxfs-applynumberformat = 0. ENDIF. - ADD zcl_excel_common=>c_excel_numfmt_offset TO ls_cellxfs-numfmtid. " Add OXML offset for custom styles - ls_cellxfs-applynumberformat = 1. + "----------- " ALE changes on going ELSE. - ls_cellxfs-applynumberformat = 0. - ENDIF. - "----------- " ALE changes on going - ELSE. - ls_cellxfs-applynumberformat = 1. - IF ls_numfmt-numfmt EQ zcl_excel_style_number_format=>c_format_date_std. - ls_cellxfs-numfmtid = 14. + ls_cellxfs-applynumberformat = 1. + IF ls_numfmt-numfmt EQ zcl_excel_style_number_format=>c_format_date_std. + ls_cellxfs-numfmtid = 14. * elseif ls_numfmt-NUMFMT eq 'STD_NDEC'. * ls_cellxfs-numfmtid = 2. + ENDIF. ENDIF. - ENDIF. - "--- + "--- - IF ls_cellxfs-fontid NE 0. - ls_cellxfs-applyfont = 1. - ELSE. - ls_cellxfs-applyfont = 0. - ENDIF. - IF ls_cellxfs-alignmentid NE 0. - ls_cellxfs-applyalignment = 1. - ELSE. - ls_cellxfs-applyalignment = 0. - ENDIF. - IF ls_cellxfs-fillid NE 0. - ls_cellxfs-applyfill = 1. - ELSE. - ls_cellxfs-applyfill = 0. - ENDIF. - IF ls_cellxfs-borderid NE 0. - ls_cellxfs-applyborder = 1. - ELSE. - ls_cellxfs-applyborder = 0. - ENDIF. + IF ls_cellxfs-fontid NE 0. + ls_cellxfs-applyfont = 1. + ELSE. + ls_cellxfs-applyfont = 0. + ENDIF. + IF ls_cellxfs-alignmentid NE 0. + ls_cellxfs-applyalignment = 1. + ELSE. + ls_cellxfs-applyalignment = 0. + ENDIF. + IF ls_cellxfs-fillid NE 0. + ls_cellxfs-applyfill = 1. + ELSE. + ls_cellxfs-applyfill = 0. + ENDIF. + IF ls_cellxfs-borderid NE 0. + ls_cellxfs-applyborder = 1. + ELSE. + ls_cellxfs-applyborder = 0. + ENDIF. * Remap styles - READ TABLE lt_cellxfs FROM ls_cellxfs TRANSPORTING NO FIELDS. - IF sy-subrc EQ 0. - ls_styles_mapping-style = sy-tabix. - ELSE. - APPEND ls_cellxfs TO lt_cellxfs. - DESCRIBE TABLE lt_cellxfs LINES ls_styles_mapping-style. - ENDIF. - SUBTRACT 1 FROM ls_styles_mapping-style. - ls_styles_mapping-guid = lo_style->get_guid( ). - APPEND ls_styles_mapping TO me->styles_mapping. - ENDWHILE. - - " create numfmt elements - LOOP AT lt_numfmts INTO ls_numfmt. - lo_element_numfmt = lo_document->create_simple_element( name = lc_xml_node_numfmt - parent = lo_document ). - lv_value = sy-tabix + zcl_excel_common=>c_excel_numfmt_offset. - CONDENSE lv_value. - lo_element_numfmt->set_attribute_ns( name = lc_xml_attr_numfmtid - value = lv_value ). - lv_value = ls_numfmt-numfmt. -* REPLACE ALL OCCURRENCES OF '.' IN lv_value WITH '\.'. - lo_element_numfmt->set_attribute_ns( name = lc_xml_attr_formatcode - value = lv_value ). - lo_element_numfmts->append_child( new_child = lo_element_numfmt ). - ENDLOOP. - - " create font elements - LOOP AT lt_fonts INTO ls_font. - lo_element_font = lo_document->create_simple_element( name = lc_xml_node_font - parent = lo_document ). - IF ls_font-bold EQ abap_true. - lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_b - parent = lo_document ). - lo_element_font->append_child( new_child = lo_sub_element ). - ENDIF. - IF ls_font-italic EQ abap_true. - lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_i - parent = lo_document ). - lo_element_font->append_child( new_child = lo_sub_element ). - ENDIF. - IF ls_font-underline EQ abap_true. - lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_u - parent = lo_document ). - lv_value = ls_font-underline_mode. - lo_sub_element->set_attribute_ns( name = lc_xml_attr_val - value = lv_value ). - lo_element_font->append_child( new_child = lo_sub_element ). - ENDIF. - IF ls_font-strikethrough EQ abap_true. - lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_strike - parent = lo_document ). - lo_element_font->append_child( new_child = lo_sub_element ). - ENDIF. - "size - lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_sz - parent = lo_document ). - lv_value = ls_font-size. - SHIFT lv_value RIGHT DELETING TRAILING space. - SHIFT lv_value LEFT DELETING LEADING space. - lo_sub_element->set_attribute_ns( name = lc_xml_attr_val - value = lv_value ). - lo_element_font->append_child( new_child = lo_sub_element ). - "color - create_xl_styles_color_node( - io_document = lo_document - io_parent = lo_element_font - is_color = ls_font-color ). - - "name - lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_name - parent = lo_document ). - lv_value = ls_font-name. - lo_sub_element->set_attribute_ns( name = lc_xml_attr_val - value = lv_value ). - lo_element_font->append_child( new_child = lo_sub_element ). - "family - lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_family - parent = lo_document ). - lv_value = ls_font-family. - SHIFT lv_value RIGHT DELETING TRAILING space. - SHIFT lv_value LEFT DELETING LEADING space. - lo_sub_element->set_attribute_ns( name = lc_xml_attr_val - value = lv_value ). - lo_element_font->append_child( new_child = lo_sub_element ). - "scheme - IF ls_font-scheme IS NOT INITIAL. - lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_scheme - parent = lo_document ). - lv_value = ls_font-scheme. - lo_sub_element->set_attribute_ns( name = lc_xml_attr_val - value = lv_value ). - lo_element_font->append_child( new_child = lo_sub_element ). - ENDIF. - lo_element_fonts->append_child( new_child = lo_element_font ). - ENDLOOP. - - " create fill elements - LOOP AT lt_fills INTO ls_fill. - lo_element_fill = lo_document->create_simple_element( name = lc_xml_node_fill - parent = lo_document ). - "pattern - lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_patternfill - parent = lo_document ). - lv_value = ls_fill-filltype. - lo_sub_element->set_attribute_ns( name = lc_xml_attr_patterntype - value = lv_value ). - " fgcolor - create_xl_styles_color_node( - io_document = lo_document - io_parent = lo_sub_element - is_color = ls_fill-fgcolor - iv_color_elem_name = lc_xml_node_fgcolor ). - - " bgcolor - create_xl_styles_color_node( - io_document = lo_document - io_parent = lo_sub_element - is_color = ls_fill-bgcolor - iv_color_elem_name = lc_xml_node_bgcolor ). - - lo_element_fill->append_child( new_child = lo_sub_element )."pattern - lo_element_fills->append_child( new_child = lo_element_fill ). - ENDLOOP. - - " create border elements - LOOP AT lt_borders INTO ls_border. - lo_element_border = lo_document->create_simple_element( name = lc_xml_node_border - parent = lo_document ). - - IF ls_border-diagonalup IS NOT INITIAL. - lv_value = ls_border-diagonalup. - CONDENSE lv_value. - lo_element_border->set_attribute_ns( name = lc_xml_attr_diagonalup - value = lv_value ). - ENDIF. - - IF ls_border-diagonaldown IS NOT INITIAL. - lv_value = ls_border-diagonaldown. - CONDENSE lv_value. - lo_element_border->set_attribute_ns( name = lc_xml_attr_diagonaldown - value = lv_value ). - ENDIF. - - "left - lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_left - parent = lo_document ). - IF ls_border-left_style IS NOT INITIAL. - lv_value = ls_border-left_style. - lo_sub_element->set_attribute_ns( name = lc_xml_attr_style - value = lv_value ). - ENDIF. - - create_xl_styles_color_node( - io_document = lo_document - io_parent = lo_sub_element - is_color = ls_border-left_color ). - - lo_element_border->append_child( new_child = lo_sub_element ). - - "right - lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_right - parent = lo_document ). - IF ls_border-right_style IS NOT INITIAL. - lv_value = ls_border-right_style. - lo_sub_element->set_attribute_ns( name = lc_xml_attr_style - value = lv_value ). - ENDIF. - - create_xl_styles_color_node( - io_document = lo_document - io_parent = lo_sub_element - is_color = ls_border-right_color ). - - lo_element_border->append_child( new_child = lo_sub_element ). - - "top - lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_top - parent = lo_document ). - IF ls_border-top_style IS NOT INITIAL. - lv_value = ls_border-top_style. - lo_sub_element->set_attribute_ns( name = lc_xml_attr_style - value = lv_value ). - ENDIF. - - create_xl_styles_color_node( - io_document = lo_document - io_parent = lo_sub_element - is_color = ls_border-top_color ). - - lo_element_border->append_child( new_child = lo_sub_element ). - - "bottom - lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_bottom - parent = lo_document ). - IF ls_border-bottom_style IS NOT INITIAL. - lv_value = ls_border-bottom_style. - lo_sub_element->set_attribute_ns( name = lc_xml_attr_style - value = lv_value ). - ENDIF. - - create_xl_styles_color_node( - io_document = lo_document - io_parent = lo_sub_element - is_color = ls_border-bottom_color ). - - lo_element_border->append_child( new_child = lo_sub_element ). - - "diagonal - lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_diagonal - parent = lo_document ). - IF ls_border-diagonal_style IS NOT INITIAL. - lv_value = ls_border-diagonal_style. - lo_sub_element->set_attribute_ns( name = lc_xml_attr_style - value = lv_value ). - ENDIF. - - create_xl_styles_color_node( - io_document = lo_document - io_parent = lo_sub_element - is_color = ls_border-diagonal_color ). - - lo_element_border->append_child( new_child = lo_sub_element ). - lo_element_borders->append_child( new_child = lo_element_border ). - ENDLOOP. - - " update attribute "count" - DESCRIBE TABLE lt_fonts LINES lv_fonts_count. - MOVE lv_fonts_count TO lv_value. - SHIFT lv_value RIGHT DELETING TRAILING space. - SHIFT lv_value LEFT DELETING LEADING space. - lo_element_fonts->set_attribute_ns( name = lc_xml_attr_count - value = lv_value ). - DESCRIBE TABLE lt_fills LINES lv_fills_count. - MOVE lv_fills_count TO lv_value. - SHIFT lv_value RIGHT DELETING TRAILING space. - SHIFT lv_value LEFT DELETING LEADING space. - lo_element_fills->set_attribute_ns( name = lc_xml_attr_count - value = lv_value ). - DESCRIBE TABLE lt_borders LINES lv_borders_count. - MOVE lv_borders_count TO lv_value. - SHIFT lv_value RIGHT DELETING TRAILING space. - SHIFT lv_value LEFT DELETING LEADING space. - lo_element_borders->set_attribute_ns( name = lc_xml_attr_count - value = lv_value ). - DESCRIBE TABLE lt_cellxfs LINES lv_cellxfs_count. - MOVE lv_cellxfs_count TO lv_value. - SHIFT lv_value RIGHT DELETING TRAILING space. - SHIFT lv_value LEFT DELETING LEADING space. - lo_element_cellxfs->set_attribute_ns( name = lc_xml_attr_count - value = lv_value ). - - " Append to root node - lo_element_root->append_child( new_child = lo_element_numfmts ). - lo_element_root->append_child( new_child = lo_element_fonts ). - lo_element_root->append_child( new_child = lo_element_fills ). - lo_element_root->append_child( new_child = lo_element_borders ). - - " cellstylexfs node - lo_element = lo_document->create_simple_element( name = lc_xml_node_cellstylexfs - parent = lo_document ). - lo_element->set_attribute_ns( name = lc_xml_attr_count - value = '1' ). - lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_xf - parent = lo_document ). - - lo_sub_element->set_attribute_ns( name = lc_xml_attr_numfmtid - value = c_off ). - lo_sub_element->set_attribute_ns( name = lc_xml_attr_fontid - value = c_off ). - lo_sub_element->set_attribute_ns( name = lc_xml_attr_fillid - value = c_off ). - lo_sub_element->set_attribute_ns( name = lc_xml_attr_borderid - value = c_off ). - - lo_element->append_child( new_child = lo_sub_element ). - lo_element_root->append_child( new_child = lo_element ). - - LOOP AT lt_cellxfs INTO ls_cellxfs. - lo_element = lo_document->create_simple_element( name = lc_xml_node_xf - parent = lo_document ). - MOVE ls_cellxfs-numfmtid TO lv_value. - SHIFT lv_value RIGHT DELETING TRAILING space. - SHIFT lv_value LEFT DELETING LEADING space. - lo_element->set_attribute_ns( name = lc_xml_attr_numfmtid - value = lv_value ). - MOVE ls_cellxfs-fontid TO lv_value. - SHIFT lv_value RIGHT DELETING TRAILING space. - SHIFT lv_value LEFT DELETING LEADING space. - lo_element->set_attribute_ns( name = lc_xml_attr_fontid - value = lv_value ). - MOVE ls_cellxfs-fillid TO lv_value. - SHIFT lv_value RIGHT DELETING TRAILING space. - SHIFT lv_value LEFT DELETING LEADING space. - lo_element->set_attribute_ns( name = lc_xml_attr_fillid - value = lv_value ). - MOVE ls_cellxfs-borderid TO lv_value. - SHIFT lv_value RIGHT DELETING TRAILING space. - SHIFT lv_value LEFT DELETING LEADING space. - lo_element->set_attribute_ns( name = lc_xml_attr_borderid - value = lv_value ). - MOVE ls_cellxfs-xfid TO lv_value. - SHIFT lv_value RIGHT DELETING TRAILING space. - SHIFT lv_value LEFT DELETING LEADING space. - lo_element->set_attribute_ns( name = lc_xml_attr_xfid - value = lv_value ). - IF ls_cellxfs-applynumberformat EQ 1. - MOVE ls_cellxfs-applynumberformat TO lv_value. - SHIFT lv_value RIGHT DELETING TRAILING space. - SHIFT lv_value LEFT DELETING LEADING space. - lo_element->set_attribute_ns( name = lc_xml_attr_applynumberformat - value = lv_value ). - ENDIF. - IF ls_cellxfs-applyfont EQ 1. - MOVE ls_cellxfs-applyfont TO lv_value. - SHIFT lv_value RIGHT DELETING TRAILING space. - SHIFT lv_value LEFT DELETING LEADING space. - lo_element->set_attribute_ns( name = lc_xml_attr_applyfont - value = lv_value ). - ENDIF. - IF ls_cellxfs-applyfill EQ 1. - MOVE ls_cellxfs-applyfill TO lv_value. - SHIFT lv_value RIGHT DELETING TRAILING space. - SHIFT lv_value LEFT DELETING LEADING space. - lo_element->set_attribute_ns( name = lc_xml_attr_applyfill - value = lv_value ). - ENDIF. - IF ls_cellxfs-applyborder EQ 1. - MOVE ls_cellxfs-applyborder TO lv_value. - SHIFT lv_value RIGHT DELETING TRAILING space. - SHIFT lv_value LEFT DELETING LEADING space. - lo_element->set_attribute_ns( name = lc_xml_attr_applyborder - value = lv_value ). - ENDIF. - IF ls_cellxfs-applyalignment EQ 1. " depends on each style not for all the sheet - MOVE ls_cellxfs-applyalignment TO lv_value. - SHIFT lv_value RIGHT DELETING TRAILING space. - SHIFT lv_value LEFT DELETING LEADING space. - lo_element->set_attribute_ns( name = lc_xml_attr_applyalignment - value = lv_value ). - lo_sub_element_2 = lo_document->create_simple_element( name = lc_xml_node_alignment - parent = lo_document ). - ADD 1 TO ls_cellxfs-alignmentid. "Table index starts from 1 - READ TABLE lt_alignments INTO ls_alignment INDEX ls_cellxfs-alignmentid. - SUBTRACT 1 FROM ls_cellxfs-alignmentid. - IF ls_alignment-horizontal IS NOT INITIAL. - MOVE ls_alignment-horizontal TO lv_value. - lo_sub_element_2->set_attribute_ns( name = lc_xml_attr_horizontal - value = lv_value ). + READ TABLE lt_cellxfs FROM ls_cellxfs TRANSPORTING NO FIELDS. + IF sy-subrc EQ 0. + ls_styles_mapping-style = sy-tabix. + ELSE. + APPEND ls_cellxfs TO lt_cellxfs. + DESCRIBE TABLE lt_cellxfs LINES ls_styles_mapping-style. ENDIF. - IF ls_alignment-vertical IS NOT INITIAL. - MOVE ls_alignment-vertical TO lv_value. - lo_sub_element_2->set_attribute_ns( name = lc_xml_attr_vertical - value = lv_value ). - ENDIF. - IF ls_alignment-wraptext EQ abap_true. - lo_sub_element_2->set_attribute_ns( name = lc_xml_attr_wraptext - value = c_on ). - ENDIF. - IF ls_alignment-textrotation IS NOT INITIAL. - MOVE ls_alignment-textrotation TO lv_value. - SHIFT lv_value RIGHT DELETING TRAILING space. - SHIFT lv_value LEFT DELETING LEADING space. - lo_sub_element_2->set_attribute_ns( name = lc_xml_attr_textrotation - value = lv_value ). - ENDIF. - IF ls_alignment-shrinktofit EQ abap_true. - lo_sub_element_2->set_attribute_ns( name = lc_xml_attr_shrinktofit - value = c_on ). - ENDIF. - IF ls_alignment-indent IS NOT INITIAL. - MOVE ls_alignment-indent TO lv_value. - SHIFT lv_value RIGHT DELETING TRAILING space. - SHIFT lv_value LEFT DELETING LEADING space. - lo_sub_element_2->set_attribute_ns( name = lc_xml_attr_indent - value = lv_value ). - ENDIF. - - lo_element->append_child( new_child = lo_sub_element_2 ). - ENDIF. - IF ls_cellxfs-applyprotection EQ 1. - MOVE ls_cellxfs-applyprotection TO lv_value. - CONDENSE lv_value NO-GAPS. - lo_element->set_attribute_ns( name = lc_xml_attr_applyprotection - value = lv_value ). - lo_sub_element_2 = lo_document->create_simple_element( name = lc_xml_node_protection - parent = lo_document ). - ADD 1 TO ls_cellxfs-protectionid. "Table index starts from 1 - READ TABLE lt_protections INTO ls_protection INDEX ls_cellxfs-protectionid. - SUBTRACT 1 FROM ls_cellxfs-protectionid. - IF ls_protection-locked IS NOT INITIAL. - MOVE ls_protection-locked TO lv_value. - CONDENSE lv_value. - lo_sub_element_2->set_attribute_ns( name = lc_xml_attr_locked - value = lv_value ). - ENDIF. - IF ls_protection-hidden IS NOT INITIAL. - MOVE ls_protection-hidden TO lv_value. - CONDENSE lv_value. - lo_sub_element_2->set_attribute_ns( name = lc_xml_attr_hidden - value = lv_value ). - ENDIF. - lo_element->append_child( new_child = lo_sub_element_2 ). - ENDIF. - lo_element_cellxfs->append_child( new_child = lo_element ). - ENDLOOP. - - lo_element_root->append_child( new_child = lo_element_cellxfs ). - - " cellStyles node - lo_element = lo_document->create_simple_element( name = lc_xml_node_cellstyles - parent = lo_document ). - lo_element->set_attribute_ns( name = lc_xml_attr_count - value = '1' ). - lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_cellstyle - parent = lo_document ). - - lo_sub_element->set_attribute_ns( name = lc_xml_attr_name - value = 'Normal' ). - lo_sub_element->set_attribute_ns( name = lc_xml_attr_xfid - value = c_off ). - lo_sub_element->set_attribute_ns( name = lc_xml_attr_builtinid - value = c_off ). - - lo_element->append_child( new_child = lo_sub_element ). - lo_element_root->append_child( new_child = lo_element ). - - " dxfs node - lo_element = lo_document->create_simple_element( name = lc_xml_node_dxfs - parent = lo_document ). - - lo_iterator = me->excel->get_worksheets_iterator( ). - " get sheets - WHILE lo_iterator->if_object_collection_iterator~has_next( ) EQ abap_true. - lo_worksheet ?= lo_iterator->if_object_collection_iterator~get_next( ). - " Conditional formatting styles into exch sheet - lo_iterator2 = lo_worksheet->get_cond_styles_iterator( ). - WHILE lo_iterator2->if_object_collection_iterator~has_next( ) EQ abap_true. - lo_style_conditional ?= lo_iterator2->if_object_collection_iterator~get_next( ). - CASE lo_style_conditional->rule. - WHEN zcl_excel_style_conditional=>c_rule_cellis. - "if style defined - ls_cellis = lo_style_conditional->mode_cellis. - IF ls_cellis-cell_style IS INITIAL. - CONTINUE. - ENDIF. - READ TABLE me->styles_mapping INTO ls_styles_mapping WITH KEY guid = ls_cellis-cell_style. - ADD 1 TO ls_styles_mapping-style. " the numbering starts from 0 - READ TABLE lt_cellxfs INTO ls_cellxfs INDEX ls_styles_mapping-style. - ADD 1 TO ls_cellxfs-fillid. " the numbering starts from 0 - - " Style already mapped? - READ TABLE me->styles_cond_mapping INTO ls_style_cond_mapping WITH KEY style = ls_styles_mapping-style. - IF sy-subrc EQ 0. - ls_style_cond_mapping-guid = ls_cellis-cell_style. - APPEND ls_style_cond_mapping TO me->styles_cond_mapping. - ELSE. - ls_style_cond_mapping-guid = ls_cellis-cell_style. - ls_style_cond_mapping-style = ls_styles_mapping-style. - ls_style_cond_mapping-dxf = lv_dfx_count. - APPEND ls_style_cond_mapping TO me->styles_cond_mapping. - ADD 1 TO lv_dfx_count. - - " dxf node - lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_dxf - parent = lo_document ). - - READ TABLE lt_fills INTO ls_fill INDEX ls_cellxfs-fillid. - IF ls_fill IS NOT INITIAL. - " fill properties - lo_element_fill = lo_document->create_simple_element( name = lc_xml_node_fill - parent = lo_document ). - "pattern - lo_sub_element_2 = lo_document->create_simple_element( name = lc_xml_node_patternfill - parent = lo_document ). - lv_value = ls_fill-filltype. - lo_sub_element_2->set_attribute_ns( name = lc_xml_attr_patterntype - value = lv_value ). - " fgcolor - create_xl_styles_color_node( - io_document = lo_document - io_parent = lo_sub_element_2 - is_color = ls_fill-fgcolor - iv_color_elem_name = lc_xml_node_fgcolor ). - - " bgcolor - create_xl_styles_color_node( - io_document = lo_document - io_parent = lo_sub_element_2 - is_color = ls_fill-bgcolor - iv_color_elem_name = lc_xml_node_bgcolor ). - - lo_element_fill->append_child( new_child = lo_sub_element_2 ). "pattern - - lo_sub_element->append_child( new_child = lo_element_fill ). - ENDIF. - ENDIF. - - lo_element->append_child( new_child = lo_sub_element ). - WHEN zcl_excel_style_conditional=>c_rule_expression. - "if style defined - ls_expression = lo_style_conditional->mode_expression. - IF ls_expression-cell_style IS INITIAL. - CONTINUE. - ENDIF. - READ TABLE me->styles_mapping INTO ls_styles_mapping WITH KEY guid = ls_expression-cell_style. - ADD 1 TO ls_styles_mapping-style. " the numbering starts from 0 - READ TABLE lt_cellxfs INTO ls_cellxfs INDEX ls_styles_mapping-style. - ADD 1 TO ls_cellxfs-fillid. " the numbering starts from 0 - - READ TABLE me->styles_cond_mapping INTO ls_style_cond_mapping WITH KEY style = ls_styles_mapping-style. - IF sy-subrc EQ 0. - ls_style_cond_mapping-guid = ls_expression-cell_style. - APPEND ls_style_cond_mapping TO me->styles_cond_mapping. - ELSE. - ls_style_cond_mapping-guid = ls_expression-cell_style. - ls_style_cond_mapping-style = ls_styles_mapping-style. - ls_style_cond_mapping-dxf = lv_dfx_count. - APPEND ls_style_cond_mapping TO me->styles_cond_mapping. - ADD 1 TO lv_dfx_count. - - " dxf node - lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_dxf - parent = lo_document ). - - READ TABLE lt_fills INTO ls_fill INDEX ls_cellxfs-fillid. - IF ls_fill IS NOT INITIAL. - " fill properties - lo_element_fill = lo_document->create_simple_element( name = lc_xml_node_fill - parent = lo_document ). - "pattern - lo_sub_element_2 = lo_document->create_simple_element( name = lc_xml_node_patternfill - parent = lo_document ). - lv_value = ls_fill-filltype. - lo_sub_element_2->set_attribute_ns( name = lc_xml_attr_patterntype - value = lv_value ). - " fgcolor - create_xl_styles_color_node( - io_document = lo_document - io_parent = lo_sub_element_2 - is_color = ls_fill-fgcolor - iv_color_elem_name = lc_xml_node_fgcolor ). - - " bgcolor - create_xl_styles_color_node( - io_document = lo_document - io_parent = lo_sub_element_2 - is_color = ls_fill-bgcolor - iv_color_elem_name = lc_xml_node_bgcolor ). - - lo_element_fill->append_child( new_child = lo_sub_element_2 ). "pattern - - lo_sub_element->append_child( new_child = lo_element_fill ). - ENDIF. - ENDIF. - - lo_element->append_child( new_child = lo_sub_element ). - WHEN OTHERS. - CONTINUE. - ENDCASE. + SUBTRACT 1 FROM ls_styles_mapping-style. + ls_styles_mapping-guid = lo_style->get_guid( ). + APPEND ls_styles_mapping TO me->styles_mapping. ENDWHILE. - ENDWHILE. - lv_value = lv_dfx_count. - CONDENSE lv_value. - lo_element->set_attribute_ns( name = lc_xml_attr_count - value = lv_value ). - lo_element_root->append_child( new_child = lo_element ). - - " tableStyles node - lo_element = lo_document->create_simple_element( name = lc_xml_node_tablestyles - parent = lo_document ). - lo_element->set_attribute_ns( name = lc_xml_attr_count - value = '0' ). - lo_element->set_attribute_ns( name = lc_xml_attr_defaulttablestyle - value = zcl_excel_table=>builtinstyle_medium9 ). - lo_element->set_attribute_ns( name = lc_xml_attr_defaultpivotstyle - value = zcl_excel_table=>builtinstyle_pivot_light16 ). - lo_element_root->append_child( new_child = lo_element ). - - "write legacy color palette in case any indexed color was changed - IF excel->legacy_palette->is_modified( ) = abap_true. - lo_element = lo_document->create_simple_element( name = lc_xml_node_colors - parent = lo_document ). - lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_indexedcolors - parent = lo_document ). - lo_element->append_child( new_child = lo_sub_element ). - - lt_colors = excel->legacy_palette->get_colors( ). - LOOP AT lt_colors INTO ls_color. - lo_sub_element_2 = lo_document->create_simple_element( name = lc_xml_node_rgbcolor - parent = lo_document ). - lv_value = ls_color. - lo_sub_element_2->set_attribute_ns( name = lc_xml_attr_rgb - value = lv_value ). - lo_sub_element->append_child( new_child = lo_sub_element_2 ). + " create numfmt elements + LOOP AT lt_numfmts INTO ls_numfmt. + lo_element_numfmt = lo_document->create_simple_element( name = lc_xml_node_numfmt + parent = lo_document ). + lv_value = sy-tabix + zcl_excel_common=>c_excel_numfmt_offset. + CONDENSE lv_value. + lo_element_numfmt->set_attribute_ns( name = lc_xml_attr_numfmtid + value = lv_value ). + lv_value = ls_numfmt-numfmt. +* REPLACE ALL OCCURRENCES OF '.' IN lv_value WITH '\.'. + lo_element_numfmt->set_attribute_ns( name = lc_xml_attr_formatcode + value = lv_value ). + lo_element_numfmts->append_child( new_child = lo_element_numfmt ). ENDLOOP. + " create font elements + LOOP AT lt_fonts INTO ls_font. + lo_element_font = lo_document->create_simple_element( name = lc_xml_node_font + parent = lo_document ). + IF ls_font-bold EQ abap_true. + lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_b + parent = lo_document ). + lo_element_font->append_child( new_child = lo_sub_element ). + ENDIF. + IF ls_font-italic EQ abap_true. + lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_i + parent = lo_document ). + lo_element_font->append_child( new_child = lo_sub_element ). + ENDIF. + IF ls_font-underline EQ abap_true. + lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_u + parent = lo_document ). + lv_value = ls_font-underline_mode. + lo_sub_element->set_attribute_ns( name = lc_xml_attr_val + value = lv_value ). + lo_element_font->append_child( new_child = lo_sub_element ). + ENDIF. + IF ls_font-strikethrough EQ abap_true. + lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_strike + parent = lo_document ). + lo_element_font->append_child( new_child = lo_sub_element ). + ENDIF. + "size + lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_sz + parent = lo_document ). + lv_value = ls_font-size. + SHIFT lv_value RIGHT DELETING TRAILING space. + SHIFT lv_value LEFT DELETING LEADING space. + lo_sub_element->set_attribute_ns( name = lc_xml_attr_val + value = lv_value ). + lo_element_font->append_child( new_child = lo_sub_element ). + "color + create_xl_styles_color_node( + io_document = lo_document + io_parent = lo_element_font + is_color = ls_font-color ). + + "name + lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_name + parent = lo_document ). + lv_value = ls_font-name. + lo_sub_element->set_attribute_ns( name = lc_xml_attr_val + value = lv_value ). + lo_element_font->append_child( new_child = lo_sub_element ). + "family + lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_family + parent = lo_document ). + lv_value = ls_font-family. + SHIFT lv_value RIGHT DELETING TRAILING space. + SHIFT lv_value LEFT DELETING LEADING space. + lo_sub_element->set_attribute_ns( name = lc_xml_attr_val + value = lv_value ). + lo_element_font->append_child( new_child = lo_sub_element ). + "scheme + IF ls_font-scheme IS NOT INITIAL. + lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_scheme + parent = lo_document ). + lv_value = ls_font-scheme. + lo_sub_element->set_attribute_ns( name = lc_xml_attr_val + value = lv_value ). + lo_element_font->append_child( new_child = lo_sub_element ). + ENDIF. + lo_element_fonts->append_child( new_child = lo_element_font ). + ENDLOOP. + + " create fill elements + LOOP AT lt_fills INTO ls_fill. + lo_element_fill = lo_document->create_simple_element( name = lc_xml_node_fill + parent = lo_document ). + "pattern + lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_patternfill + parent = lo_document ). + lv_value = ls_fill-filltype. + lo_sub_element->set_attribute_ns( name = lc_xml_attr_patterntype + value = lv_value ). + " fgcolor + create_xl_styles_color_node( + io_document = lo_document + io_parent = lo_sub_element + is_color = ls_fill-fgcolor + iv_color_elem_name = lc_xml_node_fgcolor ). + + " bgcolor + create_xl_styles_color_node( + io_document = lo_document + io_parent = lo_sub_element + is_color = ls_fill-bgcolor + iv_color_elem_name = lc_xml_node_bgcolor ). + + lo_element_fill->append_child( new_child = lo_sub_element )."pattern + lo_element_fills->append_child( new_child = lo_element_fill ). + ENDLOOP. + + " create border elements + LOOP AT lt_borders INTO ls_border. + lo_element_border = lo_document->create_simple_element( name = lc_xml_node_border + parent = lo_document ). + + IF ls_border-diagonalup IS NOT INITIAL. + lv_value = ls_border-diagonalup. + CONDENSE lv_value. + lo_element_border->set_attribute_ns( name = lc_xml_attr_diagonalup + value = lv_value ). + ENDIF. + + IF ls_border-diagonaldown IS NOT INITIAL. + lv_value = ls_border-diagonaldown. + CONDENSE lv_value. + lo_element_border->set_attribute_ns( name = lc_xml_attr_diagonaldown + value = lv_value ). + ENDIF. + + "left + lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_left + parent = lo_document ). + IF ls_border-left_style IS NOT INITIAL. + lv_value = ls_border-left_style. + lo_sub_element->set_attribute_ns( name = lc_xml_attr_style + value = lv_value ). + ENDIF. + + create_xl_styles_color_node( + io_document = lo_document + io_parent = lo_sub_element + is_color = ls_border-left_color ). + + lo_element_border->append_child( new_child = lo_sub_element ). + + "right + lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_right + parent = lo_document ). + IF ls_border-right_style IS NOT INITIAL. + lv_value = ls_border-right_style. + lo_sub_element->set_attribute_ns( name = lc_xml_attr_style + value = lv_value ). + ENDIF. + + create_xl_styles_color_node( + io_document = lo_document + io_parent = lo_sub_element + is_color = ls_border-right_color ). + + lo_element_border->append_child( new_child = lo_sub_element ). + + "top + lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_top + parent = lo_document ). + IF ls_border-top_style IS NOT INITIAL. + lv_value = ls_border-top_style. + lo_sub_element->set_attribute_ns( name = lc_xml_attr_style + value = lv_value ). + ENDIF. + + create_xl_styles_color_node( + io_document = lo_document + io_parent = lo_sub_element + is_color = ls_border-top_color ). + + lo_element_border->append_child( new_child = lo_sub_element ). + + "bottom + lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_bottom + parent = lo_document ). + IF ls_border-bottom_style IS NOT INITIAL. + lv_value = ls_border-bottom_style. + lo_sub_element->set_attribute_ns( name = lc_xml_attr_style + value = lv_value ). + ENDIF. + + create_xl_styles_color_node( + io_document = lo_document + io_parent = lo_sub_element + is_color = ls_border-bottom_color ). + + lo_element_border->append_child( new_child = lo_sub_element ). + + "diagonal + lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_diagonal + parent = lo_document ). + IF ls_border-diagonal_style IS NOT INITIAL. + lv_value = ls_border-diagonal_style. + lo_sub_element->set_attribute_ns( name = lc_xml_attr_style + value = lv_value ). + ENDIF. + + create_xl_styles_color_node( + io_document = lo_document + io_parent = lo_sub_element + is_color = ls_border-diagonal_color ). + + lo_element_border->append_child( new_child = lo_sub_element ). + lo_element_borders->append_child( new_child = lo_element_border ). + ENDLOOP. + + " update attribute "count" + DESCRIBE TABLE lt_fonts LINES lv_fonts_count. + MOVE lv_fonts_count TO lv_value. + SHIFT lv_value RIGHT DELETING TRAILING space. + SHIFT lv_value LEFT DELETING LEADING space. + lo_element_fonts->set_attribute_ns( name = lc_xml_attr_count + value = lv_value ). + DESCRIBE TABLE lt_fills LINES lv_fills_count. + MOVE lv_fills_count TO lv_value. + SHIFT lv_value RIGHT DELETING TRAILING space. + SHIFT lv_value LEFT DELETING LEADING space. + lo_element_fills->set_attribute_ns( name = lc_xml_attr_count + value = lv_value ). + DESCRIBE TABLE lt_borders LINES lv_borders_count. + MOVE lv_borders_count TO lv_value. + SHIFT lv_value RIGHT DELETING TRAILING space. + SHIFT lv_value LEFT DELETING LEADING space. + lo_element_borders->set_attribute_ns( name = lc_xml_attr_count + value = lv_value ). + DESCRIBE TABLE lt_cellxfs LINES lv_cellxfs_count. + MOVE lv_cellxfs_count TO lv_value. + SHIFT lv_value RIGHT DELETING TRAILING space. + SHIFT lv_value LEFT DELETING LEADING space. + lo_element_cellxfs->set_attribute_ns( name = lc_xml_attr_count + value = lv_value ). + + " Append to root node + lo_element_root->append_child( new_child = lo_element_numfmts ). + lo_element_root->append_child( new_child = lo_element_fonts ). + lo_element_root->append_child( new_child = lo_element_fills ). + lo_element_root->append_child( new_child = lo_element_borders ). + + " cellstylexfs node + lo_element = lo_document->create_simple_element( name = lc_xml_node_cellstylexfs + parent = lo_document ). + lo_element->set_attribute_ns( name = lc_xml_attr_count + value = '1' ). + lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_xf + parent = lo_document ). + + lo_sub_element->set_attribute_ns( name = lc_xml_attr_numfmtid + value = c_off ). + lo_sub_element->set_attribute_ns( name = lc_xml_attr_fontid + value = c_off ). + lo_sub_element->set_attribute_ns( name = lc_xml_attr_fillid + value = c_off ). + lo_sub_element->set_attribute_ns( name = lc_xml_attr_borderid + value = c_off ). + + lo_element->append_child( new_child = lo_sub_element ). lo_element_root->append_child( new_child = lo_element ). - ENDIF. + + LOOP AT lt_cellxfs INTO ls_cellxfs. + lo_element = lo_document->create_simple_element( name = lc_xml_node_xf + parent = lo_document ). + MOVE ls_cellxfs-numfmtid TO lv_value. + SHIFT lv_value RIGHT DELETING TRAILING space. + SHIFT lv_value LEFT DELETING LEADING space. + lo_element->set_attribute_ns( name = lc_xml_attr_numfmtid + value = lv_value ). + MOVE ls_cellxfs-fontid TO lv_value. + SHIFT lv_value RIGHT DELETING TRAILING space. + SHIFT lv_value LEFT DELETING LEADING space. + lo_element->set_attribute_ns( name = lc_xml_attr_fontid + value = lv_value ). + MOVE ls_cellxfs-fillid TO lv_value. + SHIFT lv_value RIGHT DELETING TRAILING space. + SHIFT lv_value LEFT DELETING LEADING space. + lo_element->set_attribute_ns( name = lc_xml_attr_fillid + value = lv_value ). + MOVE ls_cellxfs-borderid TO lv_value. + SHIFT lv_value RIGHT DELETING TRAILING space. + SHIFT lv_value LEFT DELETING LEADING space. + lo_element->set_attribute_ns( name = lc_xml_attr_borderid + value = lv_value ). + MOVE ls_cellxfs-xfid TO lv_value. + SHIFT lv_value RIGHT DELETING TRAILING space. + SHIFT lv_value LEFT DELETING LEADING space. + lo_element->set_attribute_ns( name = lc_xml_attr_xfid + value = lv_value ). + IF ls_cellxfs-applynumberformat EQ 1. + MOVE ls_cellxfs-applynumberformat TO lv_value. + SHIFT lv_value RIGHT DELETING TRAILING space. + SHIFT lv_value LEFT DELETING LEADING space. + lo_element->set_attribute_ns( name = lc_xml_attr_applynumberformat + value = lv_value ). + ENDIF. + IF ls_cellxfs-applyfont EQ 1. + MOVE ls_cellxfs-applyfont TO lv_value. + SHIFT lv_value RIGHT DELETING TRAILING space. + SHIFT lv_value LEFT DELETING LEADING space. + lo_element->set_attribute_ns( name = lc_xml_attr_applyfont + value = lv_value ). + ENDIF. + IF ls_cellxfs-applyfill EQ 1. + MOVE ls_cellxfs-applyfill TO lv_value. + SHIFT lv_value RIGHT DELETING TRAILING space. + SHIFT lv_value LEFT DELETING LEADING space. + lo_element->set_attribute_ns( name = lc_xml_attr_applyfill + value = lv_value ). + ENDIF. + IF ls_cellxfs-applyborder EQ 1. + MOVE ls_cellxfs-applyborder TO lv_value. + SHIFT lv_value RIGHT DELETING TRAILING space. + SHIFT lv_value LEFT DELETING LEADING space. + lo_element->set_attribute_ns( name = lc_xml_attr_applyborder + value = lv_value ). + ENDIF. + IF ls_cellxfs-applyalignment EQ 1. " depends on each style not for all the sheet + MOVE ls_cellxfs-applyalignment TO lv_value. + SHIFT lv_value RIGHT DELETING TRAILING space. + SHIFT lv_value LEFT DELETING LEADING space. + lo_element->set_attribute_ns( name = lc_xml_attr_applyalignment + value = lv_value ). + lo_sub_element_2 = lo_document->create_simple_element( name = lc_xml_node_alignment + parent = lo_document ). + ADD 1 TO ls_cellxfs-alignmentid. "Table index starts from 1 + READ TABLE lt_alignments INTO ls_alignment INDEX ls_cellxfs-alignmentid. + SUBTRACT 1 FROM ls_cellxfs-alignmentid. + IF ls_alignment-horizontal IS NOT INITIAL. + MOVE ls_alignment-horizontal TO lv_value. + lo_sub_element_2->set_attribute_ns( name = lc_xml_attr_horizontal + value = lv_value ). + ENDIF. + IF ls_alignment-vertical IS NOT INITIAL. + MOVE ls_alignment-vertical TO lv_value. + lo_sub_element_2->set_attribute_ns( name = lc_xml_attr_vertical + value = lv_value ). + ENDIF. + IF ls_alignment-wraptext EQ abap_true. + lo_sub_element_2->set_attribute_ns( name = lc_xml_attr_wraptext + value = c_on ). + ENDIF. + IF ls_alignment-textrotation IS NOT INITIAL. + MOVE ls_alignment-textrotation TO lv_value. + SHIFT lv_value RIGHT DELETING TRAILING space. + SHIFT lv_value LEFT DELETING LEADING space. + lo_sub_element_2->set_attribute_ns( name = lc_xml_attr_textrotation + value = lv_value ). + ENDIF. + IF ls_alignment-shrinktofit EQ abap_true. + lo_sub_element_2->set_attribute_ns( name = lc_xml_attr_shrinktofit + value = c_on ). + ENDIF. + IF ls_alignment-indent IS NOT INITIAL. + MOVE ls_alignment-indent TO lv_value. + SHIFT lv_value RIGHT DELETING TRAILING space. + SHIFT lv_value LEFT DELETING LEADING space. + lo_sub_element_2->set_attribute_ns( name = lc_xml_attr_indent + value = lv_value ). + ENDIF. + + lo_element->append_child( new_child = lo_sub_element_2 ). + ENDIF. + IF ls_cellxfs-applyprotection EQ 1. + MOVE ls_cellxfs-applyprotection TO lv_value. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_applyprotection + value = lv_value ). + lo_sub_element_2 = lo_document->create_simple_element( name = lc_xml_node_protection + parent = lo_document ). + ADD 1 TO ls_cellxfs-protectionid. "Table index starts from 1 + READ TABLE lt_protections INTO ls_protection INDEX ls_cellxfs-protectionid. + SUBTRACT 1 FROM ls_cellxfs-protectionid. + IF ls_protection-locked IS NOT INITIAL. + MOVE ls_protection-locked TO lv_value. + CONDENSE lv_value. + lo_sub_element_2->set_attribute_ns( name = lc_xml_attr_locked + value = lv_value ). + ENDIF. + IF ls_protection-hidden IS NOT INITIAL. + MOVE ls_protection-hidden TO lv_value. + CONDENSE lv_value. + lo_sub_element_2->set_attribute_ns( name = lc_xml_attr_hidden + value = lv_value ). + ENDIF. + lo_element->append_child( new_child = lo_sub_element_2 ). + ENDIF. + lo_element_cellxfs->append_child( new_child = lo_element ). + ENDLOOP. + + lo_element_root->append_child( new_child = lo_element_cellxfs ). + + " cellStyles node + lo_element = lo_document->create_simple_element( name = lc_xml_node_cellstyles + parent = lo_document ). + lo_element->set_attribute_ns( name = lc_xml_attr_count + value = '1' ). + lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_cellstyle + parent = lo_document ). + + lo_sub_element->set_attribute_ns( name = lc_xml_attr_name + value = 'Normal' ). + lo_sub_element->set_attribute_ns( name = lc_xml_attr_xfid + value = c_off ). + lo_sub_element->set_attribute_ns( name = lc_xml_attr_builtinid + value = c_off ). + + lo_element->append_child( new_child = lo_sub_element ). + lo_element_root->append_child( new_child = lo_element ). + + " dxfs node + lo_element = lo_document->create_simple_element( name = lc_xml_node_dxfs + parent = lo_document ). + + lo_iterator = me->excel->get_worksheets_iterator( ). + " get sheets + WHILE lo_iterator->if_object_collection_iterator~has_next( ) EQ abap_true. + lo_worksheet ?= lo_iterator->if_object_collection_iterator~get_next( ). + " Conditional formatting styles into exch sheet + lo_iterator2 = lo_worksheet->get_cond_styles_iterator( ). + WHILE lo_iterator2->if_object_collection_iterator~has_next( ) EQ abap_true. + lo_style_conditional ?= lo_iterator2->if_object_collection_iterator~get_next( ). + CASE lo_style_conditional->rule. + WHEN zcl_excel_style_conditional=>c_rule_cellis. + "if style defined + ls_cellis = lo_style_conditional->mode_cellis. + IF ls_cellis-cell_style IS INITIAL. + CONTINUE. + ENDIF. + READ TABLE me->styles_mapping INTO ls_styles_mapping WITH KEY guid = ls_cellis-cell_style. + ADD 1 TO ls_styles_mapping-style. " the numbering starts from 0 + READ TABLE lt_cellxfs INTO ls_cellxfs INDEX ls_styles_mapping-style. + ADD 1 TO ls_cellxfs-fillid. " the numbering starts from 0 + + " Style already mapped? + READ TABLE me->styles_cond_mapping INTO ls_style_cond_mapping WITH KEY style = ls_styles_mapping-style. + IF sy-subrc EQ 0. + ls_style_cond_mapping-guid = ls_cellis-cell_style. + APPEND ls_style_cond_mapping TO me->styles_cond_mapping. + ELSE. + ls_style_cond_mapping-guid = ls_cellis-cell_style. + ls_style_cond_mapping-style = ls_styles_mapping-style. + ls_style_cond_mapping-dxf = lv_dfx_count. + APPEND ls_style_cond_mapping TO me->styles_cond_mapping. + ADD 1 TO lv_dfx_count. + + " dxf node + lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_dxf + parent = lo_document ). + +"Conditional formatting font style correction by Alessandro Iannacci START + READ TABLE lt_fonts into ls_font INDEX ls_cellxfs-FONTID + 1. + IF ls_font IS NOT INITIAL. + lo_element_font = lo_document->create_simple_element( name = lc_xml_node_font + parent = lo_document ). + IF ls_font-bold EQ abap_true. + lo_sub_element_2 = lo_document->create_simple_element( name = lc_xml_node_b + parent = lo_document ). + lo_element_font->append_child( new_child = lo_sub_element_2 ). + ENDIF. + IF ls_font-italic EQ abap_true. + lo_sub_element_2 = lo_document->create_simple_element( name = lc_xml_node_i + parent = lo_document ). + lo_element_font->append_child( new_child = lo_sub_element_2 ). + ENDIF. + IF ls_font-underline EQ abap_true. + lo_sub_element_2 = lo_document->create_simple_element( name = lc_xml_node_u + parent = lo_document ). + lv_value = ls_font-underline_mode. + lo_sub_element_2->set_attribute_ns( name = lc_xml_attr_val + value = lv_value ). + lo_element_font->append_child( new_child = lo_sub_element_2 ). + ENDIF. + IF ls_font-strikethrough EQ abap_true. + lo_sub_element_2 = lo_document->create_simple_element( name = lc_xml_node_strike + parent = lo_document ). + lo_element_font->append_child( new_child = lo_sub_element_2 ). + ENDIF. + "color + create_xl_styles_color_node( + io_document = lo_document + io_parent = lo_element_font + is_color = ls_font-color ). + lo_sub_element->append_child( new_child = lo_element_font ). + ENDIF. +"---Conditional formatting font style correction by Alessandro Iannacci END + + + READ TABLE lt_fills INTO ls_fill INDEX ls_cellxfs-fillid. + IF ls_fill IS NOT INITIAL. + " fill properties + lo_element_fill = lo_document->create_simple_element( name = lc_xml_node_fill + parent = lo_document ). + "pattern + lo_sub_element_2 = lo_document->create_simple_element( name = lc_xml_node_patternfill + parent = lo_document ). + lv_value = ls_fill-filltype. + lo_sub_element_2->set_attribute_ns( name = lc_xml_attr_patterntype + value = lv_value ). + " fgcolor + create_xl_styles_color_node( + io_document = lo_document + io_parent = lo_sub_element_2 + is_color = ls_fill-fgcolor + iv_color_elem_name = lc_xml_node_fgcolor ). + + " bgcolor + create_xl_styles_color_node( + io_document = lo_document + io_parent = lo_sub_element_2 + is_color = ls_fill-bgcolor + iv_color_elem_name = lc_xml_node_bgcolor ). + + lo_element_fill->append_child( new_child = lo_sub_element_2 ). "pattern + + lo_sub_element->append_child( new_child = lo_element_fill ). + ENDIF. + ENDIF. + + lo_element->append_child( new_child = lo_sub_element ). + WHEN zcl_excel_style_conditional=>c_rule_expression. + "if style defined + ls_expression = lo_style_conditional->mode_expression. + IF ls_expression-cell_style IS INITIAL. + CONTINUE. + ENDIF. + READ TABLE me->styles_mapping INTO ls_styles_mapping WITH KEY guid = ls_expression-cell_style. + ADD 1 TO ls_styles_mapping-style. " the numbering starts from 0 + READ TABLE lt_cellxfs INTO ls_cellxfs INDEX ls_styles_mapping-style. + ADD 1 TO ls_cellxfs-fillid. " the numbering starts from 0 + + READ TABLE me->styles_cond_mapping INTO ls_style_cond_mapping WITH KEY style = ls_styles_mapping-style. + IF sy-subrc EQ 0. + ls_style_cond_mapping-guid = ls_expression-cell_style. + APPEND ls_style_cond_mapping TO me->styles_cond_mapping. + ELSE. + ls_style_cond_mapping-guid = ls_expression-cell_style. + ls_style_cond_mapping-style = ls_styles_mapping-style. + ls_style_cond_mapping-dxf = lv_dfx_count. + APPEND ls_style_cond_mapping TO me->styles_cond_mapping. + ADD 1 TO lv_dfx_count. + + " dxf node + lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_dxf + parent = lo_document ). + + READ TABLE lt_fills INTO ls_fill INDEX ls_cellxfs-fillid. + IF ls_fill IS NOT INITIAL. + " fill properties + lo_element_fill = lo_document->create_simple_element( name = lc_xml_node_fill + parent = lo_document ). + "pattern + lo_sub_element_2 = lo_document->create_simple_element( name = lc_xml_node_patternfill + parent = lo_document ). + lv_value = ls_fill-filltype. + lo_sub_element_2->set_attribute_ns( name = lc_xml_attr_patterntype + value = lv_value ). + " fgcolor + create_xl_styles_color_node( + io_document = lo_document + io_parent = lo_sub_element_2 + is_color = ls_fill-fgcolor + iv_color_elem_name = lc_xml_node_fgcolor ). + + " bgcolor + create_xl_styles_color_node( + io_document = lo_document + io_parent = lo_sub_element_2 + is_color = ls_fill-bgcolor + iv_color_elem_name = lc_xml_node_bgcolor ). + + lo_element_fill->append_child( new_child = lo_sub_element_2 ). "pattern + + lo_sub_element->append_child( new_child = lo_element_fill ). + ENDIF. + ENDIF. + + lo_element->append_child( new_child = lo_sub_element ). + WHEN OTHERS. + CONTINUE. + ENDCASE. + ENDWHILE. + ENDWHILE. + + lv_value = lv_dfx_count. + CONDENSE lv_value. + lo_element->set_attribute_ns( name = lc_xml_attr_count + value = lv_value ). + lo_element_root->append_child( new_child = lo_element ). + + " tableStyles node + lo_element = lo_document->create_simple_element( name = lc_xml_node_tablestyles + parent = lo_document ). + lo_element->set_attribute_ns( name = lc_xml_attr_count + value = '0' ). + lo_element->set_attribute_ns( name = lc_xml_attr_defaulttablestyle + value = zcl_excel_table=>builtinstyle_medium9 ). + lo_element->set_attribute_ns( name = lc_xml_attr_defaultpivotstyle + value = zcl_excel_table=>builtinstyle_pivot_light16 ). + lo_element_root->append_child( new_child = lo_element ). + + "write legacy color palette in case any indexed color was changed + IF excel->legacy_palette->is_modified( ) = abap_true. + lo_element = lo_document->create_simple_element( name = lc_xml_node_colors + parent = lo_document ). + lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_indexedcolors + parent = lo_document ). + lo_element->append_child( new_child = lo_sub_element ). + + lt_colors = excel->legacy_palette->get_colors( ). + LOOP AT lt_colors INTO ls_color. + lo_sub_element_2 = lo_document->create_simple_element( name = lc_xml_node_rgbcolor + parent = lo_document ). + lv_value = ls_color. + lo_sub_element_2->set_attribute_ns( name = lc_xml_attr_rgb + value = lv_value ). + lo_sub_element->append_child( new_child = lo_sub_element_2 ). + ENDLOOP. + + lo_element_root->append_child( new_child = lo_element ). + ENDIF. ********************************************************************** * STEP 5: Create xstring stream - lo_streamfactory = lo_ixml->create_stream_factory( ). - lo_ostream = lo_streamfactory->create_ostream_xstring( string = ep_content ). - lo_renderer = lo_ixml->create_renderer( ostream = lo_ostream document = lo_document ). - lo_renderer->render( ). + lo_streamfactory = lo_ixml->create_stream_factory( ). + lo_ostream = lo_streamfactory->create_ostream_xstring( string = ep_content ). + lo_renderer = lo_ixml->create_renderer( ostream = lo_ostream document = lo_document ). + lo_renderer->render( ). -endmethod. + endmethod. @@ -5417,12 +18030,12 @@ endmethod. ENDIF. io_parent->append_child( new_child = lo_sub_element ). -endmethod. + endmethod. - METHOD create_xl_table. + method CREATE_XL_TABLE. DATA: lc_xml_node_table TYPE string VALUE 'table', lc_xml_node_relationship TYPE string VALUE 'Relationship', @@ -5594,7 +18207,7 @@ endmethod. lo_renderer = lo_ixml->create_renderer( ostream = lo_ostream document = lo_document ). lo_renderer->render( ). -ENDMETHOD. + endmethod. @@ -5683,20 +18296,20 @@ ENDMETHOD. buffer = ep_content. -endmethod. + endmethod. method CREATE_XL_WORKBOOK. *--------------------------------------------------------------------* * issue #230 - Pimp my Code -* - Stefan Schmöcker, (done) 2012-11-07 +* - Stefan Schmöcker, (done) 2012-11-07 * - ... * changes: aligning code * adding comments to explain what we are trying to achieve *--------------------------------------------------------------------* * issue#235 - repeat rows/columns -* - Stefan Schmöcker, 2012-12-01 +* - Stefan Schmöcker, 2012-12-01 * changes: correction of pointer to localSheetId *--------------------------------------------------------------------* @@ -5877,7 +18490,7 @@ endmethod. lo_sub_element = lo_document->create_simple_element_ns( name = lc_xml_node_sheet parent = lo_document ). lo_worksheet ?= lo_iterator->if_object_collection_iterator~get_next( ). - lv_syindex = sy-index. " question by Stefan Schmöcker 2012-12-02: sy-index seems to do the job - but is it proven to work or purely coincedence + lv_syindex = sy-index. " question by Stefan Schmöcker 2012-12-02: sy-index seems to do the job - but is it proven to work or purely coincedence lv_value = lo_worksheet->get_title( ). SHIFT lv_syindex RIGHT DELETING TRAILING space. SHIFT lv_syindex LEFT DELETING LEADING space. @@ -6004,7 +18617,7 @@ endmethod. lo_renderer = lo_ixml->create_renderer( ostream = lo_ostream document = lo_document ). lo_renderer->render( ). -endmethod. + endmethod. @@ -6017,7 +18630,7 @@ endmethod. ELSE. ep_boolean = 'false'. ENDIF. -endmethod. + endmethod. @@ -6030,11 +18643,11 @@ endmethod. READ TABLE shared_strings INTO ls_shared_string WITH KEY string_value = ip_cell_value BINARY SEARCH. ep_index = ls_shared_string-string_no. -endmethod. + endmethod. - + *"* local class implementation for public class *"* use this source file for the implementation part of *"* local helper classes @@ -6053,7 +18666,7 @@ endmethod. method ZIF_EXCEL_WRITER~WRITE_FILE. me->excel = io_excel. ep_file = me->create( ). -endmethod. + endmethod. @@ -6063,7 +18676,7 @@ endmethod. ep_excel = me->CREATE_CSV( ). -endmethod. + endmethod. @@ -6282,43 +18895,43 @@ endmethod. OTHERS = 2 . -endmethod. + endmethod. method SET_ACTIVE_SHEET_INDEX. CLEAR WORKSHEET_NAME. WORKSHEET_INDEX = i_active_worksheet. -endmethod. + endmethod. method SET_ACTIVE_SHEET_INDEX_BY_NAME. CLEAR WORKSHEET_INDEX. WORKSHEET_NAME = i_worksheet_name. -endmethod. + endmethod. method SET_DELIMITER. delimiter = ip_value. -endmethod. + endmethod. method SET_ENCLOSURE. zcl_excel_writer_csv=>enclosure = ip_value. -endmethod. + endmethod. method SET_ENDOFLINE. zcl_excel_writer_csv=>eol = ip_value. -endmethod. + endmethod. - - - sheetid type string, "ins #235 - repeat rows/cols - needed to identify correct sheet END OF t_relationship '/> - - - - - - - - - - - - - - - + *"* local class implementation for public class *"* use this source file for the implementation part of *"* local helper classes @@ -6424,32 +19037,32 @@ endmethod. - - + + method ZIF_EXCEL_READER~CAN_READ_FILE. *--------------------------------------------------------------------* * issue #230 - Pimp my Code -* - Stefan Schmöcker, (done) 2012-11-07 +* - Stefan Schmöcker, (done) 2012-11-07 * - ... * changes: nothing done in code * but started discussion about killing this method *--------------------------------------------------------------------* * For now always Unknown r_readable = abap_undefined. -endmethod. + endmethod. method ZIF_EXCEL_READER~LOAD. *--------------------------------------------------------------------* * ToDos: -* 2do§1 Map Document Properties to ZCL_EXCEL +* 2do§1 Map Document Properties to ZCL_EXCEL *--------------------------------------------------------------------* *--------------------------------------------------------------------* * issue #230 - Pimp my Code -* - Stefan Schmöcker, (done) 2012-11-07 +* - Stefan Schmöcker, (done) 2012-11-07 * - ... * changes: renaming variables to naming conventions * removing unused variables @@ -6459,7 +19072,7 @@ endmethod. * adding me-> where possible *--------------------------------------------------------------------* * issue#234 - error reading xlsx written by libre office -* - Stefan Schmöcker, 2012-11-07 +* - Stefan Schmöcker, 2012-11-07 * changes: passing new optional input parameter to private attribute *--------------------------------------------------------------------* @@ -6471,9 +19084,9 @@ endmethod. ls_relationship TYPE t_relationship. *--------------------------------------------------------------------* -* §1 Create EXCEL-Object we want to return to caller +* §1 Create EXCEL-Object we want to return to caller -* §2 We need to read the the file "\\_rels\.rels" because it tells +* §2 We need to read the the file "\\_rels\.rels" because it tells * us where in this folder structure the data for the workbook * is located in the xlsx zip-archive * @@ -6486,7 +19099,7 @@ endmethod. * |--> theme * |--> worksheets -* §3 Extracting from this the path&file where the workbook is located +* §3 Extracting from this the path&file where the workbook is located * Following is an example how this file could be set up * <?xml version="1.0" encoding="UTF-8" standalone="true"?> * <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"> @@ -6498,24 +19111,24 @@ endmethod. *--------------------------------------------------------------------* -* §1 Create EXCEL-Object we want to return to caller +* §1 Create EXCEL-Object we want to return to caller *--------------------------------------------------------------------* CREATE OBJECT r_excel. *--------------------------------------------------------------------* * issue#234 - error reading xlsx written by libre office - me->zif_excel_reader~gv_use_alternate_zip = iv_use_alternate_zip. + me->zif_excel_reader~gv_use_alternate_zip = i_use_alternate_zip. *--------------------------------------------------------------------* *--------------------------------------------------------------------* -* §2 Get file in folderstructure +* §2 Get file in folderstructure *--------------------------------------------------------------------* me->excel2007 = i_excel2007. lo_rels = me->get_ixml_from_zip_archive( '_rels/.rels' ). *--------------------------------------------------------------------* -* §3 Cycle through the Relationship Tags and use the ones we need +* §3 Cycle through the Relationship Tags and use the ones we need *--------------------------------------------------------------------* lo_node ?= lo_rels->find_from_name( 'Relationship' ). "#EC NOTEXT WHILE lo_node IS BOUND. @@ -6527,7 +19140,7 @@ endmethod. CASE ls_relationship-type. WHEN lcv_core_properties. - " 2do§1 Map Document Properties to ZCL_EXCEL + " 2do§1 Map Document Properties to ZCL_EXCEL WHEN lcv_office_document. me->load_workbook( iv_workbook_full_filename = ls_relationship-target @@ -6541,22 +19154,22 @@ endmethod. ENDWHILE. -endmethod. + endmethod. - method ZIF_EXCEL_READER~LOAD_FILE. + METHOD zif_excel_reader~load_file. *--------------------------------------------------------------------* * ToDos: -* 2do§1 decision whether to load from frontend or backend +* 2do§1 decision whether to load from frontend or backend * current behavior ( autodecide ) should be default * add optional parameter to allow user to choose * to load from backend even when online -* 2do§2 loosen typing of i_filename to CLIKE +* 2do§2 loosen typing of i_filename to CLIKE *--------------------------------------------------------------------* *--------------------------------------------------------------------* * issue #230 - Pimp my Code -* - Stefan Schmöcker, (done) 2012-11-05 +* - Stefan Schmöcker, (done) 2012-11-05 * - ... * changes: renaming variables to naming conventions * renaming variables to indicate what they are used for @@ -6569,130 +19182,28 @@ endmethod. * added errorhandling for open dataset *--------------------------------------------------------------------* * issue#234 - error reading xlsx written by libre office -* - Stefan Schmöcker, 2012-11-07 +* - Stefan Schmöcker, 2012-11-07 * changes: passing new optional input parameter to private attribute *--------------------------------------------------------------------* - CONSTANTS: lcv_load_from_frontend TYPE char1 VALUE 'F', - lcv_load_from_backend TYPE char1 VALUE 'B'. + DATA: lv_excel_data TYPE xstring. - DATA: lv_load_from_source TYPE char1, +* issue#234 - error reading xlsx written by libre office + me->zif_excel_reader~gv_use_alternate_zip = i_use_alternate_zip. - lv_filelength TYPE i, - lt_binary_data TYPE STANDARD TABLE OF x255 WITH NON-UNIQUE DEFAULT KEY, - ls_binary_data LIKE LINE OF lt_binary_data, -* Background processing - lv_max_length_line TYPE i, - lv_actual_length_line TYPE i, - - lv_errormessage TYPE string, " Can't pass '...'(abc) to exception-class - lv_excel_data TYPE xstring. " Binary content of .xlsx file - - -*--------------------------------------------------------------------* -* ToDos: 2do§1 Decision whether to load from frontend or backend -*--------------------------------------------------------------------* + IF i_from_applserver = abap_true. + lv_excel_data = me->read_from_applserver( i_filename = i_filename ). + ELSE. + lv_excel_data = me->read_from_local_file( i_filename = i_filename ). + ENDIF. *--------------------------------------------------------------------* * issue#234 - error reading xlsx written by libre office - me->zif_excel_reader~gv_use_alternate_zip = iv_use_alternate_zip. + r_excel = me->zif_excel_reader~load( i_excel2007 = lv_excel_data + i_use_alternate_zip = i_use_alternate_zip ). *--------------------------------------------------------------------* - -*--------------------------------------------------------------------* -* Autodecide on frontend or backend reading -* Background-processing --> backend reading -* Online-processing --> frontend reading -*--------------------------------------------------------------------* - IF sy-batch = abap_true. - lv_load_from_source = lcv_load_from_backend. - ELSE. - lv_load_from_source = lcv_load_from_frontend. - ENDIF. - - CASE lv_load_from_source. - -*--------------------------------------------------------------------* -* Read from backend -*--------------------------------------------------------------------* - WHEN lcv_load_from_backend. - DESCRIBE FIELD ls_binary_data LENGTH lv_max_length_line IN BYTE MODE. - OPEN DATASET i_filename FOR INPUT IN BINARY MODE. - IF sy-subrc <> 0. - lv_errormessage = 'A problem occured when reading the file'(001). - RAISE EXCEPTION TYPE zcx_excel - EXPORTING - error = lv_errormessage. - ENDIF. - WHILE sy-subrc = 0. - - READ DATASET i_filename INTO ls_binary_data MAXIMUM LENGTH lv_max_length_line ACTUAL LENGTH lv_actual_length_line. - APPEND ls_binary_data TO lt_binary_data. - lv_filelength = lv_filelength + lv_actual_length_line. - - ENDWHILE. - CLOSE DATASET i_filename. - -*--------------------------------------------------------------------* -* Read from frontend -*--------------------------------------------------------------------* - WHEN lcv_load_from_frontend. - cl_gui_frontend_services=>gui_upload( EXPORTING - filename = i_filename - filetype = 'BIN' " We are basically working with zipped directories --> force binary read - IMPORTING - filelength = lv_filelength - CHANGING - data_tab = lt_binary_data - EXCEPTIONS - file_open_error = 1 - file_read_error = 2 - no_batch = 3 - gui_refuse_filetransfer = 4 - invalid_type = 5 - no_authority = 6 - unknown_error = 7 - bad_data_format = 8 - header_not_allowed = 9 - separator_not_allowed = 10 - header_too_long = 11 - unknown_dp_error = 12 - access_denied = 13 - dp_out_of_memory = 14 - disk_full = 15 - dp_timeout = 16 - not_supported_by_gui = 17 - error_no_gui = 18 - OTHERS = 19 ). - IF sy-subrc <> 0. - lv_errormessage = 'A problem occured when reading the file'(001). - RAISE EXCEPTION TYPE zcx_excel - EXPORTING - error = lv_errormessage. - ENDIF. - - ENDCASE. - - -*--------------------------------------------------------------------* -* Binary data needs to be provided as XSTRING for further processing -*--------------------------------------------------------------------* - CALL FUNCTION 'SCMS_BINARY_TO_XSTRING' - EXPORTING - input_length = lv_filelength - IMPORTING - buffer = lv_excel_data - TABLES - binary_tab = lt_binary_data. - -*--------------------------------------------------------------------* -* issue#234 - error reading xlsx written by libre office - r_excel = me->zif_excel_reader~load( i_excel2007 = lv_excel_data - iv_use_alternate_zip = iv_use_alternate_zip ). -*--------------------------------------------------------------------* - - -endmethod. + ENDMETHOD. @@ -6700,7 +19211,7 @@ endmethod. method FILL_STRUCT_FROM_ATTRIBUTES. *--------------------------------------------------------------------* * issue #230 - Pimp my Code -* - Stefan Schmöcker, (done) 2012-11-07 +* - Stefan Schmöcker, (done) 2012-11-07 * - ... * changes: renaming variables to naming conventions * aligning code @@ -6743,7 +19254,7 @@ endmethod. ENDWHILE. -endmethod. + endmethod. @@ -6752,7 +19263,7 @@ endmethod. method GET_FROM_ZIP_ARCHIVE. *--------------------------------------------------------------------* * issue #230 - Pimp my Code -* - Stefan Schmöcker, (done) 2012-11-07 +* - Stefan Schmöcker, (done) 2012-11-07 * - ... * changes: aligning code * adding comments to explain what we are trying to achieve @@ -6760,7 +19271,7 @@ endmethod. * message made to support multilinguality *--------------------------------------------------------------------**--------------------------------------------------------------------* * issue#234 - error reading xlsx written by libre office -* - Stefan Schmöcker, 2012-11-07 +* - Stefan Schmöcker, 2012-11-07 * changes: copying coding and using ALTERNATE_ZIP in ELSE-Branch *--------------------------------------------------------------------* @@ -6869,7 +19380,7 @@ endmethod. * issue#234 - end of insertion *--------------------------------------------------------------------* -endmethod. + endmethod. @@ -6879,12 +19390,12 @@ endmethod. method GET_IXML_FROM_ZIP_ARCHIVE. *--------------------------------------------------------------------* * ToDos: -* 2do§1 Add comment what is being achieved here +* 2do§1 Add comment what is being achieved here *--------------------------------------------------------------------* *--------------------------------------------------------------------* * issue #230 - Pimp my Code -* - Stefan Schmöcker, (done) 2012-11-07 +* - Stefan Schmöcker, (done) 2012-11-07 * - ... * changes: renaming variables to naming conventions * removing unnecessary type-pool @@ -6900,7 +19411,7 @@ endmethod. *--------------------------------------------------------------------* -* 2do§1 ???? Something happens here ??? +* 2do§1 ???? Something happens here ??? *--------------------------------------------------------------------* lv_content = me->get_from_zip_archive( i_filename ). lo_ixml = cl_ixml=>create( ). @@ -6915,7 +19426,7 @@ endmethod. lo_parser->set_validating( mode = if_ixml_parser=>co_no_validation ). lo_parser->parse( ). -endmethod. + endmethod. @@ -7067,7 +19578,7 @@ endmethod. lo_drawing->load_chart_attributes( rel_drawing-content_xml ). endif. -endmethod. + endmethod. @@ -7075,12 +19586,12 @@ endmethod. method LOAD_SHARED_STRINGS. *--------------------------------------------------------------------* * ToDos: -* 2do§1 Support partial formatting of strings in cells +* 2do§1 Support partial formatting of strings in cells *--------------------------------------------------------------------* *--------------------------------------------------------------------* * issue #230 - Pimp my Code -* - Stefan Schmöcker, (done) 2012-11-11 +* - Stefan Schmöcker, (done) 2012-11-11 * - ... * changes: renaming variables to naming conventions * renaming variables to indicate what they are used for @@ -7103,10 +19614,10 @@ endmethod. *--------------------------------------------------------------------* -* §1 Parse shared strings file and get into internal table +* §1 Parse shared strings file and get into internal table * So far I have encountered 2 ways how a string can be represented in the shared strings file -* §1.1 - "simple" strings -* §1.2 - rich text formatted strings +* §1.1 - "simple" strings +* §1.2 - rich text formatted strings * Following is an example how this file could be set up; 2 strings in simple formatting, 3rd string rich textformatted @@ -7158,15 +19669,15 @@ endmethod. lv_tag_name = lo_node_si_child->get_name( ). IF lv_tag_name = 't'. *--------------------------------------------------------------------* -* §1.1 - "simple" strings +* §1.1 - "simple" strings * Example: see above *--------------------------------------------------------------------* <lv_shared_string> = lo_node_si_child->get_value( ). ELSE. *--------------------------------------------------------------------* -* §1.2 - rich text formatted strings +* §1.2 - rich text formatted strings * it is sufficient to strip the <t>...</t> tag from each <r>-tag and concatenate these -* as long as rich text formatting is not supported (2do§1) ignore all info about formatting +* as long as rich text formatting is not supported (2do§1) ignore all info about formatting * Example: see above *--------------------------------------------------------------------* WHILE lo_node_si_child IS BOUND. " actually these children of <si> are <r>-tags @@ -7186,7 +19697,7 @@ endmethod. lo_node_si ?= lo_node_si->get_next( ). ENDWHILE. -endmethod. + endmethod. @@ -7196,7 +19707,7 @@ endmethod. *--------------------------------------------------------------------* * issue #230 - Pimp my Code -* - Stefan Schmöcker, (wip ) 2012-11-25 +* - Stefan Schmöcker, (wip ) 2012-11-25 * - ... * changes: renaming variables and types to naming conventions * aligning code @@ -7264,16 +19775,16 @@ endmethod. *--------------------------------------------------------------------* * To build a complete style that fully describes how a cell looks like * we need the various parts -* §1 - Numberformat -* §2 - Fillstyle -* §3 - Borders -* §4 - Font -* §5 - Alignment -* §6 - Protection +* §1 - Numberformat +* §2 - Fillstyle +* §3 - Borders +* §4 - Font +* §5 - Alignment +* §6 - Protection * Following is an example how this part of a file could be set up * ... -* parts with various formatinformation - see §1,§2,§3,§4 +* parts with various formatinformation - see §1,§2,§3,§4 * ... * <cellXfs count="26"> * <xf numFmtId="0" borderId="0" fillId="0" fontId="0" xfId="0"/> @@ -7291,17 +19802,17 @@ endmethod. *--------------------------------------------------------------------* * The styles are build up from -* §1 number formats -* §2 fill styles -* §3 border styles -* §4 fonts +* §1 number formats +* §2 fill styles +* §3 border styles +* §4 fonts * These need to be read before we can try to build up a complete * style that describes the look of a cell *--------------------------------------------------------------------* - lt_num_formats = load_style_num_formats( lo_styles_xml ). " §1 - lt_fills = load_style_fills( lo_styles_xml ). " §2 - lt_borders = load_style_borders( lo_styles_xml ). " §3 - lt_fonts = load_style_fonts( lo_styles_xml ). " §4 + lt_num_formats = load_style_num_formats( lo_styles_xml ). " §1 + lt_fills = load_style_fills( lo_styles_xml ). " §2 + lt_borders = load_style_borders( lo_styles_xml ). " §3 + lt_fonts = load_style_fonts( lo_styles_xml ). " §4 *--------------------------------------------------------------------* * Now everything is prepared to build a "full" style @@ -7319,7 +19830,7 @@ endmethod. CHANGING cp_structure = ls_xf ). *--------------------------------------------------------------------* -* §2 fill style +* §2 fill style *--------------------------------------------------------------------* IF ls_xf-applyfill = '1' AND ls_xf-fillid IS NOT INITIAL. lv_index = ls_xf-fillid + 1. @@ -7330,7 +19841,7 @@ endmethod. ENDIF. *--------------------------------------------------------------------* -* §1 number format +* §1 number format *--------------------------------------------------------------------* IF ls_xf-numfmtid IS NOT INITIAL. READ TABLE lt_num_formats INTO ls_num_format WITH TABLE KEY id = ls_xf-numfmtid. @@ -7340,7 +19851,7 @@ endmethod. ENDIF. *--------------------------------------------------------------------* -* §3 border style +* §3 border style *--------------------------------------------------------------------* IF ls_xf-applyborder = '1' AND ls_xf-borderid IS NOT INITIAL. lv_index = ls_xf-borderid + 1. @@ -7351,7 +19862,7 @@ endmethod. ENDIF. *--------------------------------------------------------------------* -* §4 font +* §4 font *--------------------------------------------------------------------* IF ls_xf-applyfont = '1' AND ls_xf-fontid IS NOT INITIAL. lv_index = ls_xf-fontid + 1. @@ -7362,7 +19873,7 @@ endmethod. ENDIF. *--------------------------------------------------------------------* -* §5 - Alignment +* §5 - Alignment *--------------------------------------------------------------------* lo_node_cellxfs_xf_alignment ?= lo_node_cellxfs_xf->find_from_name( 'alignment' ). IF lo_node_cellxfs_xf_alignment IS BOUND. @@ -7396,7 +19907,7 @@ endmethod. ENDIF. *--------------------------------------------------------------------* -* §6 - Protection +* §6 - Protection *--------------------------------------------------------------------* lo_node_cellxfs_xf_protection ?= lo_node_cellxfs_xf->find_from_name( 'protection' ). IF lo_node_cellxfs_xf_protection IS BOUND. @@ -7425,7 +19936,7 @@ endmethod. ENDWHILE. ENDIF. -endmethod. + endmethod. @@ -7434,7 +19945,7 @@ endmethod. *--------------------------------------------------------------------* * issue #230 - Pimp my Code -* - Stefan Schmöcker, (done) 2012-11-25 +* - Stefan Schmöcker, (done) 2012-11-25 * - ... * changes: renaming variables and types to naming conventions * aligning code @@ -7450,11 +19961,11 @@ endmethod. *--------------------------------------------------------------------* * We need a table of used borderformats to build up our styles -* §1 A cell has 4 outer borders and 2 diagonal "borders" +* §1 A cell has 4 outer borders and 2 diagonal "borders" * These borders can be formatted separately but the diagonal borders * are always being formatted the same * We'll parse through the <border>-tag for each of the bordertypes -* §2 and read the corresponding formatting information +* §2 and read the corresponding formatting information * Following is an example how this part of a file could be set up * <border diagonalDown="1"> @@ -7497,7 +20008,7 @@ endmethod. lo_node_bordertype ?= lo_node_border->get_first_child( ). WHILE lo_node_bordertype IS BOUND. *--------------------------------------------------------------------* -* §1 Determine what kind of border we are talking about +* §1 Determine what kind of border we are talking about *--------------------------------------------------------------------* * Up, down, left, right, diagonal *--------------------------------------------------------------------* @@ -7523,7 +20034,7 @@ endmethod. ENDCASE. *--------------------------------------------------------------------* -* §2 Read the border-formatting +* §2 Read the border-formatting *--------------------------------------------------------------------* lo_border->border_style = lo_node_bordertype->get_attribute( 'style' ). lo_node_bordercolor ?= lo_node_bordertype->find_from_name( 'color' ). @@ -7555,7 +20066,7 @@ endmethod. ENDWHILE. -endmethod. + endmethod. @@ -7563,12 +20074,12 @@ endmethod. method LOAD_STYLE_FILLS. *--------------------------------------------------------------------* * ToDos: -* 2do§1 Support gradientFill +* 2do§1 Support gradientFill *--------------------------------------------------------------------* *--------------------------------------------------------------------* * issue #230 - Pimp my Code -* - Stefan Schmöcker, (done) 2012-11-25 +* - Stefan Schmöcker, (done) 2012-11-25 * - ... * changes: renaming variables and types to naming conventions * aligning code @@ -7659,7 +20170,7 @@ endmethod. * gradientFill *--------------------------------------------------------------------* WHEN 'gradientFill'. - " 2do§1 Support gradientFill + " 2do§1 Support gradientFill WHEN OTHERS. @@ -7673,7 +20184,7 @@ endmethod. ENDWHILE. -endmethod. + endmethod. @@ -7682,7 +20193,7 @@ endmethod. *--------------------------------------------------------------------* * issue #230 - Pimp my Code -* - Stefan Schmöcker, (done) 2012-11-25 +* - Stefan Schmöcker, (done) 2012-11-25 * - ... * changes: renaming variables and types to naming conventions * aligning code @@ -7799,7 +20310,7 @@ endmethod. ENDWHILE. -endmethod. + endmethod. @@ -7807,12 +20318,12 @@ endmethod. method LOAD_STYLE_NUM_FORMATS. *--------------------------------------------------------------------* * ToDos: -* 2do§1 Explain gaps in predefined formats +* 2do§1 Explain gaps in predefined formats *--------------------------------------------------------------------* *--------------------------------------------------------------------* * issue #230 - Pimp my Code -* - Stefan Schmöcker, (done) 2012-11-25 +* - Stefan Schmöcker, (done) 2012-11-25 * - ... * changes: renaming variables and types to naming conventions * adding comments to explain what we are trying to achieve @@ -7824,12 +20335,12 @@ endmethod. *--------------------------------------------------------------------* * We need a table of used numberformats to build up our styles * there are two kinds of numberformats -* §1 those that have been explicitly added by the createor of the excel-file -* §2 and built-in numberformats +* §1 those that have been explicitly added by the createor of the excel-file +* §2 and built-in numberformats *--------------------------------------------------------------------* *--------------------------------------------------------------------* -* §1 Get non-internal numberformats that are found in the file explicitly +* §1 Get non-internal numberformats that are found in the file explicitly * Following is an example how this part of a file could be set up * <numFmts count="1"> @@ -7858,7 +20369,7 @@ endmethod. END-OF-DEFINITION. *--------------------------------------------------------------------* -* §1 Get internal predefined numberformats +* §1 Get internal predefined numberformats *--------------------------------------------------------------------* predefined_format '1' '0'. predefined_format '2' '0.00'. @@ -7882,7 +20393,7 @@ endmethod. predefined_format '20' 'h:mm'. predefined_format '21' 'h:mm:ss'. predefined_format '22' 'm/d/yyyy h:mm'. -* 2do§1 Why is there a gap in here? +* 2do§1 Why is there a gap in here? @@ -7900,7 +20411,7 @@ endmethod. predefined_format '38' '#,##0_);[Red](#,##0)'. predefined_format '39' '#,##0.00_);(#,##0.00)'. predefined_format '40' '#,##0.00_);[Red](#,##0.00)'. -* 2do§1 Why is there a gap in here? +* 2do§1 Why is there a gap in here? @@ -7909,26 +20420,26 @@ endmethod. predefined_format '47' 'mm:ss.0'. predefined_format '48' '##0.0E+0'. predefined_format '49' '@'. -* 2do§1 Is 49 really the last predefined format? +* 2do§1 Is 49 really the last predefined format? -endmethod. + endmethod. - METHOD load_workbook. + method LOAD_WORKBOOK. *--------------------------------------------------------------------* * ToDos: -* 2do§1 Move macro-reading from zcl_excel_reader_xlsm to this class +* 2do§1 Move macro-reading from zcl_excel_reader_xlsm to this class * autodetect existance of macro/vba content * Allow inputparameter to explicitly tell reader to ignore vba-content *--------------------------------------------------------------------* *--------------------------------------------------------------------* * issue #230 - Pimp my Code -* - Stefan Schmöcker, (done) 2012-11-10 +* - Stefan Schmöcker, (done) 2012-11-10 * - ... * changes: renaming variables to naming conventions * aligning code @@ -7940,15 +20451,15 @@ endmethod. * ip_excel renamed while being at it --> rename to io_excel *--------------------------------------------------------------------* * issue #232 - Read worksheetstate hidden/veryHidden -* - Stefan Schmöcker, 2012-11-11 +* - Stefan Schmöcker, 2012-11-11 *--------------------------------------------------------------------* * issue#235 - repeat rows/columns -* - Stefan Schmöcker, 2012-12-02 +* - Stefan Schmöcker, 2012-12-02 * changes: correction in named ranges to correctly attach * sheetlocal names/ranges to the correct sheet *--------------------------------------------------------------------* * issue#284 - Copied formulae ignored when reading excelfile -* - Stefan Schmöcker, 2013-08-02 +* - Stefan Schmöcker, 2013-08-02 * changes: initialize area to hold referenced formulaedata * after all worksheets have been read resolve formuae *--------------------------------------------------------------------* @@ -8011,7 +20522,7 @@ endmethod. *--------------------------------------------------------------------* -* §1 Get the position of files related to this workbook +* §1 Get the position of files related to this workbook * Usually this will be <root>/xl/workbook.xml * Thus the workbookroot will be <root>/xl/ * The position of all related files will be given in file @@ -8031,19 +20542,19 @@ endmethod. * <Relationship Target="sharedStrings.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings" Id="rId7"/> * </Relationships> * -* §2 Load data that is relevant to the complete workbook +* §2 Load data that is relevant to the complete workbook * Currently supported is: -* §2.1 Shared strings - This holds all strings that are used in all worksheets -* §2.2 Styles - This holds all styles that are used in all worksheets -* §2.3 Worksheets - For each worksheet in the workbook one entry appears here to point to the file that holds the content of this worksheet -* §2.4 [Themes] - not supported -* §2.5 [VBA (Macro)] - supported in class zcl_excel_reader_xlsm but should be moved here and autodetect +* §2.1 Shared strings - This holds all strings that are used in all worksheets +* §2.2 Styles - This holds all styles that are used in all worksheets +* §2.3 Worksheets - For each worksheet in the workbook one entry appears here to point to the file that holds the content of this worksheet +* §2.4 [Themes] - not supported +* §2.5 [VBA (Macro)] - supported in class zcl_excel_reader_xlsm but should be moved here and autodetect * ... * -* §3 Some information is held in the workbookfile as well -* §3.1 Names and order of of worksheets -* §3.2 Active worksheet -* §3.3 Defined names +* §3 Some information is held in the workbookfile as well +* §3.1 Names and order of of worksheets +* §3.2 Active worksheet +* §3.3 Defined names * ... * Following is an example how this file could be set up @@ -8068,7 +20579,7 @@ endmethod. CLEAR me->mt_ref_formulae. " ins issue#284 *--------------------------------------------------------------------* -* §1 Get the position of files related to this workbook +* §1 Get the position of files related to this workbook * Entry into this method is with the filename of the workbook *--------------------------------------------------------------------* CALL FUNCTION 'TRINT_SPLIT_FILE_AND_PATH' @@ -8090,7 +20601,7 @@ endmethod. CASE ls_relationship-type. *--------------------------------------------------------------------* -* §2.1 Shared strings - This holds all strings that are used in all worksheets +* §2.1 Shared strings - This holds all strings that are used in all worksheets *--------------------------------------------------------------------* WHEN lcv_shared_strings. CONCATENATE lv_path ls_relationship-target @@ -8098,7 +20609,7 @@ endmethod. me->load_shared_strings( lv_full_filename ). *--------------------------------------------------------------------* -* §2.3 Worksheets +* §2.3 Worksheets * For each worksheet in the workbook one entry appears here to point to the file that holds the content of this worksheet * Shared strings and styles have to be present before we can start with creating the worksheets * thus we only store this information for use when parsing the workbookfile for sheetinformations @@ -8107,7 +20618,7 @@ endmethod. APPEND ls_relationship TO lt_worksheets. *--------------------------------------------------------------------* -* §2.2 Styles - This holds the styles that are used in all worksheets +* §2.2 Styles - This holds the styles that are used in all worksheets *--------------------------------------------------------------------* WHEN lcv_styles. CONCATENATE lv_path ls_relationship-target @@ -8124,12 +20635,12 @@ endmethod. ENDWHILE. *--------------------------------------------------------------------* -* §3 Some information held in the workbookfile +* §3 Some information held in the workbookfile *--------------------------------------------------------------------* lo_workbook = me->get_ixml_from_zip_archive( iv_workbook_full_filename ). *--------------------------------------------------------------------* -* §3.1 Names and order of of worksheets +* §3.1 Names and order of of worksheets *--------------------------------------------------------------------* lo_node ?= lo_workbook->find_from_name( 'sheet' ). lv_workbook_index = 1. @@ -8192,7 +20703,7 @@ endmethod. " ins issue#284 *--------------------------------------------------------------------* * #229: Set active worksheet - begin coding -* §3.2 Active worksheet +* §3.2 Active worksheet *--------------------------------------------------------------------* lv_zexcel_active_worksheet = 1. " First sheet = active sheet if nothing else specified. lo_node ?= lo_workbook->find_from_name( 'workbookView' ). @@ -8210,7 +20721,7 @@ endmethod. *--------------------------------------------------------------------* -* §3.3 Defined names +* §3.3 Defined names * So far I have encountered these * - named ranges - sheetlocal * - named ranges - workbookglobal @@ -8331,16 +20842,16 @@ endmethod. ENDWHILE. -ENDMETHOD. + endmethod. - METHOD load_worksheet. + method LOAD_WORKSHEET. *--------------------------------------------------------------------* * ToDos: -* 2do§1 Header/footer +* 2do§1 Header/footer * * Please don't just delete these ToDos if they are not * needed but leave a comment that states this @@ -8348,7 +20859,7 @@ ENDMETHOD. *--------------------------------------------------------------------* * issue #230 - Pimp my Code -* - Stefan Schmöcker, +* - Stefan Schmöcker, * - ... * changes: renaming variables to naming conventions * aligning code (started) @@ -8519,7 +21030,7 @@ ENDMETHOD. *--------------------------------------------------------------------* -* §2 We need to read the the file "\\_rels\.rels" because it tells +* §2 We need to read the the file "\\_rels\.rels" because it tells * us where in this folder structure the data for the workbook * is located in the xlsx zip-archive * @@ -8918,7 +21429,7 @@ ENDMETHOD. ls_odd_footer-left_value = lo_ixml_hf_value_elem->get_value( ). ENDIF. -* 2do§1 Header/footer +* 2do§1 Header/footer " TODO.. get the rest. io_worksheet->sheet_setup->set_header_footer( ip_odd_header = ls_odd_header @@ -8955,7 +21466,7 @@ ENDMETHOD. ENDIF. " End fix 194 Read attributes HIDDEN, OUTLINELEVEL, COLLAPSED in ZCL_EXCEL_READER_2007 -ENDMETHOD. + endmethod. @@ -9025,11 +21536,6 @@ ENDMETHOD. path2 = path. zcl_excel_common=>split_file( EXPORTING ip_file = path2 IMPORTING ep_extension = file_ext2 ). -* CALL FUNCTION 'CV120_SPLIT_FILE' -* EXPORTING -* pf_file = path2 -* IMPORTING -* pfx_extension = file_ext2. rel_drawing-file_ext = file_ext2. "-------------Added by Alessandro Iannacci - Should load graph xml @@ -9079,7 +21585,110 @@ ENDMETHOD. ENDDO. -endmethod. + endmethod. + + + + + METHOD read_from_applserver. + + DATA: lv_filelength TYPE i, + lt_binary_data TYPE STANDARD TABLE OF x255 WITH NON-UNIQUE DEFAULT KEY, + ls_binary_data LIKE LINE OF lt_binary_data, + lv_filename TYPE string, + lv_max_length_line TYPE i, + lv_actual_length_line TYPE i, + lv_errormessage TYPE string. + + MOVE i_filename TO lv_filename. + + DESCRIBE FIELD ls_binary_data LENGTH lv_max_length_line IN BYTE MODE. + OPEN DATASET lv_filename FOR INPUT IN BINARY MODE. + IF sy-subrc <> 0. + lv_errormessage = 'A problem occured when reading the file'(001). + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = lv_errormessage. + ENDIF. + WHILE sy-subrc = 0. + + READ DATASET lv_filename INTO ls_binary_data MAXIMUM LENGTH lv_max_length_line ACTUAL LENGTH lv_actual_length_line. + APPEND ls_binary_data TO lt_binary_data. + lv_filelength = lv_filelength + lv_actual_length_line. + + ENDWHILE. + CLOSE DATASET lv_filename. + +*--------------------------------------------------------------------* +* Binary data needs to be provided as XSTRING for further processing +*--------------------------------------------------------------------* + CALL FUNCTION 'SCMS_BINARY_TO_XSTRING' + EXPORTING + input_length = lv_filelength + IMPORTING + buffer = r_excel_data + TABLES + binary_tab = lt_binary_data. + ENDMETHOD. + + + + + METHOD read_from_local_file. + DATA: lv_filelength TYPE i, + lt_binary_data TYPE STANDARD TABLE OF x255 WITH NON-UNIQUE DEFAULT KEY, + ls_binary_data LIKE LINE OF lt_binary_data, + lv_filename TYPE string, + lv_errormessage TYPE string. + + MOVE i_filename TO lv_filename. + + cl_gui_frontend_services=>gui_upload( EXPORTING + filename = lv_filename + filetype = 'BIN' " We are basically working with zipped directories --> force binary read + IMPORTING + filelength = lv_filelength + CHANGING + data_tab = lt_binary_data + EXCEPTIONS + file_open_error = 1 + file_read_error = 2 + no_batch = 3 + gui_refuse_filetransfer = 4 + invalid_type = 5 + no_authority = 6 + unknown_error = 7 + bad_data_format = 8 + header_not_allowed = 9 + separator_not_allowed = 10 + header_too_long = 11 + unknown_dp_error = 12 + access_denied = 13 + dp_out_of_memory = 14 + disk_full = 15 + dp_timeout = 16 + not_supported_by_gui = 17 + error_no_gui = 18 + OTHERS = 19 ). + IF sy-subrc <> 0. + lv_errormessage = 'A problem occured when reading the file'(001). + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = lv_errormessage. + ENDIF. + +*--------------------------------------------------------------------* +* Binary data needs to be provided as XSTRING for further processing +*--------------------------------------------------------------------* + CALL FUNCTION 'SCMS_BINARY_TO_XSTRING' + EXPORTING + input_length = lv_filelength + IMPORTING + buffer = r_excel_data + TABLES + binary_tab = lt_binary_data. + + ENDMETHOD. @@ -9087,10 +21696,10 @@ endmethod. method RESOLVE_PATH. *--------------------------------------------------------------------* * ToDos: -* 2do§1 Determine whether the replacement should be done +* 2do§1 Determine whether the replacement should be done * iterative to allow /../../.. or something alike -* 2do§2 Determine whether /./ has to be supported as well -* 2do§3 Create unit-test for this method +* 2do§2 Determine whether /./ has to be supported as well +* 2do§3 Create unit-test for this method * * Please don't just delete these ToDos if they are not * needed but leave a comment that states this @@ -9098,14 +21707,14 @@ endmethod. *--------------------------------------------------------------------* * issue #230 - Pimp my Code -* - Stefan Schmöcker, (done) 2012-11-11 +* - Stefan Schmöcker, (done) 2012-11-11 * - ... * changes: replaced previous coding by regular expression * adding comments to explain what we are trying to achieve *--------------------------------------------------------------------* *--------------------------------------------------------------------* -* §1 This routine will receive a path, that may have a relative pathname (/../) included somewhere +* §1 This routine will receive a path, that may have a relative pathname (/../) included somewhere * The output should be a resolved path without relative references * Example: Input xl/worksheets/../drawings/drawing1.xml * Output xl/drawings/drawing1.xml @@ -9113,7 +21722,7 @@ endmethod. rp_result = ip_path. *--------------------------------------------------------------------* -* §1 Remove relative pathnames +* §1 Remove relative pathnames *--------------------------------------------------------------------* * Regular expression [^/]*/\.\./ * [^/]* --> any number of characters other than / @@ -9123,10 +21732,10 @@ endmethod. REPLACE REGEX '[^/]*/\.\./' IN rp_result WITH ``. -endmethod. + endmethod. - METHOD resolve_referenced_formulae. + method RESOLVE_REFERENCED_FORMULAE. TYPES: BEGIN OF ty_referenced_cells, sheet TYPE REF TO zcl_excel_worksheet, si TYPE i, @@ -9222,7 +21831,7 @@ endmethod. ENDLOOP. ENDLOOP. -ENDMETHOD. + endmethod. @@ -9255,7 +21864,7 @@ ENDMETHOD. border_style = zcl_excel_style_border=>c_border_none. border_color-theme = zcl_excel_style_color=>c_theme_not_set. border_color-indexed = zcl_excel_style_color=>c_indexed_not_set. -endmethod. + endmethod. @@ -9267,1043 +21876,11 @@ endmethod. *"* implementation or private method's signature *"* use this source file for any macro definitions you need *"* in the implementation part of the class - CLASS lcl_excel_common_test DEFINITION DEFERRED. -CLASS zcl_excel_common DEFINITION LOCAL FRIENDS lcl_excel_common_test. - -*----------------------------------------------------------------------* -* CLASS lcl_Excel_Common_Test DEFINITION -*----------------------------------------------------------------------* -* -*----------------------------------------------------------------------* -CLASS lcl_excel_common_test DEFINITION FOR TESTING "#AU Risk_Level Harmless - . "#AU Duration Short -*?<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0"> -*?<asx:values> -*?<TESTCLASS_OPTIONS> -*?<TEST_CLASS>lcl_Excel_Common_Test -*?</TEST_CLASS> -*?<TEST_MEMBER>f_Cut -*?</TEST_MEMBER> -*?<OBJECT_UNDER_TEST>ZCL_EXCEL_COMMON -*?</OBJECT_UNDER_TEST> -*?<OBJECT_IS_LOCAL/> -*?<GENERATE_FIXTURE>X -*?</GENERATE_FIXTURE> -*?<GENERATE_CLASS_FIXTURE>X -*?</GENERATE_CLASS_FIXTURE> -*?<GENERATE_INVOCATION>X -*?</GENERATE_INVOCATION> -*?<GENERATE_ASSERT_EQUAL>X -*?</GENERATE_ASSERT_EQUAL> -*?</TESTCLASS_OPTIONS> -*?</asx:values> -*?</asx:abap> - PRIVATE SECTION. -* ================ - DATA: - lx_excel TYPE REF TO zcx_excel, - ls_symsg_act TYPE symsg, " actual messageinformation of exception - ls_symsg_exp TYPE symsg, " expected messageinformation of exception - f_cut TYPE REF TO zcl_excel_common. "class under test - - CLASS-METHODS: class_setup. - CLASS-METHODS: class_teardown. - METHODS: setup. - METHODS: teardown. -* METHODS: char2hex FOR TESTING. - METHODS: convert_column2alpha FOR TESTING. - METHODS: convert_column2int FOR TESTING. - METHODS: date_to_excel_string FOR TESTING. - METHODS: encrypt_password FOR TESTING. - METHODS: excel_string_to_date FOR TESTING. - METHODS: excel_string_to_time FOR TESTING. -* METHODS: number_to_excel_string FOR TESTING. - METHODS: time_to_excel_string FOR TESTING. - METHODS: split_file FOR TESTING. - METHODS: convert_range2column_a_row FOR TESTING. - METHODS: describe_structure FOR TESTING. - METHODS: calculate_cell_distance FOR TESTING. - METHODS: shift_formula FOR TESTING. -ENDCLASS. "lcl_Excel_Common_Test - - -*----------------------------------------------------------------------* -* CLASS lcl_Excel_Common_Test IMPLEMENTATION -*----------------------------------------------------------------------* -* -*----------------------------------------------------------------------* -CLASS lcl_excel_common_test IMPLEMENTATION. -* =========================================== - - METHOD class_setup. -* =================== - - - ENDMETHOD. "class_Setup - - - METHOD class_teardown. -* ====================== - - - ENDMETHOD. "class_Teardown - - - METHOD setup. -* ============= - - CREATE OBJECT f_cut. - ENDMETHOD. "setup - - - METHOD teardown. -* ================ - - - ENDMETHOD. "teardown - - - METHOD convert_column2alpha. -* ============================ - DATA ep_column TYPE zexcel_cell_column_alpha. - -* Test 1. Simple test - TRY. - ep_column = zcl_excel_common=>convert_column2alpha( 1 ). - - zcl_excel_common=>assert_equals( - act = ep_column - exp = 'A' - msg = 'Wrong column conversion' - level = if_aunit_constants=>critical - ). - CATCH zcx_excel INTO lx_excel. - zcl_excel_common=>fail( - msg = 'unexpected exception' - level = if_aunit_constants=>critical " Error Severity - ). - ENDTRY. - -* Test 2. Max column for OXML #16,384 = XFD - TRY. - ep_column = zcl_excel_common=>convert_column2alpha( 16384 ). - - zcl_excel_common=>assert_equals( - act = ep_column - exp = 'XFD' - msg = 'Wrong column conversion' - level = if_aunit_constants=>critical - ). - CATCH zcx_excel INTO lx_excel. - zcl_excel_common=>fail( - msg = 'unexpected exception' - level = if_aunit_constants=>critical " Error Severity - ). - ENDTRY. - -* Test 3. Index 0 is out of bounds - TRY. - ep_column = zcl_excel_common=>convert_column2alpha( 0 ). - - zcl_excel_common=>assert_equals( - act = ep_column - exp = 'A' - ). - CATCH zcx_excel INTO lx_excel. - zcl_excel_common=>assert_equals( - act = lx_excel->error - exp = 'Index out of bounds' - msg = 'Colum index 0 is out of bounds, min column index is 1' - level = if_aunit_constants=>fatal - ). - ENDTRY. - -* Test 4. Exception should be thrown index out of bounds - TRY. - ep_column = zcl_excel_common=>convert_column2alpha( 16385 ). - - zcl_excel_common=>assert_differs( - act = ep_column - exp = 'XFE' - msg = 'Colum index 16385 is out of bounds, max column index is 16384' - level = if_aunit_constants=>fatal - ). - CATCH zcx_excel INTO lx_excel. - zcl_excel_common=>assert_equals( - act = lx_excel->error - exp = 'Index out of bounds' - msg = 'Wrong exception is thrown' - level = if_aunit_constants=>tolerable - ). - ENDTRY. - ENDMETHOD. "convert_Column2alpha - - - METHOD convert_column2int. -* ========================== - DATA ep_column TYPE zexcel_cell_column. - -* Test 1. Basic test - TRY. - ep_column = zcl_excel_common=>convert_column2int( 'A' ). - - zcl_excel_common=>assert_equals( - act = ep_column - exp = 1 - msg = 'Wrong column conversion' - level = if_aunit_constants=>critical - ). - CATCH zcx_excel INTO lx_excel. - zcl_excel_common=>fail( - msg = 'unexpected exception' - level = if_aunit_constants=>critical " Error Severity - ). - ENDTRY. - -* Test 2. Max column - TRY. - ep_column = zcl_excel_common=>convert_column2int( 'XFD' ). - - zcl_excel_common=>assert_equals( - act = ep_column - exp = 16384 - msg = 'Wrong column conversion' - level = if_aunit_constants=>critical - ). - CATCH zcx_excel INTO lx_excel. - zcl_excel_common=>fail( - msg = 'unexpected exception' - level = if_aunit_constants=>critical " Error Severity - ). - ENDTRY. - -* Test 3. Out of bounds - TRY. - ep_column = zcl_excel_common=>convert_column2int( '' ). - - zcl_excel_common=>assert_differs( act = ep_column - exp = '0' - msg = 'Wrong column conversion' - level = if_aunit_constants=>critical ). - CATCH zcx_excel INTO lx_excel. - CLEAR: ls_symsg_act, - ls_symsg_exp. - ls_symsg_exp-msgid = 'ZABAP2XLSX'. - ls_symsg_exp-msgno = '800'. - ls_symsg_act-msgid = lx_excel->syst_at_raise-msgid. - ls_symsg_act-msgno = lx_excel->syst_at_raise-msgno. - zcl_excel_common=>assert_equals( act = ls_symsg_act - exp = ls_symsg_exp - msg = 'Colum name should be a valid string' - level = if_aunit_constants=>fatal ). - ENDTRY. - -* Test 4. Out of bounds - TRY. - ep_column = zcl_excel_common=>convert_column2int( 'XFE' ). - - zcl_excel_common=>assert_differs( act = ep_column - exp = 16385 - msg = 'Wrong column conversion' - level = if_aunit_constants=>critical ). - CATCH zcx_excel INTO lx_excel. - zcl_excel_common=>assert_equals( act = lx_excel->error - exp = 'Index out of bounds' - msg = 'Colum XFE is out of range' - level = if_aunit_constants=>fatal ). - ENDTRY. - ENDMETHOD. "convert_Column2int - - - METHOD date_to_excel_string. -* ============================ - DATA ep_value TYPE zexcel_cell_value. - -* Test 1. Basic conversion - TRY. - ep_value = zcl_excel_common=>date_to_excel_string( '19000101' ). - - zcl_excel_common=>assert_equals( - act = ep_value - exp = 1 - msg = 'Wrong date conversion' - level = if_aunit_constants=>critical - ). - CATCH zcx_excel INTO lx_excel. - zcl_excel_common=>fail( - msg = 'unexpected exception' - level = if_aunit_constants=>critical " Error Severity - ). - ENDTRY. -* Check around the "Excel Leap Year" 1900 - TRY. - ep_value = zcl_excel_common=>date_to_excel_string( '19000228' ). - - zcl_excel_common=>assert_equals( - act = ep_value - exp = 59 - msg = 'Wrong date conversion' - level = if_aunit_constants=>critical - ). - CATCH zcx_excel INTO lx_excel. - zcl_excel_common=>fail( - msg = 'unexpected exception' - level = if_aunit_constants=>critical " Error Severity - ). - ENDTRY. - TRY. - ep_value = zcl_excel_common=>date_to_excel_string( '19000301' ). - - zcl_excel_common=>assert_equals( - act = ep_value - exp = 61 - msg = 'Wrong date conversion' - level = if_aunit_constants=>critical - ). - CATCH zcx_excel INTO lx_excel. - zcl_excel_common=>fail( - msg = 'unexpected exception' - level = if_aunit_constants=>critical " Error Severity - ). - ENDTRY. - - -* Test 2. Basic conversion - TRY. - ep_value = zcl_excel_common=>date_to_excel_string( '99991212' ). - - zcl_excel_common=>assert_equals( - act = ep_value - exp = 2958446 - msg = 'Wrong date conversion' - level = if_aunit_constants=>critical - ). - CATCH zcx_excel INTO lx_excel. - zcl_excel_common=>fail( - msg = 'unexpected exception' - level = if_aunit_constants=>critical " Error Severity - ). - ENDTRY. - -* Test 3. Initial date - TRY. - DATA: lv_date TYPE d. - ep_value = zcl_excel_common=>date_to_excel_string( lv_date ). - - zcl_excel_common=>assert_equals( - act = ep_value - exp = '' - msg = 'Wrong date conversion' - level = if_aunit_constants=>critical - ). - CATCH zcx_excel INTO lx_excel. - zcl_excel_common=>fail( - msg = 'unexpected exception' - level = if_aunit_constants=>critical " Error Severity - ). - ENDTRY. - -* Test 2. Basic conversion - TRY. - DATA exp_value TYPE zexcel_cell_value VALUE 0. - ep_value = zcl_excel_common=>date_to_excel_string( '18991231' ). - - zcl_excel_common=>assert_differs( - act = ep_value - exp = exp_value - msg = 'Wrong date conversion' - level = if_aunit_constants=>critical - ). - CATCH zcx_excel INTO lx_excel. - zcl_excel_common=>assert_equals( - act = lx_excel->error - exp = 'Index out of bounds' - msg = 'Dates prior of 1900 are not available in excel' - level = if_aunit_constants=>critical - ). - ENDTRY. - - ENDMETHOD. "date_To_Excel_String - - - METHOD encrypt_password. -* ======================== - DATA lv_encrypted_pwd TYPE zexcel_aes_password. - - TRY. - lv_encrypted_pwd = zcl_excel_common=>encrypt_password( 'test' ). - - zcl_excel_common=>assert_equals( - act = lv_encrypted_pwd - exp = 'CBEB' - msg = 'Wrong password encryption' - level = if_aunit_constants=>critical - ). - CATCH zcx_excel INTO lx_excel. - zcl_excel_common=>fail( - msg = 'unexpected exception' - level = if_aunit_constants=>critical " Error Severity - ). - ENDTRY. - ENDMETHOD. "encrypt_Password - - - METHOD excel_string_to_date. -* ============================ - DATA ep_value TYPE d. - - -* Test 1. Simple test -> ABAP Manage also date prior of 1900 - TRY. - ep_value = zcl_excel_common=>excel_string_to_date( '0' ). - - zcl_excel_common=>assert_equals( - act = ep_value - exp = '18991231' - msg = 'Wrong date conversion' - level = if_aunit_constants=>tolerable - ). - CATCH zcx_excel INTO lx_excel. - zcl_excel_common=>fail( - msg = 'unexpected exception' - level = if_aunit_constants=>critical " Error Severity - ). - ENDTRY. -* Check around the "Excel Leap Year" 1900 - TRY. - ep_value = zcl_excel_common=>excel_string_to_date( '59' ). - - zcl_excel_common=>assert_equals( - act = ep_value - exp = '19000228' - msg = 'Wrong date conversion' - level = if_aunit_constants=>critical - ). - CATCH zcx_excel INTO lx_excel. - zcl_excel_common=>fail( - msg = 'unexpected exception' - level = if_aunit_constants=>critical " Error Severity - ). - ENDTRY. - TRY. - ep_value = zcl_excel_common=>excel_string_to_date( '61' ). - - zcl_excel_common=>assert_equals( - act = ep_value - exp = '19000301' - msg = 'Wrong date conversion' - level = if_aunit_constants=>critical - ). - CATCH zcx_excel INTO lx_excel. - zcl_excel_common=>fail( - msg = 'unexpected exception' - level = if_aunit_constants=>critical " Error Severity - ). - ENDTRY. - -* Test 2. Simple test - TRY. - ep_value = zcl_excel_common=>excel_string_to_date( '1' ). - - zcl_excel_common=>assert_equals( - act = ep_value - exp = '19000101' - msg = 'Wrong date conversion' - level = if_aunit_constants=>critical - ). - CATCH zcx_excel INTO lx_excel. - zcl_excel_common=>fail( - msg = 'unexpected exception' - level = if_aunit_constants=>critical " Error Severity - ). - ENDTRY. - -* Test 3. Index 0 is out of bounds - TRY. - ep_value = zcl_excel_common=>excel_string_to_date( '2958446' ). - - zcl_excel_common=>assert_equals( - act = ep_value - exp = '99991212' - msg = 'Wrong date conversion' - level = if_aunit_constants=>critical - ). - CATCH zcx_excel INTO lx_excel. - zcl_excel_common=>fail( - msg = 'unexpected exception' - level = if_aunit_constants=>critical " Error Severity - ). - ENDTRY. - -* Test 4. Exception should be thrown index out of bounds - TRY. - ep_value = zcl_excel_common=>excel_string_to_date( '2958447' ). - - zcl_excel_common=>assert_differs( - act = ep_value - exp = '99991212' - msg = 'Wrong date conversion' - level = if_aunit_constants=>fatal - ). - - zcl_excel_common=>assert_differs( - act = ep_value - exp = '00000000' - msg = 'Wrong date conversion' - level = if_aunit_constants=>fatal - ). - - CATCH zcx_excel INTO lx_excel. - zcl_excel_common=>assert_equals( - act = lx_excel->error - exp = 'Index out of bounds' - msg = 'Wrong exception is thrown' - level = if_aunit_constants=>tolerable - ). - ENDTRY. - ENDMETHOD. "excel_String_To_Date - - - METHOD excel_string_to_time. -* ============================ - DATA ep_value TYPE t. - -* Test 1. Simple test - TRY. - ep_value = zcl_excel_common=>excel_string_to_time( '0' ). - - zcl_excel_common=>assert_equals( - act = ep_value - exp = '000000' - msg = 'Wrong date conversion' - level = if_aunit_constants=>tolerable - ). - CATCH zcx_excel INTO lx_excel. - zcl_excel_common=>fail( - msg = 'unexpected exception' - level = if_aunit_constants=>critical " Error Severity - ). - ENDTRY. - -* Test 2. Simple test - TRY. - ep_value = zcl_excel_common=>excel_string_to_time( '1' ). - - zcl_excel_common=>assert_equals( - act = ep_value - exp = '000000' - msg = 'Wrong date conversion' - level = if_aunit_constants=>critical - ). - CATCH zcx_excel INTO lx_excel. - zcl_excel_common=>fail( - msg = 'unexpected exception' - level = if_aunit_constants=>critical " Error Severity - ). - ENDTRY. - -* Test 3. Simple test - TRY. - ep_value = zcl_excel_common=>excel_string_to_time( '0.99999' ). - - zcl_excel_common=>assert_equals( - act = ep_value - exp = '235959' - msg = 'Wrong date conversion' - level = if_aunit_constants=>critical - ). - CATCH zcx_excel INTO lx_excel. - zcl_excel_common=>fail( - msg = 'unexpected exception' - level = if_aunit_constants=>critical " Error Severity - ). - ENDTRY. - -* Test 4. Also string greater than 1 should be managed - TRY. - ep_value = zcl_excel_common=>excel_string_to_time( '4.1' ). - - zcl_excel_common=>assert_equals( - act = ep_value - exp = '022400' - msg = 'Wrong date conversion' - level = if_aunit_constants=>critical - ). - CATCH zcx_excel INTO lx_excel. - zcl_excel_common=>fail( - msg = 'unexpected exception' - level = if_aunit_constants=>critical " Error Severity - ). - ENDTRY. - -* Test 4. string is not a number - TRY. - ep_value = zcl_excel_common=>excel_string_to_time( 'NaN' ). - - zcl_excel_common=>assert_differs( - act = ep_value - exp = '000000' - msg = 'Wrong date conversion' - level = if_aunit_constants=>critical - ). - CATCH zcx_excel INTO lx_excel. - zcl_excel_common=>assert_equals( - act = lx_excel->error - exp = 'Unable to interpret time' - msg = 'Time should be a valid string' - level = if_aunit_constants=>fatal - ). - ENDTRY. - ENDMETHOD. "excel_String_To_Time - - - METHOD time_to_excel_string. -* ============================ - DATA ep_value TYPE zexcel_cell_value. - -* Test 1. Basic conversion - TRY. - ep_value = zcl_excel_common=>time_to_excel_string( '000001' ). - " A test directly in Excel returns the value 0.0000115740740740741000 - zcl_excel_common=>assert_equals( - act = ep_value - exp = '0.0000115740740741' - msg = 'Wrong date conversion' - level = if_aunit_constants=>critical - ). - CATCH zcx_excel INTO lx_excel. - zcl_excel_common=>fail( - msg = 'unexpected exception' - level = if_aunit_constants=>critical " Error Severity - ). - ENDTRY. - -* Test 2. Basic conversion - TRY. - ep_value = zcl_excel_common=>time_to_excel_string( '235959' ). - " A test directly in Excel returns the value 0.9999884259259260000000 - zcl_excel_common=>assert_equals( - act = ep_value - exp = '0.9999884259259260' - msg = 'Wrong date conversion' - level = if_aunit_constants=>critical - ). - CATCH zcx_excel INTO lx_excel. - zcl_excel_common=>fail( - msg = 'unexpected exception' - level = if_aunit_constants=>critical " Error Severity - ). - ENDTRY. - -* Test 3. Initial date - TRY. - ep_value = zcl_excel_common=>time_to_excel_string( '000000' ). - - zcl_excel_common=>assert_equals( - act = ep_value - exp = '0' - msg = 'Wrong date conversion' - level = if_aunit_constants=>critical - ). - CATCH zcx_excel INTO lx_excel. - zcl_excel_common=>fail( - msg = 'unexpected exception' - level = if_aunit_constants=>critical " Error Severity - ). - ENDTRY. - -* Test 2. Basic conversion - TRY. - ep_value = zcl_excel_common=>time_to_excel_string( '022400' ). - - zcl_excel_common=>assert_equals( - act = ep_value - exp = '0.1000000000000000' - msg = 'Wrong date conversion' - level = if_aunit_constants=>critical - ). - CATCH zcx_excel INTO lx_excel. - zcl_excel_common=>fail( - msg = 'unexpected exception' - level = if_aunit_constants=>critical " Error Severity - ). - ENDTRY. - - ENDMETHOD. "time_To_Excel_String - - METHOD split_file. -* ============================ - - DATA: ep_file TYPE text255, - ep_extension TYPE char10, - ep_dotextension TYPE char10. - - -* Test 1. Basic conversion - zcl_excel_common=>split_file( EXPORTING ip_file = 'filename.xml' - IMPORTING ep_file = ep_file - ep_extension = ep_extension - ep_dotextension = ep_dotextension ). - - zcl_excel_common=>assert_equals( - act = ep_file - exp = 'filename' - msg = 'Split filename failed' - level = if_aunit_constants=>critical ). - - zcl_excel_common=>assert_equals( - act = ep_extension - exp = 'xml' - msg = 'Split extension failed' - level = if_aunit_constants=>critical ). - - zcl_excel_common=>assert_equals( - act = ep_dotextension - exp = '.xml' - msg = 'Split extension failed' - level = if_aunit_constants=>critical ). - -* Test 2. no extension - zcl_excel_common=>split_file( EXPORTING ip_file = 'filename' - IMPORTING ep_file = ep_file - ep_extension = ep_extension - ep_dotextension = ep_dotextension ). - - zcl_excel_common=>assert_equals( - act = ep_file - exp = 'filename' - msg = 'Split filename failed' - level = if_aunit_constants=>critical ). - - zcl_excel_common=>assert_equals( - act = ep_extension - exp = '' - msg = 'Split extension failed' - level = if_aunit_constants=>critical ). - - zcl_excel_common=>assert_equals( - act = ep_dotextension - exp = '' - msg = 'Split extension failed' - level = if_aunit_constants=>critical ). - - ENDMETHOD. "split_file - - METHOD convert_range2column_a_row. - DATA: lv_range TYPE string. - DATA: lv_column_start TYPE zexcel_cell_column_alpha, - lv_column_end TYPE zexcel_cell_column_alpha, - lv_row_start TYPE zexcel_cell_row, - lv_row_end TYPE zexcel_cell_row, - lv_sheet TYPE string. - -* a) input empty --> nothing to do - zcl_excel_common=>convert_range2column_a_row( - EXPORTING - i_range = lv_range - IMPORTING - e_column_start = lv_column_start " Cell Column Start - e_column_end = lv_column_end " Cell Column End - e_row_start = lv_row_start " Cell Row - e_row_end = lv_row_end " Cell Row - e_sheet = lv_sheet " Title - ). - - zcl_excel_common=>assert_equals( - act = lv_column_start - exp = '' - msg = 'Conversion of range failed' - level = if_aunit_constants=>critical ). - zcl_excel_common=>assert_equals( - act = lv_column_end - exp = '' - msg = 'Conversion of range failed' - level = if_aunit_constants=>critical ). - zcl_excel_common=>assert_equals( - act = lv_row_start - exp = '' - msg = 'Conversion of range failed' - level = if_aunit_constants=>critical ). - zcl_excel_common=>assert_equals( - act = lv_row_end - exp = '' - msg = 'Conversion of range failed' - level = if_aunit_constants=>critical ). - zcl_excel_common=>assert_equals( - act = lv_sheet - exp = '' - msg = 'Conversion of range failed' - level = if_aunit_constants=>critical ). -* b) sheetname existing - starts with ' example 'Sheet 1'!$B$6:$D$13 - lv_range = `'Sheet 1'!$B$6:$D$13`. - zcl_excel_common=>convert_range2column_a_row( - EXPORTING - i_range = lv_range - IMPORTING - e_column_start = lv_column_start " Cell Column Start - e_column_end = lv_column_end " Cell Column End - e_row_start = lv_row_start " Cell Row - e_row_end = lv_row_end " Cell Row - e_sheet = lv_sheet " Title - ). - - zcl_excel_common=>assert_equals( - act = lv_column_start - exp = 'B' - msg = 'Conversion of range failed' - level = if_aunit_constants=>critical ). - zcl_excel_common=>assert_equals( - act = lv_column_end - exp = 'D' - msg = 'Conversion of range failed' - level = if_aunit_constants=>critical ). - zcl_excel_common=>assert_equals( - act = lv_row_start - exp = '6' - msg = 'Conversion of range failed' - level = if_aunit_constants=>critical ). - zcl_excel_common=>assert_equals( - act = lv_row_end - exp = '13' - msg = 'Conversion of range failed' - level = if_aunit_constants=>critical ). - zcl_excel_common=>assert_equals( - act = lv_sheet - exp = 'Sheet 1' - msg = 'Conversion of range failed' - level = if_aunit_constants=>critical ). -* c) sheetname existing - does not start with ' example Sheet1!$B$6:$D$13 - lv_range = `Sheet1!B6:$D$13`. - zcl_excel_common=>convert_range2column_a_row( - EXPORTING - i_range = lv_range - IMPORTING - e_column_start = lv_column_start " Cell Column Start - e_column_end = lv_column_end " Cell Column End - e_row_start = lv_row_start " Cell Row - e_row_end = lv_row_end " Cell Row - e_sheet = lv_sheet " Title - ). - - zcl_excel_common=>assert_equals( - act = lv_column_start - exp = 'B' - msg = 'Conversion of range failed' - level = if_aunit_constants=>critical ). - zcl_excel_common=>assert_equals( - act = lv_column_end - exp = 'D' - msg = 'Conversion of range failed' - level = if_aunit_constants=>critical ). - zcl_excel_common=>assert_equals( - act = lv_row_start - exp = '6' - msg = 'Conversion of range failed' - level = if_aunit_constants=>critical ). - zcl_excel_common=>assert_equals( - act = lv_row_end - exp = '13' - msg = 'Conversion of range failed' - level = if_aunit_constants=>critical ). - zcl_excel_common=>assert_equals( - act = lv_sheet - exp = 'Sheet1' - msg = 'Conversion of range failed' - level = if_aunit_constants=>critical ). -* d) no sheetname - just area example $B$6:$D$13 - lv_range = `$B$6:D13`. - zcl_excel_common=>convert_range2column_a_row( - EXPORTING - i_range = lv_range - IMPORTING - e_column_start = lv_column_start " Cell Column Start - e_column_end = lv_column_end " Cell Column End - e_row_start = lv_row_start " Cell Row - e_row_end = lv_row_end " Cell Row - e_sheet = lv_sheet " Title - ). - - zcl_excel_common=>assert_equals( - act = lv_column_start - exp = 'B' - msg = 'Conversion of range failed' - level = if_aunit_constants=>critical ). - zcl_excel_common=>assert_equals( - act = lv_column_end - exp = 'D' - msg = 'Conversion of range failed' - level = if_aunit_constants=>critical ). - zcl_excel_common=>assert_equals( - act = lv_row_start - exp = '6' - msg = 'Conversion of range failed' - level = if_aunit_constants=>critical ). - zcl_excel_common=>assert_equals( - act = lv_row_end - exp = '13' - msg = 'Conversion of range failed' - level = if_aunit_constants=>critical ). - zcl_excel_common=>assert_equals( - act = lv_sheet - exp = '' - msg = 'Conversion of range failed' - level = if_aunit_constants=>critical ). - ENDMETHOD. "convert_range2column_a_row - - - METHOD describe_structure. - DATA: ls_test TYPE scarr. - DATA: lo_structdescr TYPE REF TO cl_abap_structdescr. - DATA: lt_structure TYPE ddfields. - FIELD-SYMBOLS: <line> LIKE LINE OF lt_structure. - - " Test with DDIC Type - lo_structdescr ?= cl_abap_structdescr=>describe_by_data( p_data = ls_test ). - lt_structure = zcl_excel_common=>describe_structure( io_struct = lo_structdescr ). - READ TABLE lt_structure ASSIGNING <line> INDEX 1. - zcl_excel_common=>assert_equals( - act = <line>-fieldname - exp = 'MANDT' - msg = 'Describe structure failed' - level = if_aunit_constants=>critical ). - - " Test with local defined structure having DDIC and non DDIC elements - TYPES: - BEGIN OF t_test, - carrid TYPE s_carr_id, - carrname TYPE s_carrname, - carrdesc TYPE string, - END OF t_test. - DATA: ls_ttest TYPE t_test. - - lo_structdescr ?= cl_abap_structdescr=>describe_by_data( p_data = ls_ttest ). - lt_structure = zcl_excel_common=>describe_structure( io_struct = lo_structdescr ). - READ TABLE lt_structure ASSIGNING <line> INDEX 1. - zcl_excel_common=>assert_equals( - act = <line>-fieldname - exp = 'CARRID' - msg = 'Describe structure failed' - level = if_aunit_constants=>critical ). - - ENDMETHOD. "describe_structure - - - METHOD calculate_cell_distance. - DATA: lv_offset_rows TYPE i, - lv_offset_cols TYPE i, - lv_message TYPE string. - - DEFINE macro_calculate_cell_distance. - zcl_excel_common=>calculate_cell_distance( exporting iv_reference_cell = &1 - iv_current_cell = &2 - importing ev_row_difference = lv_offset_rows - ev_col_difference = lv_offset_cols ). -* Check delta columns - concatenate 'Error calculating column difference in test:' - &1 - '->' - &2 - into lv_message separated by space. - zcl_excel_common=>assert_equals( act = lv_offset_cols - exp = &3 - msg = lv_message - quit = 0 " continue tests - level = if_aunit_constants=>critical ). -* Check delta rows - concatenate 'Error calculating row difference in test:' - &1 - '->' - &2 - into lv_message separated by space. - zcl_excel_common=>assert_equals( act = lv_offset_rows - exp = &4 - msg = lv_message - quit = 0 " continue tests - level = if_aunit_constants=>critical ). - END-OF-DEFINITION. - - - macro_calculate_cell_distance: - 'C12' 'C12' 0 0 , " Same cell - 'C12' 'C13' 0 1 , " Shift down 1 place - 'C12' 'C25' 0 13 , " Shift down some places - 'C12' 'C11' 0 -1 , " Shift up 1 place - 'C12' 'C1' 0 -11 , " Shift up some place - 'C12' 'D12' 1 0 , " Shift right 1 place - 'C12' 'AA12' 24 0 , " Shift right some places - 'C12' 'B12' -1 0 , " Shift left 1 place - 'AA12' 'C12' -24 0 , " Shift left some place - 'AA121' 'C12' -24 -109 . " The full package. - - ENDMETHOD. "CALCULATE_CELL_DISTANCE - - METHOD shift_formula. - DATA: lv_resulting_formula TYPE string, - lv_message TYPE string, - lv_counter TYPE num8. - - DEFINE macro_shift_formula. - add 1 to lv_counter. - clear lv_resulting_formula. - try. - lv_resulting_formula = zcl_excel_common=>shift_formula( iv_reference_formula = &1 - iv_shift_cols = &2 - iv_shift_rows = &3 ). - concatenate 'Wrong result in test' - lv_counter - 'shifting formula ' - &1 - into lv_message separated by space. - zcl_excel_common=>assert_equals( act = lv_resulting_formula - exp = &4 - msg = lv_message - quit = 0 " continue tests - level = if_aunit_constants=>critical ). - catch zcx_excel. - concatenate 'Unexpected exception occurred in test' - lv_counter - 'shifting formula ' - &1 - into lv_message separated by space. - zcl_excel_common=>assert_equals( act = lv_resulting_formula - exp = &4 - msg = lv_message - quit = 0 " continue tests - level = if_aunit_constants=>critical ). - endtry. - END-OF-DEFINITION. - -* Test shifts that should result in a valid output - macro_shift_formula: - 'C17' 0 0 'C17', " Very basic check - 'C17' 2 3 'E20', " Check shift right and down - 'C17' -2 -3 'A14', " Check shift left and up - '$C$17' 1 1 '$C$17', " Fixed columns/rows - 'SUM($C17:C$23)+C30' 1 11 'SUM($C28:D$23)+D41', " Operators and Ranges, mixed fixed rows or columns - 'RNGNAME1+C7' -1 -4 'RNGNAME1+B3', " Operators and Rangename - '"Date:"&TEXT(B2)' 1 1 '"Date:"&TEXT(C3)', " String literals and string concatenation - '[TEST6.XLSX]SHEET1!A1' 1 11 '[TEST6.XLSX]SHEET1!B12', " External sheet reference - `X(B13, "KK" ) ` 1 1 `X(C14,"KK")`, " superflous blanks, multi-argument functions, literals in function, unknown functions -* 'SIN((((((B2))))))' 1 1 'SIN((((((C3))))))', " Deep nesting -* 'SIN(SIN(SIN(SIN(E22))))' 0 1 'SIN(SIN(SIN(SIN(E23))))', " Different type of deep nesting - `SIN(SIN(SIN(SIN(E22))))` 0 1 'SIN(SIN(SIN(SIN(E23))))', " same as above - but with string input instead of Char-input - 'HEUTE()' 2 5 'HEUTE()', " Functions w/o arguments, No cellreferences - '"B2"' 2 5 '"B2"', " No cellreferences - '' 2 5 '', " Empty - 'A1+$A1+A$1+$A$1+B2' -1 0 '#REF!+$A1+#REF!+$A$1+A2', " Referencing error , column only , underflow - 'A1+$A1+A$1+$A$1+B2' 0 -1 '#REF!+#REF!+A$1+$A$1+B1', " Referencing error , row only , underflow - 'A1+$A1+A$1+$A$1+B2' -1 -1 '#REF!+#REF!+#REF!+$A$1+A1'. " Referencing error , row and column , underflow - ENDMETHOD. "SHIFT_FORMULA - - - - - -ENDCLASS. "lcl_Excel_Common_Test + *"* use this source file for your ABAP unit test classes - + @@ -10373,7 +21950,7 @@ ENDCLASS. "lcl_Excel_Common_Test * We do nothing for now not supported ENDIF. ENDIF. -endmethod. + endmethod. @@ -10384,7 +21961,7 @@ endmethod. - METHOD assert_equals. + method ASSERT_EQUALS. DATA: ls_seoclass TYPE seoclass. " Let see >=7.02 @@ -10426,7 +22003,7 @@ endmethod. * We do nothing for now not supported ENDIF. ENDIF. -ENDMETHOD. + endmethod. @@ -10434,7 +22011,7 @@ ENDMETHOD. - METHOD calculate_cell_distance. + method CALCULATE_CELL_DISTANCE. DATA: lv_reference_row TYPE i, lv_reference_col_alpha TYPE zexcel_cell_column_alpha, @@ -10473,7 +22050,7 @@ ENDMETHOD. ev_row_difference = lv_current_row - lv_reference_row. ev_col_difference = lv_current_col - lv_reference_col. -ENDMETHOD. + endmethod. @@ -10490,13 +22067,13 @@ ENDMETHOD. CALL METHOD o_conv->write( data = i_char ). r_hex+1 = o_conv->get_buffer( ). " x'65' must be x'0065' -endmethod. + endmethod. - METHOD convert_column2alpha. + method CONVERT_COLUMN2ALPHA. DATA: lv_uccpi TYPE i, lv_text TYPE sychar02, @@ -10531,17 +22108,17 @@ endmethod. ENDWHILE. -ENDMETHOD. + endmethod. - METHOD convert_column2int. + method CONVERT_COLUMN2INT. *--------------------------------------------------------------------* * issue #230 - Pimp my Code -* - Stefan Schmöcker, (done) 2012-12-29 +* - Stefan Schmöcker, (done) 2012-12-29 * - ... * changes: renaming variables to naming conventions * removing unused variables @@ -10550,7 +22127,7 @@ ENDMETHOD. * adding comments to explain what we are trying to achieve *--------------------------------------------------------------------* * issue#246 - error converting lower case column names -* - Stefan Schmöcker, 2012-12-29 +* - Stefan Schmöcker, 2012-12-29 * changes: translating the correct variable to upper dase * adding missing exception if input is a number * that is out of bounds @@ -10690,7 +22267,7 @@ ENDMETHOD. ENDIF. -ENDMETHOD. + endmethod. @@ -10700,7 +22277,7 @@ ENDMETHOD. *--------------------------------------------------------------------* "issue #256 - replacing char processing with regex *--------------------------------------------------------------------* -* Stefan Schmöcker, 2013-08-11 +* Stefan Schmöcker, 2013-08-11 * Allow input to be CLIKE instead of STRING *--------------------------------------------------------------------* @@ -10713,7 +22290,7 @@ ENDMETHOD. pane_cell_row_a. e_row = pane_cell_row_a. -endmethod. + endmethod. @@ -10726,7 +22303,7 @@ endmethod. method CONVERT_RANGE2COLUMN_A_ROW. *--------------------------------------------------------------------* * issue #230 - Pimp my Code -* - Stefan Schmöcker, (done) 2012-12-07 +* - Stefan Schmöcker, (done) 2012-12-07 * - ... * changes: renaming variables to naming conventions * aligning code @@ -10736,12 +22313,12 @@ endmethod. *--------------------------------------------------------------------* * issue#241 - error when sheetname contains "!" * - sheetname should be returned unescaped -* - Stefan Schmöcker, 2012-12-07 +* - Stefan Schmöcker, 2012-12-07 * changes: changed coding to support sheetnames with "!" * unescaping sheetname *--------------------------------------------------------------------* * issue#155 - lessening restrictions of input parameters -* - Stefan Schmöcker, 2012-12-07 +* - Stefan Schmöcker, 2012-12-07 * changes: i_range changed to clike * e_sheet changed to clike *--------------------------------------------------------------------* @@ -10806,7 +22383,7 @@ endmethod. e_row = e_row_end ). e_sheet = unescape_string( lv_sheet ). " Return in unescaped form -endmethod. + endmethod. @@ -10824,7 +22401,7 @@ endmethod. lv_date_diff = ip_value - c_excel_baseline_date + 1. ENDIF. ep_value = zcl_excel_common=>number_to_excel_string( ip_value = lv_date_diff ). -endmethod. + endmethod. @@ -10875,11 +22452,11 @@ endmethod. ENDIF. ENDLOOP. ENDIF. -endmethod. + endmethod. method DESCRIBE_TABLE. -endmethod. + endmethod. @@ -10887,7 +22464,7 @@ endmethod. - METHOD determine_resulting_formula. + method DETERMINE_RESULTING_FORMULA. DATA: lv_row_difference TYPE i, lv_col_difference TYPE i. @@ -10909,7 +22486,7 @@ endmethod. iv_shift_rows = lv_row_difference iv_shift_cols = lv_col_difference ). -ENDMETHOD. "determine_resulting_formula + endmethod. @@ -10951,7 +22528,7 @@ ENDMETHOD. "determine_resulting_formula WRITE lv_pwd_hash TO r_encrypted_pwd. -endmethod. + endmethod. @@ -10959,19 +22536,19 @@ endmethod. method ESCAPE_STRING. *--------------------------------------------------------------------* * issue #230 - Pimp my Code -* - Stefan Schmöcker, (done) 2012-12-08 +* - Stefan Schmöcker, (done) 2012-12-08 * - ... * changes: aligning code * adding comments to explain what we are trying to achieve *--------------------------------------------------------------------* * issue#242 - Support escaping for white-spaces * - Escaping also necessary when ' encountered in input -* - Stefan Schmöcker, 2012-12-08 +* - Stefan Schmöcker, 2012-12-08 * changes: switched check if escaping is necessary to regular expression * and moved the "REPLACE" *--------------------------------------------------------------------* * issue#155 - lessening restrictions of input parameters -* - Stefan Schmöcker, 2012-12-08 +* - Stefan Schmöcker, 2012-12-08 * changes: ip_value changed to clike *--------------------------------------------------------------------* DATA: lv_value TYPE string. @@ -11002,7 +22579,7 @@ endmethod. ep_escaped_value = lv_value. -endmethod. + endmethod. @@ -11025,7 +22602,7 @@ endmethod. EXPORTING error = 'Index out of bounds'. ENDTRY. -endmethod. + endmethod. @@ -11048,7 +22625,7 @@ endmethod. EXPORTING error = 'Unable to interpret time'. ENDTRY. -endmethod. + endmethod. @@ -11088,7 +22665,7 @@ endmethod. ENDIF. ENDIF. -endmethod. + endmethod. @@ -11149,7 +22726,7 @@ endmethod. ENDLOOP. -endmethod. + endmethod. @@ -11168,7 +22745,7 @@ endmethod. ELSEIF ip_value EQ 0. ep_value = '0'. ENDIF. -endmethod. + endmethod. @@ -11227,7 +22804,7 @@ endmethod. ENDCASE. ENDLOOP. -endmethod. + endmethod. @@ -11291,7 +22868,7 @@ endmethod. ENDCASE. ENDLOOP. -endmethod. + endmethod. @@ -11299,7 +22876,7 @@ endmethod. - METHOD shift_formula. + method SHIFT_FORMULA. CONSTANTS: lcv_operators TYPE string VALUE '+-/*^%=<>&, !', lcv_letters TYPE string VALUE 'ABCDEFGHIJKLMNOPQRSTUVWXYZ$', @@ -11336,10 +22913,10 @@ endmethod. * are copied as well. Cell-references in the formula are being adjusted * by the distance of the new cell to the original one *--------------------------------------------------------------------* -* §1 Parse reference formula character by character -* §2 Identify Cell-references -* §3 Shift cell-reference -* §4 Build resulting formula +* §1 Parse reference formula character by character +* §2 Identify Cell-references +* §3 Shift cell-reference +* §4 Build resulting formula *--------------------------------------------------------------------* *--------------------------------------------------------------------* @@ -11356,7 +22933,7 @@ endmethod. lv_numchars = 1. *--------------------------------------------------------------------* -* §1 Parse reference formula character by character +* §1 Parse reference formula character by character *--------------------------------------------------------------------* DO lv_flen TIMES. @@ -11632,7 +23209,7 @@ endmethod. MOVE lv_cur_form TO ev_resulting_formula. ENDIF. -ENDMETHOD. + endmethod. @@ -11652,7 +23229,7 @@ ENDMETHOD. ENDDO. SET BIT 16 OF r_pwd_hash TO 0. -endmethod. + endmethod. @@ -11679,7 +23256,7 @@ endmethod. SET BIT 1 OF r_pwd_hash TO 0. ENDDO. -endmethod. + endmethod. @@ -11727,7 +23304,7 @@ endmethod. ep_file = ip_file(lf_len). ENDIF. -endmethod. + endmethod. @@ -11746,7 +23323,7 @@ endmethod. WHEN OTHERS. "cl_abap_typedescr=>kind_ref or cl_abap_typedescr=>kind_class or cl_abap_typedescr=>kind_intf. * We skip it. for now. ENDCASE. -endmethod. + endmethod. @@ -11766,7 +23343,7 @@ endmethod. CHANGING xt_components = rt_components ) . ENDLOOP. -endmethod. + endmethod. @@ -11780,7 +23357,7 @@ endmethod. lv_seconds_in_day = ip_value - lc_time_baseline. lv_day_fraction = lv_seconds_in_day / lc_seconds_in_day. ep_value = zcl_excel_common=>number_to_excel_string( ip_value = lv_day_fraction ). -endmethod. + endmethod. @@ -11840,13 +23417,13 @@ endmethod. REPLACE ALL OCCURRENCES OF `''` IN ev_unescaped_string WITH `'`. -endmethod. + endmethod. - - - + + + *"* local class implementation for public class *"* use this source file for the implementation part of *"* local helper classes @@ -11855,106 +23432,6 @@ endmethod. *"* implementation or private method's signature *"* use this source file for any macro definitions you need *"* in the implementation part of the class - CLASS zcl_tc_excel DEFINITION DEFERRED. -CLASS zcl_excel DEFINITION LOCAL FRIENDS zcl_tc_excel. - -*----------------------------------------------------------------------* -* CLASS zcl_Tc_Excel DEFINITION -*----------------------------------------------------------------------* -* -*----------------------------------------------------------------------* -CLASS zcl_tc_excel DEFINITION FOR TESTING - DURATION SHORT - RISK LEVEL HARMLESS -. -*?<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0"> -*?<asx:values> -*?<TESTCLASS_OPTIONS> -*?<TEST_CLASS>zcl_Tc_Excel -*?</TEST_CLASS> -*?<TEST_MEMBER>f_Cut -*?</TEST_MEMBER> -*?<OBJECT_UNDER_TEST>ZCL_EXCEL -*?</OBJECT_UNDER_TEST> -*?<OBJECT_IS_LOCAL/> -*?<GENERATE_FIXTURE>X -*?</GENERATE_FIXTURE> -*?<GENERATE_CLASS_FIXTURE>X -*?</GENERATE_CLASS_FIXTURE> -*?<GENERATE_INVOCATION>X -*?</GENERATE_INVOCATION> -*?<GENERATE_ASSERT_EQUAL>X -*?</GENERATE_ASSERT_EQUAL> -*?</TESTCLASS_OPTIONS> -*?</asx:values> -*?</asx:abap> - PRIVATE SECTION. -* ================ - DATA: - f_cut TYPE REF TO zcl_excel. "class under test - - CLASS-METHODS: class_setup. - CLASS-METHODS: class_teardown. - METHODS: setup. - METHODS: teardown. - METHODS: create_empty_excel FOR TESTING. - -ENDCLASS. "zcl_Tc_Excel - - -*----------------------------------------------------------------------* -* CLASS zcl_Tc_Excel IMPLEMENTATION -*----------------------------------------------------------------------* -* -*----------------------------------------------------------------------* -CLASS zcl_tc_excel IMPLEMENTATION. -* ================================== - - METHOD class_setup. -* =================== - - - ENDMETHOD. "class_Setup - - - METHOD class_teardown. -* ====================== - - - ENDMETHOD. "class_Teardown - - - METHOD setup. -* ============= - - CREATE OBJECT f_cut. - ENDMETHOD. "setup - - - METHOD teardown. -* ================ - - - ENDMETHOD. "teardown - -*// START TEST METHODS - - METHOD create_empty_excel. -* ================================== - - DATA: lv_count TYPE i. - lv_count = f_cut->get_worksheets_size( ). - - cl_abap_unit_assert=>assert_equals( act = lv_count - exp = 1 - msg = 'Testing number of sheet' - level = if_aunit_constants=>tolerable ). - ENDMETHOD. "create_empty_excel - -*// END TEST METHODS - - -ENDCLASS. "zcl_Tc_Excel @@ -11979,7 +23456,7 @@ ENDCLASS. "zcl_Tc_Excel 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. + endmethod. method ZIF_EXCEL_BOOK_PROTECTION~INITIALIZE. @@ -11989,22 +23466,22 @@ endmethod. 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. + endmethod. method ZIF_EXCEL_BOOK_VBA_PROJECT~SET_CODENAME. me->zif_excel_book_vba_project~codename = ip_codename. -endmethod. + endmethod. method ZIF_EXCEL_BOOK_VBA_PROJECT~SET_CODENAME_PR. me->zif_excel_book_vba_project~codename_pr = ip_codename_pr. -endmethod. + endmethod. method ZIF_EXCEL_BOOK_VBA_PROJECT~SET_VBAPROJECT. me->zif_excel_book_vba_project~vbaproject = ip_vbaproject. -endmethod. + endmethod. @@ -12012,7 +23489,7 @@ 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. + endmethod. @@ -12032,7 +23509,7 @@ endmethod. WHEN 'chart'. charts->add( eo_drawing ). ENDCASE. -endmethod. + endmethod. @@ -12040,7 +23517,7 @@ endmethod. * Create default blank range CREATE OBJECT eo_range. ranges->add( eo_range ). -endmethod. + endmethod. @@ -12064,13 +23541,13 @@ endmethod. INSERT style2 INTO TABLE t_stylemapping2. * End of insertion # issue 139 - Dateretention of cellstyles -endmethod. + endmethod. - METHOD add_new_worksheet. + method ADD_NEW_WORKSHEET. DATA: lv_guid TYPE guid_16. * Create default blank worksheet @@ -12081,16 +23558,16 @@ endmethod. worksheets->add( eo_worksheet ). worksheets->active_worksheet = worksheets->size( ). -ENDMETHOD. + 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 +* 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. @@ -12106,7 +23583,7 @@ ENDMETHOD. CHANGING e_target = style ). ENDLOOP. -endmethod. + endmethod. method CONSTRUCTOR. @@ -12135,13 +23612,13 @@ endmethod. lo_style = me->add_new_style( ). " Standard style with fill gray125 lo_style->fill->filltype = zcl_excel_style_fill=>c_fill_pattern_gray125. -endmethod. + endmethod. method GET_ACTIVE_SHEET_INDEX. r_active_worksheet = me->worksheets->active_worksheet. -endmethod. + endmethod. @@ -12149,7 +23626,7 @@ endmethod. eo_worksheet = me->worksheets->get( me->worksheets->active_worksheet ). -endmethod. + endmethod. @@ -12157,13 +23634,13 @@ endmethod. ro_autofilters = autofilters. -endmethod. + endmethod. method GET_DEFAULT_STYLE. ep_style = me->default_style. -endmethod. + endmethod. @@ -12178,7 +23655,7 @@ endmethod. WHEN OTHERS. ENDCASE. -endmethod. + endmethod. @@ -12198,7 +23675,7 @@ endmethod. ADD 1 TO ep_id. -endmethod. + endmethod. @@ -12206,7 +23683,7 @@ endmethod. eo_iterator = me->ranges->get_iterator( ). -endmethod. + endmethod. @@ -12232,7 +23709,7 @@ endmethod. ENDIF. ep_guid = style-guid. -endmethod. + endmethod. @@ -12240,7 +23717,7 @@ endmethod. eo_iterator = me->styles->get_iterator( ). -endmethod. + endmethod. @@ -12271,7 +23748,7 @@ endmethod. else. SUBTRACT 1 from ep_index. " In excel list starts with "0" ENDIF. -endmethod. + endmethod. @@ -12294,7 +23771,7 @@ endmethod. ENDIF. -endmethod. + endmethod. @@ -12302,7 +23779,7 @@ endmethod. eo_iterator = me->worksheets->get_iterator( ). -endmethod. + endmethod. @@ -12310,7 +23787,7 @@ endmethod. ep_name = me->worksheets->name. -endmethod. + endmethod. @@ -12318,7 +23795,7 @@ endmethod. ep_size = me->worksheets->size( ). -endmethod. + endmethod. @@ -12340,13 +23817,13 @@ endmethod. CLEAR eo_worksheet. -endmethod. + endmethod. method SET_ACTIVE_SHEET_INDEX. me->worksheets->active_worksheet = i_active_worksheet. -endmethod. + endmethod. @@ -12369,14 +23846,14 @@ endmethod. count = count + 1. ENDWHILE. -endmethod. + endmethod. method SET_DEFAULT_STYLE. me->default_style = ip_style. -endmethod. + endmethod. @@ -12391,16 +23868,16 @@ endmethod. * don't care about attributes here, since this data may change * dynamically -endmethod. + endmethod. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -12715,7 +24192,7 @@ endmethod. - METHOD create_serie. + method CREATE_SERIE. DATA ls_serie TYPE s_series. DATA: lv_start_row_c TYPE char7, @@ -12758,22 +24235,22 @@ endmethod. ls_serie-sername = ip_sername. APPEND ls_serie TO me->series. SORT me->series BY order ASCENDING. -ENDMETHOD. + endmethod. method SET_PRINT_LBL. me->print_label = ip_value. -endmethod. + endmethod. - METHOD set_style. + method SET_STYLE. me->ns_c14styleval = ip_style-c14style. CONDENSE me->ns_c14styleval NO-GAPS. me->ns_styleval = ip_style-cstyle. CONDENSE me->ns_styleval NO-GAPS. -ENDMETHOD. + endmethod. @@ -12801,49 +24278,49 @@ ENDMETHOD. - METHOD set_show_cat_name. + method SET_SHOW_CAT_NAME. ns_showcatnameval = ip_value. -ENDMETHOD. + endmethod. - METHOD set_show_leader_lines. + method SET_SHOW_LEADER_LINES. ns_showleaderlinesval = ip_value. -ENDMETHOD. + endmethod. - METHOD set_show_legend_key. + method SET_SHOW_LEGEND_KEY. ns_showlegendkeyval = ip_value. -ENDMETHOD. + endmethod. - METHOD set_show_percent. + method SET_SHOW_PERCENT. ns_showpercentval = ip_value. -ENDMETHOD. + endmethod. - METHOD set_show_ser_name. + method SET_SHOW_SER_NAME. ns_showsernameval = ip_value. -ENDMETHOD. + endmethod. - METHOD set_show_values. + method SET_SHOW_VALUES. ns_showvalval = ip_value. -ENDMETHOD. + endmethod. - METHOD set_varycolor. + method SET_VARYCOLOR. ns_varycolorsval = ip_value. -ENDMETHOD. + endmethod. - - *"* use this source file for the definition and implementation of *"* local helper classes, interface definitions and type @@ -12874,11 +24351,11 @@ ENDMETHOD. *"* use this source file for any macro definitions you need *"* in the implementation part of the class - - @@ -12911,7 +24388,7 @@ ENDMETHOD. - METHOD create_ax. + method CREATE_AX. DATA ls_ax TYPE s_ax. ls_ax-type = ip_type. @@ -13056,12351 +24533,86 @@ ENDMETHOD. APPEND ls_ax TO me->axes. sort me->axes by axid ascending. -ENDMETHOD. + endmethod. - METHOD set_show_cat_name. + method SET_SHOW_CAT_NAME. ns_showcatnameval = ip_value. -ENDMETHOD. + endmethod. - METHOD set_show_legend_key. + method SET_SHOW_LEGEND_KEY. ns_showlegendkeyval = ip_value. -ENDMETHOD. + endmethod. - METHOD set_show_percent. + method SET_SHOW_PERCENT. ns_showpercentval = ip_value. -ENDMETHOD. + endmethod. - METHOD set_show_ser_name. + method SET_SHOW_SER_NAME. ns_showsernameval = ip_value. -ENDMETHOD. + endmethod. - METHOD set_show_values. + method SET_SHOW_VALUES. ns_showvalval = ip_value. -ENDMETHOD. + endmethod. - METHOD set_varycolor. + method SET_VARYCOLOR. ns_varycolorsval = ip_value. -ENDMETHOD. + endmethod. - - - - *"* use this source file for the definition and implementation of -*"* local helper classes, interface definitions and type -*"* declarations - *"* use this source file for any type of declarations (class -*"* definitions, interfaces or type declarations) you need for -*"* components in the private section - *"* use this source file for any macro definitions you need -*"* in the implementation part of the class - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - METHOD create_ax. - DATA ls_ax TYPE s_ax. - ls_ax-type = ip_type. - - IF ip_type = c_catax. - IF ip_axid IS SUPPLIED. - ls_ax-axid = ip_axid. - ELSE. - ls_ax-axid = '1'. - ENDIF. - IF ip_orientation IS SUPPLIED. - ls_ax-orientation = ip_orientation. - ELSE. - ls_ax-orientation = 'minMax'. - ENDIF. - IF ip_delete IS SUPPLIED. - ls_ax-delete = ip_delete. - ELSE. - ls_ax-delete = '0'. - ENDIF. - IF ip_axpos IS SUPPLIED. - ls_ax-axpos = ip_axpos. - ELSE. - ls_ax-axpos = 'b'. - ENDIF. - IF ip_formatcode IS SUPPLIED. - ls_ax-formatcode = ip_formatcode. - ELSE. - ls_ax-formatcode = 'General'. - ENDIF. - IF ip_sourcelinked IS SUPPLIED. - ls_ax-sourcelinked = ip_sourcelinked. - ELSE. - ls_ax-sourcelinked = '1'. - ENDIF. - IF ip_majortickmark IS SUPPLIED. - ls_ax-majortickmark = ip_majortickmark. - ELSE. - ls_ax-majortickmark = 'out'. - ENDIF. - IF ip_minortickmark IS SUPPLIED. - ls_ax-minortickmark = ip_minortickmark. - ELSE. - ls_ax-minortickmark = 'none'. - ENDIF. - IF ip_ticklblpos IS SUPPLIED. - ls_ax-ticklblpos = ip_ticklblpos. - ELSE. - ls_ax-ticklblpos = 'nextTo'. - ENDIF. - IF ip_crossax IS SUPPLIED. - ls_ax-crossax = ip_crossax. - ELSE. - ls_ax-crossax = '2'. - ENDIF. - IF ip_crosses IS SUPPLIED. - ls_ax-crosses = ip_crosses. - ELSE. - ls_ax-crosses = 'autoZero'. - ENDIF. - IF ip_auto IS SUPPLIED. - ls_ax-auto = ip_auto. - ELSE. - ls_ax-auto = '1'. - ENDIF. - IF ip_lblalgn IS SUPPLIED. - ls_ax-lblalgn = ip_lblalgn. - ELSE. - ls_ax-lblalgn = 'ctr'. - ENDIF. - IF ip_lbloffset IS SUPPLIED. - ls_ax-lbloffset = ip_lbloffset. - ELSE. - ls_ax-lbloffset = '100'. - ENDIF. - IF ip_nomultilvllbl IS SUPPLIED. - ls_ax-nomultilvllbl = ip_nomultilvllbl. - ELSE. - ls_ax-nomultilvllbl = '0'. - ENDIF. - ELSEIF ip_type = c_valax. - IF ip_axid IS SUPPLIED. - ls_ax-axid = ip_axid. - ELSE. - ls_ax-axid = '2'. - ENDIF. - IF ip_orientation IS SUPPLIED. - ls_ax-orientation = ip_orientation. - ELSE. - ls_ax-orientation = 'minMax'. - ENDIF. - IF ip_delete IS SUPPLIED. - ls_ax-delete = ip_delete. - ELSE. - ls_ax-delete = '0'. - ENDIF. - IF ip_axpos IS SUPPLIED. - ls_ax-axpos = ip_axpos. - ELSE. - ls_ax-axpos = 'l'. - ENDIF. - IF ip_formatcode IS SUPPLIED. - ls_ax-formatcode = ip_formatcode. - ELSE. - ls_ax-formatcode = 'General'. - ENDIF. - IF ip_sourcelinked IS SUPPLIED. - ls_ax-sourcelinked = ip_sourcelinked. - ELSE. - ls_ax-sourcelinked = '1'. - ENDIF. - IF ip_majortickmark IS SUPPLIED. - ls_ax-majortickmark = ip_majortickmark. - ELSE. - ls_ax-majortickmark = 'out'. - ENDIF. - IF ip_minortickmark IS SUPPLIED. - ls_ax-minortickmark = ip_minortickmark. - ELSE. - ls_ax-minortickmark = 'none'. - ENDIF. - IF ip_ticklblpos IS SUPPLIED. - ls_ax-ticklblpos = ip_ticklblpos. - ELSE. - ls_ax-ticklblpos = 'nextTo'. - ENDIF. - IF ip_crossax IS SUPPLIED. - ls_ax-crossax = ip_crossax. - ELSE. - ls_ax-crossax = '1'. - ENDIF. - IF ip_crosses IS SUPPLIED. - ls_ax-crosses = ip_crosses. - ELSE. - ls_ax-crosses = 'autoZero'. - ENDIF. - IF ip_crossbetween IS SUPPLIED. - ls_ax-crossbetween = ip_crossbetween. - ELSE. - ls_ax-crossbetween = 'between'. - ENDIF. - ENDIF. - - APPEND ls_ax TO me->axes. - SORT me->axes BY axid ASCENDING. -ENDMETHOD. - - - - METHOD SET_SHOW_CAT_NAME. - ns_showcatnameval = ip_value. -ENDMETHOD. - - - - METHOD SET_SHOW_LEGEND_KEY. - ns_showlegendkeyval = ip_value. -ENDMETHOD. - - - - METHOD SET_SHOW_PERCENT. - ns_showpercentval = ip_value. -ENDMETHOD. - - - - METHOD SET_SHOW_SER_NAME. - ns_showsernameval = ip_value. -ENDMETHOD. - - - - METHOD SET_SHOW_VALUES. - ns_showvalval = ip_value. -ENDMETHOD. - - - - METHOD set_varycolor. - ns_varycolorsval = ip_value. -ENDMETHOD. - - - - *"* 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 - - ABAP - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - method CONSTRUCTOR. - " Initialise instance variables - formula1 = ''. - formula2 = ''. - type = me->c_type_none. - errorstyle = me->c_style_stop. - operator = ''. - allowblank = abap_false. - showdropdown = abap_false. - showinputmessage = abap_true. - showerrormessage = abap_true. - errortitle = ''. - error = ''. - prompttitle = ''. - prompt = ''. -* inizialize dimension range - cell_row = 1. - cell_column = 'A'. -endmethod. - - - - *"* 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 - - ABAP - - - - method ADD. - data_validations->add( ip_data_validation ). -endmethod. - - - method CLEAR. - data_validations->clear( ). -endmethod. - - - method CONSTRUCTOR. - - CREATE OBJECT data_validations. - -endmethod. - - - - method GET_ITERATOR. - eo_iterator ?= data_validations->if_object_collection~get_iterator( ). -endmethod. - - - - method IS_EMPTY. - is_empty = data_validations->if_object_collection~is_empty( ). -endmethod. - - - - method REMOVE. - data_validations->remove( ip_data_validation ). -endmethod. - - - - method SIZE. - ep_size = data_validations->if_object_collection~size( ). -endmethod. - - - - *"* 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 - - ABAP - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - method CONSTRUCTOR. - - CALL FUNCTION 'GUID_CREATE' - IMPORTING - ev_guid_16 = me->guid. - - IF ip_title IS NOT INITIAL. - title = ip_title. - ELSE. - title = me->guid. - ENDIF. - - me->type = ip_type. - -* inizialize dimension range - anchor = anchor_one_cell. - from_loc-col = 1. - from_loc-row = 1. -endmethod. - - - - method CREATE_MEDIA_NAME. - -* if media name is initial, create unique name - CHECK media_name IS INITIAL. - - index = ip_index. - CONCATENATE me->type index INTO media_name. - CONDENSE media_name NO-GAPS. -endmethod. - - - - method GET_FROM_COL. - r_from_col = me->from_loc-col. -endmethod. - - - - method GET_FROM_ROW. - r_from_row = me->from_loc-row. -endmethod. - - - - method GET_GUID. - - ep_guid = me->guid. - -endmethod. - - - - method GET_HEIGHT_EMU_STR. - r_height = pixel2emu( size-height ). - CONDENSE r_height NO-GAPS. -endmethod. - - - - method GET_INDEX. - rp_index = me->index. -endmethod. - - - - method GET_MEDIA. - CASE media_source. - WHEN c_media_source_xstring. - r_media = media. - WHEN c_media_source_www. - DATA: lt_mime TYPE tsfmime, - lv_filesize TYPE i, - lv_filesizec(10). - - CALL FUNCTION 'WWWDATA_IMPORT' - EXPORTING - key = media_key_www - TABLES - mime = lt_mime - EXCEPTIONS - OTHERS = 1. - - CALL FUNCTION 'WWWPARAMS_READ' - EXPORTING - relid = media_key_www-relid - objid = media_key_www-objid - name = 'filesize' - IMPORTING - value = lv_filesizec. - - lv_filesize = lv_filesizec. - CALL FUNCTION 'SCMS_BINARY_TO_XSTRING' - EXPORTING - input_length = lv_filesize - IMPORTING - buffer = r_media - TABLES - binary_tab = lt_mime - EXCEPTIONS - failed = 1 - OTHERS = 2. - WHEN c_media_source_mime. - DATA: lt_bin_mime TYPE sdokcntbins. - cl_wb_mime_repository=>load_mime( EXPORTING - io = me->io - IMPORTING - filesize = lv_filesize - bin_data = lt_bin_mime - CHANGING - language = sy-langu ). - - CALL FUNCTION 'SCMS_BINARY_TO_XSTRING' - EXPORTING - input_length = lv_filesize - IMPORTING - buffer = r_media - TABLES - binary_tab = lt_bin_mime - EXCEPTIONS - failed = 1 - OTHERS = 2. - ENDCASE. -endmethod. - - - - method GET_MEDIA_NAME. - CONCATENATE media_name `.` media_type INTO r_name. -endmethod. - - - - method GET_MEDIA_TYPE. - r_type = media_type. -endmethod. - - - - method GET_NAME. - r_name = title. -endmethod. - - - - method GET_POSITION. - rp_position-anchor = anchor. - rp_position-from = from_loc. - rp_position-to = to_loc. - rp_position-size = size. -endmethod. - - - - method GET_TO_COL. - r_to_col = me->to_loc-col. -endmethod. - - - - method GET_TO_ROW. - r_to_row = me->to_loc-row. -endmethod. - - - - method GET_TYPE. - rp_type = me->type. -endmethod. - - - - method GET_WIDTH_EMU_STR. - r_width = pixel2emu( size-width ). - CONDENSE r_width NO-GAPS. -endmethod. - - - - METHOD load_chart_attributes. - DATA: node TYPE REF TO if_ixml_element. - DATA: node2 TYPE REF TO if_ixml_element. - DATA: node3 TYPE REF TO if_ixml_element. - DATA: node4 TYPE REF TO if_ixml_element. - DATA: iterator TYPE REF TO if_ixml_node_iterator. - - DATA: chartspace TYPE REF TO if_ixml_node_collection. - DATA: coll_length TYPE i. - DATA: chartelem TYPE REF TO if_ixml_element. - - DATA lo_barchart TYPE REF TO zcl_excel_graph_bars. - DATA lo_piechart TYPE REF TO zcl_excel_graph_pie. - DATA lo_linechart TYPE REF TO zcl_excel_graph_line. - - TYPES: BEGIN OF t_prop, - val TYPE string, - rtl TYPE string, - lang TYPE string, - formatcode TYPE string, - sourcelinked TYPE string, - END OF t_prop. - - TYPES: BEGIN OF t_pagemargins, - b TYPE string, - l TYPE string, - r TYPE string, - t TYPE string, - header TYPE string, - footer TYPE string, - END OF t_pagemargins. - - DATA ls_prop TYPE t_prop. - DATA ls_pagemargins TYPE t_pagemargins. - - DATA lo_collection TYPE REF TO if_ixml_node_collection. - DATA lo_node TYPE REF TO if_ixml_node. - DATA lo_iterator TYPE REF TO if_ixml_node_iterator. - DATA lv_idx TYPE i. - DATA lv_order TYPE i. - DATA lv_invertifnegative TYPE string. - DATA lv_symbol TYPE string. - DATA lv_smooth TYPE c. - DATA lv_sername TYPE string. - DATA lv_label TYPE string. - DATA lv_value TYPE string. - DATA lv_axid TYPE string. - DATA lv_orientation TYPE string. - DATA lv_delete TYPE string. - DATA lv_axpos TYPE string. - DATA lv_formatcode TYPE string. - DATA lv_sourcelinked TYPE string. - DATA lv_majortickmark TYPE string. - DATA lv_minortickmark TYPE string. - DATA lv_ticklblpos TYPE string. - DATA lv_crossax TYPE string. - DATA lv_crosses TYPE string. - DATA lv_auto TYPE string. - DATA lv_lblalgn TYPE string. - DATA lv_lbloffset TYPE string. - DATA lv_nomultilvllbl TYPE string. - DATA lv_crossbetween TYPE string. - - node ?= ip_chart->if_ixml_node~get_first_child( ). - CHECK node IS NOT INITIAL. - - CASE me->graph_type. - WHEN c_graph_bars. - CREATE OBJECT lo_barchart. - me->graph = lo_barchart. - WHEN c_graph_pie. - CREATE OBJECT lo_piechart. - me->graph = lo_piechart. - WHEN c_graph_line. - CREATE OBJECT lo_linechart. - me->graph = lo_linechart. - WHEN OTHERS. - ENDCASE. - - "Fill properties - node2 ?= node->find_from_name( name = 'date1904' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - me->graph->ns_1904val = ls_prop-val. - node2 ?= node->find_from_name( name = 'lang' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - me->graph->ns_langval = ls_prop-val. - node2 ?= node->find_from_name( name = 'roundedCorners' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - me->graph->ns_roundedcornersval = ls_prop-val. - - "style - node2 ?= node->find_from_name( name = 'style' namespace = 'c14' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - me->graph->ns_c14styleval = ls_prop-val. - node2 ?= node->find_from_name( name = 'style' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - me->graph->ns_styleval = ls_prop-val. - "---------------------------Read graph properties - node2 ?= node->find_from_name( name = 'autoTitleDeleted' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - me->graph->ns_autotitledeletedval = ls_prop-val. - - "plotArea - CASE me->graph_type. - WHEN c_graph_bars. - node2 ?= node->find_from_name( name = 'barDir' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lo_barchart->ns_bardirval = ls_prop-val. - node2 ?= node->find_from_name( name = 'grouping' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lo_barchart->ns_groupingval = ls_prop-val. - node2 ?= node->find_from_name( name = 'varyColors' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lo_barchart->ns_varycolorsval = ls_prop-val. - - "Load series - CALL METHOD node->get_elements_by_tag_name - EXPORTING -* depth = 0 - name = 'ser' -* namespace = '' - RECEIVING - rval = lo_collection. - CALL METHOD lo_collection->create_iterator - RECEIVING - rval = lo_iterator. - lo_node = lo_iterator->get_next( ). - IF lo_node IS BOUND. - node2 ?= lo_node->query_interface( ixml_iid_element ). - ENDIF. - WHILE lo_node IS BOUND. - node3 ?= node2->find_from_name( name = 'idx' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_idx = ls_prop-val. - node3 ?= node2->find_from_name( name = 'order' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_order = ls_prop-val. - node3 ?= node2->find_from_name( name = 'invertIfNegative' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_invertifnegative = ls_prop-val. - node3 ?= node2->find_from_name( name = 'v' namespace = 'c' ). - IF node3 IS BOUND. - lv_sername = node3->get_value( ). - ENDIF. - node3 ?= node2->find_from_name( name = 'strRef' namespace = 'c' ). - IF node3 IS BOUND. - node4 ?= node3->find_from_name( name = 'f' namespace = 'c' ). - lv_label = node4->get_value( ). - ENDIF. - node3 ?= node2->find_from_name( name = 'numRef' namespace = 'c' ). - IF node3 IS BOUND. - node4 ?= node3->find_from_name( name = 'f' namespace = 'c' ). - lv_value = node4->get_value( ). - ENDIF. - CALL METHOD lo_barchart->create_serie - EXPORTING - ip_idx = lv_idx - ip_order = lv_order - ip_invertifnegative = lv_invertifnegative - ip_lbl = lv_label - ip_ref = lv_value - ip_sername = lv_sername. - lo_node = lo_iterator->get_next( ). - IF lo_node IS BOUND. - node2 ?= lo_node->query_interface( ixml_iid_element ). - ENDIF. - ENDWHILE. - "note: numCache avoided - node2 ?= node->find_from_name( name = 'showLegendKey' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lo_barchart->ns_showlegendkeyval = ls_prop-val. - node2 ?= node->find_from_name( name = 'showVal' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lo_barchart->ns_showvalval = ls_prop-val. - node2 ?= node->find_from_name( name = 'showCatName' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lo_barchart->ns_showcatnameval = ls_prop-val. - node2 ?= node->find_from_name( name = 'showSerName' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lo_barchart->ns_showsernameval = ls_prop-val. - node2 ?= node->find_from_name( name = 'showPercent' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lo_barchart->ns_showpercentval = ls_prop-val. - node2 ?= node->find_from_name( name = 'showBubbleSize' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lo_barchart->ns_showbubblesizeval = ls_prop-val. - node2 ?= node->find_from_name( name = 'gapWidth' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lo_barchart->ns_gapwidthval = ls_prop-val. - - "Load axes - node2 ?= node->find_from_name( name = 'barChart' namespace = 'c' ). - CALL METHOD node2->get_elements_by_tag_name - EXPORTING -* depth = 0 - name = 'axId' -* namespace = '' - RECEIVING - rval = lo_collection. - CALL METHOD lo_collection->create_iterator - RECEIVING - rval = lo_iterator. - lo_node = lo_iterator->get_next( ). - IF lo_node IS BOUND. - node2 ?= lo_node->query_interface( ixml_iid_element ). - ENDIF. - WHILE lo_node IS BOUND. - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lv_axid = ls_prop-val. - IF sy-index EQ 1. "catAx - node2 ?= node->find_from_name( name = 'catAx' namespace = 'c' ). - node3 ?= node2->find_from_name( name = 'orientation' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_orientation = ls_prop-val. - node3 ?= node2->find_from_name( name = 'delete' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_delete = ls_prop-val. - node3 ?= node2->find_from_name( name = 'axPos' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_axpos = ls_prop-val. - node3 ?= node2->find_from_name( name = 'numFmt' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_formatcode = ls_prop-formatcode. - lv_sourcelinked = ls_prop-sourcelinked. - node3 ?= node2->find_from_name( name = 'majorTickMark' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_majortickmark = ls_prop-val. - node3 ?= node2->find_from_name( name = 'majorTickMark' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_minortickmark = ls_prop-val. - node3 ?= node2->find_from_name( name = 'tickLblPos' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_ticklblpos = ls_prop-val. - node3 ?= node2->find_from_name( name = 'crossAx' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_crossax = ls_prop-val. - node3 ?= node2->find_from_name( name = 'crosses' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_crosses = ls_prop-val. - node3 ?= node2->find_from_name( name = 'auto' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_auto = ls_prop-val. - node3 ?= node2->find_from_name( name = 'lblAlgn' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_lblalgn = ls_prop-val. - node3 ?= node2->find_from_name( name = 'lblOffset' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_lbloffset = ls_prop-val. - node3 ?= node2->find_from_name( name = 'noMultiLvlLbl' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_nomultilvllbl = ls_prop-val. - CALL METHOD lo_barchart->create_ax - EXPORTING - ip_axid = lv_axid - ip_type = zcl_excel_graph_bars=>c_catax - ip_orientation = lv_orientation - ip_delete = lv_delete - ip_axpos = lv_axpos - ip_formatcode = lv_formatcode - ip_sourcelinked = lv_sourcelinked - ip_majortickmark = lv_majortickmark - ip_minortickmark = lv_minortickmark - ip_ticklblpos = lv_ticklblpos - ip_crossax = lv_crossax - ip_crosses = lv_crosses - ip_auto = lv_auto - ip_lblalgn = lv_lblalgn - ip_lbloffset = lv_lbloffset - ip_nomultilvllbl = lv_nomultilvllbl. - ELSEIF sy-index EQ 2. "valAx - node2 ?= node->find_from_name( name = 'valAx' namespace = 'c' ). - node3 ?= node2->find_from_name( name = 'orientation' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_orientation = ls_prop-val. - node3 ?= node2->find_from_name( name = 'delete' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_delete = ls_prop-val. - node3 ?= node2->find_from_name( name = 'axPos' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_axpos = ls_prop-val. - node3 ?= node2->find_from_name( name = 'numFmt' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_formatcode = ls_prop-formatcode. - lv_sourcelinked = ls_prop-sourcelinked. - node3 ?= node2->find_from_name( name = 'majorTickMark' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_majortickmark = ls_prop-val. - node3 ?= node2->find_from_name( name = 'majorTickMark' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_minortickmark = ls_prop-val. - node3 ?= node2->find_from_name( name = 'tickLblPos' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_ticklblpos = ls_prop-val. - node3 ?= node2->find_from_name( name = 'crossAx' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_crossax = ls_prop-val. - node3 ?= node2->find_from_name( name = 'crosses' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_crosses = ls_prop-val. - node3 ?= node2->find_from_name( name = 'crossBetween' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_crossbetween = ls_prop-val. - CALL METHOD lo_barchart->create_ax - EXPORTING - ip_axid = lv_axid - ip_type = zcl_excel_graph_bars=>c_valax - ip_orientation = lv_orientation - ip_delete = lv_delete - ip_axpos = lv_axpos - ip_formatcode = lv_formatcode - ip_sourcelinked = lv_sourcelinked - ip_majortickmark = lv_majortickmark - ip_minortickmark = lv_minortickmark - ip_ticklblpos = lv_ticklblpos - ip_crossax = lv_crossax - ip_crosses = lv_crosses - ip_crossbetween = lv_crossbetween. - ENDIF. - lo_node = lo_iterator->get_next( ). - IF lo_node IS BOUND. - node2 ?= lo_node->query_interface( ixml_iid_element ). - ENDIF. - ENDWHILE. - - WHEN c_graph_pie. - node2 ?= node->find_from_name( name = 'varyColors' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lo_piechart->ns_varycolorsval = ls_prop-val. - - "Load series - CALL METHOD node->get_elements_by_tag_name - EXPORTING -* depth = 0 - name = 'ser' -* namespace = '' - RECEIVING - rval = lo_collection. - CALL METHOD lo_collection->create_iterator - RECEIVING - rval = lo_iterator. - lo_node = lo_iterator->get_next( ). - IF lo_node IS BOUND. - node2 ?= lo_node->query_interface( ixml_iid_element ). - ENDIF. - WHILE lo_node IS BOUND. - node3 ?= node2->find_from_name( name = 'idx' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_idx = ls_prop-val. - node3 ?= node2->find_from_name( name = 'order' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_order = ls_prop-val. - node3 ?= node2->find_from_name( name = 'v' namespace = 'c' ). - IF node3 IS BOUND. - lv_sername = node3->get_value( ). - ENDIF. - node3 ?= node2->find_from_name( name = 'strRef' namespace = 'c' ). - IF node3 IS BOUND. - node4 ?= node3->find_from_name( name = 'f' namespace = 'c' ). - lv_label = node4->get_value( ). - ENDIF. - node3 ?= node2->find_from_name( name = 'numRef' namespace = 'c' ). - IF node3 IS BOUND. - node4 ?= node3->find_from_name( name = 'f' namespace = 'c' ). - lv_value = node4->get_value( ). - ENDIF. - CALL METHOD lo_piechart->create_serie - EXPORTING - ip_idx = lv_idx - ip_order = lv_order - ip_lbl = lv_label - ip_ref = lv_value - ip_sername = lv_sername. - lo_node = lo_iterator->get_next( ). - IF lo_node IS BOUND. - node2 ?= lo_node->query_interface( ixml_iid_element ). - ENDIF. - ENDWHILE. - - "note: numCache avoided - node2 ?= node->find_from_name( name = 'showLegendKey' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lo_piechart->ns_showlegendkeyval = ls_prop-val. - node2 ?= node->find_from_name( name = 'showVal' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lo_piechart->ns_showvalval = ls_prop-val. - node2 ?= node->find_from_name( name = 'showCatName' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lo_piechart->ns_showcatnameval = ls_prop-val. - node2 ?= node->find_from_name( name = 'showSerName' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lo_piechart->ns_showsernameval = ls_prop-val. - node2 ?= node->find_from_name( name = 'showPercent' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lo_piechart->ns_showpercentval = ls_prop-val. - node2 ?= node->find_from_name( name = 'showBubbleSize' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lo_piechart->ns_showbubblesizeval = ls_prop-val. - node2 ?= node->find_from_name( name = 'showLeaderLines' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lo_piechart->ns_showleaderlinesval = ls_prop-val. - node2 ?= node->find_from_name( name = 'firstSliceAng' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lo_piechart->ns_firstsliceangval = ls_prop-val. - WHEN c_graph_line. - node2 ?= node->find_from_name( name = 'grouping' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lo_linechart->ns_groupingval = ls_prop-val. - node2 ?= node->find_from_name( name = 'varyColors' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lo_linechart->ns_varycolorsval = ls_prop-val. - - "Load series - CALL METHOD node->get_elements_by_tag_name - EXPORTING -* depth = 0 - name = 'ser' -* namespace = '' - RECEIVING - rval = lo_collection. - CALL METHOD lo_collection->create_iterator - RECEIVING - rval = lo_iterator. - lo_node = lo_iterator->get_next( ). - IF lo_node IS BOUND. - node2 ?= lo_node->query_interface( ixml_iid_element ). - ENDIF. - WHILE lo_node IS BOUND. - node3 ?= node2->find_from_name( name = 'idx' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_idx = ls_prop-val. - node3 ?= node2->find_from_name( name = 'order' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_order = ls_prop-val. - node3 ?= node2->find_from_name( name = 'symbol' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_symbol = ls_prop-val. - node3 ?= node2->find_from_name( name = 'smooth' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_smooth = ls_prop-val. - node3 ?= node2->find_from_name( name = 'v' namespace = 'c' ). - IF node3 IS BOUND. - lv_sername = node3->get_value( ). - ENDIF. - node3 ?= node2->find_from_name( name = 'strRef' namespace = 'c' ). - IF node3 IS BOUND. - node4 ?= node3->find_from_name( name = 'f' namespace = 'c' ). - lv_label = node4->get_value( ). - ENDIF. - node3 ?= node2->find_from_name( name = 'numRef' namespace = 'c' ). - IF node3 IS BOUND. - node4 ?= node3->find_from_name( name = 'f' namespace = 'c' ). - lv_value = node4->get_value( ). - ENDIF. - CALL METHOD lo_linechart->create_serie - EXPORTING - ip_idx = lv_idx - ip_order = lv_order - ip_symbol = lv_symbol - ip_smooth = lv_smooth - ip_lbl = lv_label - ip_ref = lv_value - ip_sername = lv_sername. - lo_node = lo_iterator->get_next( ). - IF lo_node IS BOUND. - node2 ?= lo_node->query_interface( ixml_iid_element ). - ENDIF. - ENDWHILE. - "note: numCache avoided - node2 ?= node->find_from_name( name = 'showLegendKey' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lo_linechart->ns_showlegendkeyval = ls_prop-val. - node2 ?= node->find_from_name( name = 'showVal' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lo_linechart->ns_showvalval = ls_prop-val. - node2 ?= node->find_from_name( name = 'showCatName' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lo_linechart->ns_showcatnameval = ls_prop-val. - node2 ?= node->find_from_name( name = 'showSerName' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lo_linechart->ns_showsernameval = ls_prop-val. - node2 ?= node->find_from_name( name = 'showPercent' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lo_linechart->ns_showpercentval = ls_prop-val. - node2 ?= node->find_from_name( name = 'showBubbleSize' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lo_linechart->ns_showbubblesizeval = ls_prop-val. - - node ?= node->find_from_name( name = 'lineChart' namespace = 'c' ). - node2 ?= node->find_from_name( name = 'marker' namespace = 'c' DEPTH = '1' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lo_linechart->NS_MARKERVAL = ls_prop-val. - node2 ?= node->find_from_name( name = 'smooth' namespace = 'c' DEPTH = '1' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lo_linechart->NS_SMOOTHVAL = ls_prop-val. - node ?= ip_chart->if_ixml_node~get_first_child( ). - CHECK node IS NOT INITIAL. - - "Load axes - node2 ?= node->find_from_name( name = 'lineChart' namespace = 'c' ). - CALL METHOD node2->get_elements_by_tag_name - EXPORTING -* depth = 0 - name = 'axId' -* namespace = '' - RECEIVING - rval = lo_collection. - CALL METHOD lo_collection->create_iterator - RECEIVING - rval = lo_iterator. - lo_node = lo_iterator->get_next( ). - IF lo_node IS BOUND. - node2 ?= lo_node->query_interface( ixml_iid_element ). - ENDIF. - WHILE lo_node IS BOUND. - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lv_axid = ls_prop-val. - IF sy-index EQ 1. "catAx - node2 ?= node->find_from_name( name = 'catAx' namespace = 'c' ). - node3 ?= node2->find_from_name( name = 'orientation' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_orientation = ls_prop-val. - node3 ?= node2->find_from_name( name = 'delete' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_delete = ls_prop-val. - node3 ?= node2->find_from_name( name = 'axPos' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_axpos = ls_prop-val. -* node3 ?= node2->find_from_name( name = 'numFmt' namespace = 'c' ). -* zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). -* lv_formatcode = ls_prop-formatcode. -* lv_sourcelinked = ls_prop-sourcelinked. - node3 ?= node2->find_from_name( name = 'majorTickMark' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_majortickmark = ls_prop-val. - node3 ?= node2->find_from_name( name = 'majorTickMark' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_minortickmark = ls_prop-val. - node3 ?= node2->find_from_name( name = 'tickLblPos' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_ticklblpos = ls_prop-val. - node3 ?= node2->find_from_name( name = 'crossAx' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_crossax = ls_prop-val. - node3 ?= node2->find_from_name( name = 'crosses' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_crosses = ls_prop-val. - node3 ?= node2->find_from_name( name = 'auto' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_auto = ls_prop-val. - node3 ?= node2->find_from_name( name = 'lblAlgn' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_lblalgn = ls_prop-val. - node3 ?= node2->find_from_name( name = 'lblOffset' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_lbloffset = ls_prop-val. - node3 ?= node2->find_from_name( name = 'noMultiLvlLbl' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_nomultilvllbl = ls_prop-val. - CALL METHOD lo_linechart->create_ax - EXPORTING - ip_axid = lv_axid - ip_type = zcl_excel_graph_line=>c_catax - ip_orientation = lv_orientation - ip_delete = lv_delete - ip_axpos = lv_axpos - ip_formatcode = lv_formatcode - ip_sourcelinked = lv_sourcelinked - ip_majortickmark = lv_majortickmark - ip_minortickmark = lv_minortickmark - ip_ticklblpos = lv_ticklblpos - ip_crossax = lv_crossax - ip_crosses = lv_crosses - ip_auto = lv_auto - ip_lblalgn = lv_lblalgn - ip_lbloffset = lv_lbloffset - ip_nomultilvllbl = lv_nomultilvllbl. - ELSEIF sy-index EQ 2. "valAx - node2 ?= node->find_from_name( name = 'valAx' namespace = 'c' ). - node3 ?= node2->find_from_name( name = 'orientation' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_orientation = ls_prop-val. - node3 ?= node2->find_from_name( name = 'delete' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_delete = ls_prop-val. - node3 ?= node2->find_from_name( name = 'axPos' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_axpos = ls_prop-val. - node3 ?= node2->find_from_name( name = 'numFmt' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_formatcode = ls_prop-formatcode. - lv_sourcelinked = ls_prop-sourcelinked. - node3 ?= node2->find_from_name( name = 'majorTickMark' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_majortickmark = ls_prop-val. - node3 ?= node2->find_from_name( name = 'majorTickMark' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_minortickmark = ls_prop-val. - node3 ?= node2->find_from_name( name = 'tickLblPos' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_ticklblpos = ls_prop-val. - node3 ?= node2->find_from_name( name = 'crossAx' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_crossax = ls_prop-val. - node3 ?= node2->find_from_name( name = 'crosses' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_crosses = ls_prop-val. - node3 ?= node2->find_from_name( name = 'crossBetween' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = ls_prop ). - lv_crossbetween = ls_prop-val. - CALL METHOD lo_linechart->create_ax - EXPORTING - ip_axid = lv_axid - ip_type = zcl_excel_graph_line=>c_valax - ip_orientation = lv_orientation - ip_delete = lv_delete - ip_axpos = lv_axpos - ip_formatcode = lv_formatcode - ip_sourcelinked = lv_sourcelinked - ip_majortickmark = lv_majortickmark - ip_minortickmark = lv_minortickmark - ip_ticklblpos = lv_ticklblpos - ip_crossax = lv_crossax - ip_crosses = lv_crosses - ip_crossbetween = lv_crossbetween. - ENDIF. - lo_node = lo_iterator->get_next( ). - IF lo_node IS BOUND. - node2 ?= lo_node->query_interface( ixml_iid_element ). - ENDIF. - ENDWHILE. - WHEN OTHERS. - ENDCASE. - - "legend - CASE me->graph_type. - WHEN c_graph_bars. - node2 ?= node->find_from_name( name = 'legendPos' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lo_barchart->ns_legendposval = ls_prop-val. - node2 ?= node->find_from_name( name = 'overlay' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lo_barchart->ns_overlayval = ls_prop-val. - WHEN c_graph_line. - node2 ?= node->find_from_name( name = 'legendPos' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lo_linechart->ns_legendposval = ls_prop-val. - node2 ?= node->find_from_name( name = 'overlay' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lo_linechart->ns_overlayval = ls_prop-val. - WHEN c_graph_pie. - node2 ?= node->find_from_name( name = 'legendPos' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lo_piechart->ns_legendposval = ls_prop-val. - node2 ?= node->find_from_name( name = 'overlay' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lo_piechart->ns_overlayval = ls_prop-val. - node2 ?= node->find_from_name( name = 'pPr' namespace = 'a' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lo_piechart->ns_pprrtl = ls_prop-rtl. - node2 ?= node->find_from_name( name = 'endParaRPr' namespace = 'a' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - lo_piechart->ns_endpararprlang = ls_prop-lang. - - WHEN OTHERS. - ENDCASE. - - node2 ?= node->find_from_name( name = 'plotVisOnly' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - me->graph->ns_plotvisonlyval = ls_prop-val. - node2 ?= node->find_from_name( name = 'dispBlanksAs' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - me->graph->ns_dispblanksasval = ls_prop-val. - node2 ?= node->find_from_name( name = 'showDLblsOverMax' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ). - me->graph->ns_showdlblsovermaxval = ls_prop-val. - "--------------------- - - node2 ?= node->find_from_name( name = 'pageMargins' namespace = 'c' ). - zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_pagemargins ). - me->graph->pagemargins = ls_pagemargins. - - -ENDMETHOD. - - - - - - method PIXEL2EMU. -* suppose 96 DPI - IF ip_dpi IS SUPPLIED. - r_emu = ip_pixel * 914400 / ip_dpi. - ELSE. -* suppose 96 DPI - r_emu = ip_pixel * 914400 / 96. - ENDIF. -endmethod. - - - - - - - METHOD set_media. - IF ip_media IS SUPPLIED. - media = ip_media. - ENDIF. - media_type = ip_media_type. - media_source = c_media_source_xstring. - IF ip_width IS SUPPLIED. - size-width = ip_width. - ENDIF. - IF ip_height IS SUPPLIED. - size-height = ip_height. - ENDIF. -ENDMETHOD. - - - - - - method SET_MEDIA_MIME. - - io = ip_io. - media_source = c_media_source_mime. - size-width = ip_width. - size-height = ip_height. - - cl_wb_mime_repository=>load_mime( EXPORTING - io = ip_io - IMPORTING - filename = media_name - "mimetype = media_type - CHANGING - language = sy-langu ). - - SPLIT media_name AT '.' INTO media_name media_type. - - - -endmethod. - - - - - - method SET_MEDIA_WWW. - DATA: lv_value(20). - - media_key_www = ip_key. - media_source = c_media_source_www. - - CALL FUNCTION 'WWWPARAMS_READ' - EXPORTING - relid = media_key_www-relid - objid = media_key_www-objid - name = 'fileextension' - IMPORTING - value = lv_value. - media_type = lv_value. - SHIFT media_type LEFT DELETING LEADING '.'. - - size-width = ip_width. - size-height = ip_height. -endmethod. - - - - - - - METHOD set_position. - from_loc-col = zcl_excel_common=>convert_column2int( ip_from_col ) - 1. - IF ip_coloff IS SUPPLIED. - from_loc-col_offset = ip_coloff. - ENDIF. - from_loc-row = ip_from_row - 1. - IF ip_rowoff IS SUPPLIED. - from_loc-row_offset = ip_rowoff. - ENDIF. - anchor = anchor_one_cell. -ENDMETHOD. - - - - - - method SET_POSITION2. - - data: lv_anchor type zexcel_drawing_anchor. - lv_anchor = ip_anchor. - - IF lv_anchor IS INITIAL. - IF ip_to IS NOT INITIAL. - lv_anchor = anchor_two_cell. - ELSE. - lv_anchor = anchor_one_cell. - ENDIF. - ENDIF. - - CASE lv_anchor. - WHEN anchor_absolute OR anchor_one_cell. - CLEAR: me->to_loc. - WHEN anchor_two_cell. - CLEAR: me->size. - ENDCASE. - - me->from_loc = ip_from. - me->to_loc = ip_to. - me->anchor = lv_anchor. - -endmethod. - - - - *"* 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 ADD. - DATA: lv_index TYPE i. - - drawings->add( ip_drawing ). - lv_index = drawings->if_object_collection~size( ). - ip_drawing->create_media_name( - ip_index = lv_index ). -endmethod. - - - method CLEAR. - - drawings->clear( ). -endmethod. - - - - method CONSTRUCTOR. - - CREATE OBJECT drawings. - type = ip_type. - -endmethod. - - - - - method GET. - - DATA lv_index TYPE i. - lv_index = ip_index. - eo_drawing ?= drawings->if_object_collection~get( lv_index ). -endmethod. - - - - method GET_ITERATOR. - - eo_iterator ?= drawings->if_object_collection~get_iterator( ). -endmethod. - - - - method GET_TYPE. - rp_type = me->type. -endmethod. - - - - method INCLUDE. - drawings->add( ip_drawing ). -endmethod. - - - - method IS_EMPTY. - - is_empty = drawings->if_object_collection~is_empty( ). -endmethod. - - - - method REMOVE. - - drawings->remove( ip_drawing ). -endmethod. - - - - method SIZE. - - ep_size = drawings->if_object_collection~size( ). -endmethod. - - - - *"* 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 - - ABAP - - - - - - - - - - method CREATE. - data: lo_hyperlink type REF TO zcl_excel_hyperlink. - - create OBJECT lo_hyperlink. - - lo_hyperlink->location = iv_url. - lo_hyperlink->internal = iv_internal. - - ov_link = lo_hyperlink. -endmethod. - - - - - method CREATE_EXTERNAL_LINK. - - ov_link = zcl_excel_hyperlink=>create( iv_url = iv_url - iv_internal = abap_false ). -endmethod. - - - - - method CREATE_INTERNAL_LINK. - ov_link = zcl_excel_hyperlink=>create( iv_url = iv_location - iv_internal = abap_true ). -endmethod. - - - - method GET_REF. - ev_ref = row. - CONDENSE ev_ref. - CONCATENATE column ev_ref INTO ev_ref. -endmethod. - - - - method GET_URL. - ev_url = me->location. -endmethod. - - - - method IS_INTERNAL. - ev_ret = me->internal. -endmethod. - - - - - - method SET_CELL_REFERENCE. - me->column = zcl_excel_common=>convert_column2alpha( ip_column ). " issue #155 - less restrictive typing for ip_column - me->row = ip_row. -endmethod. - - - - *"* 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 CONSTRUCTOR. -endmethod. - - - - method GET_GUID. - - ep_guid = me->guid. - -endmethod. - - - - method GET_VALUE. - - ep_value = me->value. - -endmethod. - - - - method SET_RANGE_VALUE. - me->value = ip_value. -endmethod. - - - - - - - - method SET_VALUE. - DATA: lv_start_row_c TYPE char7, - lv_stop_row_c TYPE char7, - lv_value TYPE string. - lv_stop_row_c = ip_stop_row. - SHIFT lv_stop_row_c RIGHT DELETING TRAILING space. - SHIFT lv_stop_row_c LEFT DELETING LEADING space. - lv_start_row_c = ip_start_row. - SHIFT lv_start_row_c RIGHT DELETING TRAILING space. - SHIFT lv_start_row_c LEFT DELETING LEADING space. - lv_value = ip_sheet_name. - me->value = zcl_excel_common=>escape_string( ip_value = lv_value ). - - CONCATENATE me->value '!$' ip_start_column '$' lv_start_row_c ':$' ip_stop_column '$' lv_stop_row_c INTO me->value. -endmethod. - - - - *"* 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 ADD. - ranges->add( ip_range ). -endmethod. - - - method CLEAR. - ranges->clear( ). -endmethod. - - - method CONSTRUCTOR. - - - CREATE OBJECT ranges. - -endmethod. - - - - - method GET. - eo_range ?= ranges->if_object_collection~get( ip_index ). -endmethod. - - - - method GET_ITERATOR. - eo_iterator ?= ranges->if_object_collection~get_iterator( ). -endmethod. - - - - method IS_EMPTY. - is_empty = ranges->if_object_collection~is_empty( ). -endmethod. - - - - method REMOVE. - ranges->remove( ip_range ). -endmethod. - - - - method SIZE. - ep_size = ranges->if_object_collection~size( ). -endmethod. - - - - *"* 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 - - ABAP - - - - - - - method CONSTRUCTOR. -endmethod. - - - - method IS_SECURITY_ENABLED. - IF lockrevision EQ abap_true OR lockstructure EQ abap_true OR lockwindows EQ abap_true. - ep_security_enabled = abap_true. - ENDIF. -endmethod. - - - - *"* 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 - - ABAP - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - method CONSTRUCTOR. - orientation = me->c_orientation_default. - -* default margins - margin_bottom = '0.75'. - margin_footer = '0.3'. - margin_header = '0.3'. - margin_left = '0.7'. - margin_right = '0.7'. - margin_top = '0.75'. - -* clear page settings - CLEAR: black_and_white, - cell_comments, - copies, - draft, - errors, - first_page_number, - fit_to_page, - fit_to_height, - fit_to_width, - horizontal_dpi, - orientation, - page_order, - paper_height, - paper_size, - paper_width, - scale, - use_first_page_num, - use_printer_defaults, - vertical_dpi. -endmethod. - - - - - - - method GET_HEADER_FOOTER_STRING. -* ---------------------------------------------------------------------- - DATA: lc_marker_left(2) TYPE c VALUE '&L' - , lc_marker_right(2) TYPE c VALUE '&R' - , lc_marker_center(2) TYPE c VALUE '&C' - , lv_value TYPE string - . -* ---------------------------------------------------------------------- - IF ep_odd_header IS SUPPLIED. - - IF me->odd_header-left_value IS NOT INITIAL. - lv_value = me->process_header_footer( ip_header = me->odd_header ip_side = 'LEFT' ). - CONCATENATE lc_marker_left lv_value INTO ep_odd_header. - ENDIF. - - IF me->odd_header-center_value IS NOT INITIAL. - lv_value = me->process_header_footer( ip_header = me->odd_header ip_side = 'CENTER' ). - CONCATENATE ep_odd_header lc_marker_center lv_value INTO ep_odd_header. - ENDIF. - - IF me->odd_header-right_value IS NOT INITIAL. - lv_value = me->process_header_footer( ip_header = me->odd_header ip_side = 'RIGHT' ). - CONCATENATE ep_odd_header lc_marker_right lv_value INTO ep_odd_header. - ENDIF. - - ENDIF. -* ---------------------------------------------------------------------- - IF ep_odd_footer IS SUPPLIED. - - IF me->odd_footer-left_value IS NOT INITIAL. - lv_value = me->process_header_footer( ip_header = me->odd_footer ip_side = 'LEFT' ). - CONCATENATE lc_marker_left lv_value INTO ep_odd_footer. - ENDIF. - - IF me->odd_footer-center_value IS NOT INITIAL. - lv_value = me->process_header_footer( ip_header = me->odd_footer ip_side = 'CENTER' ). - CONCATENATE ep_odd_footer lc_marker_center lv_value INTO ep_odd_footer. - ENDIF. - - IF me->odd_footer-right_value IS NOT INITIAL. - lv_value = me->process_header_footer( ip_header = me->odd_footer ip_side = 'RIGHT' ). - CONCATENATE ep_odd_footer lc_marker_right lv_value INTO ep_odd_footer. - ENDIF. - - ENDIF. -* ---------------------------------------------------------------------- - IF ep_even_header IS SUPPLIED. - - IF me->even_header-left_value IS NOT INITIAL. - lv_value = me->process_header_footer( ip_header = me->even_header ip_side = 'LEFT' ). - CONCATENATE lc_marker_left lv_value INTO ep_even_header. - ENDIF. - - IF me->even_header-center_value IS NOT INITIAL. - lv_value = me->process_header_footer( ip_header = me->even_header ip_side = 'CENTER' ). - CONCATENATE ep_even_header lc_marker_center lv_value INTO ep_even_header. - ENDIF. - - IF me->even_header-right_value IS NOT INITIAL. - lv_value = me->process_header_footer( ip_header = me->even_header ip_side = 'RIGHT' ). - CONCATENATE ep_even_header lc_marker_right lv_value INTO ep_even_header. - ENDIF. - - ENDIF. -* ---------------------------------------------------------------------- - IF ep_even_footer IS SUPPLIED. - - IF me->even_footer-left_value IS NOT INITIAL. - lv_value = me->process_header_footer( ip_header = me->even_footer ip_side = 'LEFT' ). - CONCATENATE lc_marker_left lv_value INTO ep_even_footer. - ENDIF. - - IF me->even_footer-center_value IS NOT INITIAL. - lv_value = me->process_header_footer( ip_header = me->even_footer ip_side = 'CENTER' ). - CONCATENATE ep_even_footer lc_marker_center lv_value INTO ep_even_footer. - ENDIF. - - IF me->even_footer-right_value IS NOT INITIAL. - lv_value = me->process_header_footer( ip_header = me->even_footer ip_side = 'RIGHT' ). - CONCATENATE ep_even_footer lc_marker_right lv_value INTO ep_even_footer. - ENDIF. - - ENDIF. -* ---------------------------------------------------------------------- -endmethod. - - - - - - METHOD process_header_footer. - -* ---------------------------------------------------------------------- -* Only Basic font/text formatting possible: -* Bold (yes / no), Font Type, Font Size - - DATA: lv_fname(12) TYPE c - , lv_string TYPE string - . - - FIELD-SYMBOLS: <lv_value> TYPE string - , <ls_font> TYPE zexcel_s_style_font - . - -* ---------------------------------------------------------------------- - CONCATENATE ip_side '_VALUE' INTO lv_fname. - ASSIGN COMPONENT lv_fname OF STRUCTURE ip_header TO <lv_value>. - - CONCATENATE ip_side '_FONT' INTO lv_fname. - ASSIGN COMPONENT lv_fname OF STRUCTURE ip_header TO <ls_font>. - - IF <ls_font> IS ASSIGNED AND <lv_value> IS ASSIGNED. - - IF <ls_font>-name IS NOT INITIAL. - CONCATENATE '&"' <ls_font>-name ',' INTO rv_processed_string. - ELSE. - rv_processed_string = '&"-,'. - ENDIF. - - IF <ls_font>-bold = abap_true. - CONCATENATE rv_processed_string 'Bold"' INTO rv_processed_string. - ELSE. - CONCATENATE rv_processed_string 'Standard"' INTO rv_processed_string. - ENDIF. - - IF <ls_font>-size IS NOT INITIAL. - lv_string = <ls_font>-size. - CONCATENATE rv_processed_string '&' lv_string INTO rv_processed_string. - ENDIF. - - CONCATENATE rv_processed_string <lv_value> INTO rv_processed_string. - - ENDIF. -* ---------------------------------------------------------------------- - -ENDMETHOD. - - - - - - - method SET_HEADER_FOOTER. - -* Only Basic font/text formatting possible: -* Bold (yes / no), Font Type, Font Size -* -* usefull placeholders, which can be used in header/footer value strings -* '&P' - page number -* '&N' - total number of pages -* '&D' - Date -* '&T' - Time -* '&F' - File Name -* '&Z' - Path -* '&A' - Sheet name -* new line via class constant CL_ABAP_CHAR_UTILITIES=>newline -* -* Example Value String 'page &P of &N' -* -* DO NOT USE &L , &C or &R which automatically created as position markers - - me->odd_header = ip_odd_header. - me->odd_footer = ip_odd_footer. - me->even_header = ip_even_header. - me->even_footer = ip_even_footer. - - IF me->even_header IS NOT INITIAL OR me->even_footer IS NOT INITIAL. - me->diff_oddeven_headerfooter = abap_true. - ENDIF. - - -endmethod. - - - - - - - - - - method SET_PAGE_MARGINS. - DATA: lv_coef TYPE f, - lv_unit TYPE string. - - lv_unit = ip_unit. - TRANSLATE lv_unit TO UPPER CASE. - - CASE lv_unit. - WHEN 'IN'. lv_coef = 1. - WHEN 'CM'. lv_coef = '0.393700787'. - WHEN 'MM'. lv_coef = '0.0393700787'. - ENDCASE. - - IF ip_bottom IS SUPPLIED. margin_bottom = lv_coef * ip_bottom. ENDIF. - IF ip_footer IS SUPPLIED. margin_footer = lv_coef * ip_footer. ENDIF. - IF ip_header IS SUPPLIED. margin_header = lv_coef * ip_header. ENDIF. - IF ip_left IS SUPPLIED. margin_left = lv_coef * ip_left. ENDIF. - IF ip_right IS SUPPLIED. margin_right = lv_coef * ip_right. ENDIF. - IF ip_top IS SUPPLIED. margin_top = lv_coef * ip_top. ENDIF. - -endmethod. - - - - *"* 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 CONSTRUCTOR. - - - CREATE OBJECT font. - CREATE OBJECT fill. - CREATE OBJECT borders. - CREATE OBJECT alignment. - CREATE OBJECT number_format. - CREATE OBJECT protection. - -* Start of insertion # issue 139 - Dateretention of cellstyles - IF ip_guid IS NOT INITIAL. - me->guid = ip_guid. - ELSE. -* End of insertion # issue 139 - Dateretention of cellstyles - CALL FUNCTION 'GUID_CREATE' - IMPORTING - ev_guid_16 = me->guid. -* Start of insertion # issue 139 - Dateretention of cellstyles - ENDIF. -* End of insertion # issue 139 - Dateretention of cellstyles - -endmethod. - - - - method GET_GUID. - - - ep_guid = me->guid. -endmethod. - - - - *"* 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 ADD. - - - styles->add( ip_style ). -endmethod. - - - method CLEAR. - - - styles->clear( ). -endmethod. - - - method CONSTRUCTOR. - - - CREATE OBJECT styles. -endmethod. - - - - - method GET. - - - eo_style ?= styles->if_object_collection~get( ip_index ). -endmethod. - - - - method GET_ITERATOR. - - - eo_iterator ?= styles->if_object_collection~get_iterator( ). -endmethod. - - - - method IS_EMPTY. - - - is_empty = styles->if_object_collection~is_empty( ). -endmethod. - - - - - method REGISTER_NEW_STYLE. - - - me->add( io_style ). - ep_style_code = me->size( ) - 1. "style count starts from 0 -endmethod. - - - - method REMOVE. - - - styles->remove( ip_style ). -endmethod. - - - - method SIZE. - - - ep_size = styles->if_object_collection~size( ). -endmethod. - - - - *"* 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 ADD. - styles_conditional->add( ip_style_conditional ). -endmethod. - - - method CLEAR. - styles_conditional->clear( ). -endmethod. - - - method CONSTRUCTOR. - - CREATE OBJECT styles_conditional. - -endmethod. - - - - - method GET. - DATA lv_index TYPE i. - lv_index = ip_index. - eo_style_conditional ?= styles_conditional->if_object_collection~get( lv_index ). -endmethod. - - - - method GET_ITERATOR. - eo_iterator ?= styles_conditional->if_object_collection~get_iterator( ). -endmethod. - - - - method IS_EMPTY. - is_empty = styles_conditional->if_object_collection~is_empty( ). -endmethod. - - - - method REMOVE. - styles_conditional->remove( ip_style_conditional ). -endmethod. - - - - method SIZE. - ep_size = styles_conditional->if_object_collection~size( ). -endmethod. - - - - *"* 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 - - ABAP - - - - - - - - - - - - - - - - - - method CONSTRUCTOR. - horizontal = me->c_horizontal_general. - vertical = me->c_vertical_bottom. - wrapText = abap_false. - shrinkToFit = abap_false. -endmethod. - - - - method GET_STRUCTURE. - - es_alignment-horizontal = me->horizontal. - es_alignment-vertical = me->vertical. - es_alignment-textrotation = me->textrotation. - es_alignment-wraptext = me->wraptext. - es_alignment-shrinktofit = me->shrinktofit. - es_alignment-indent = me->indent. - -endmethod. - - - - *"* use this source file for the definition and implementation of -*"* local helper classes, interface definitions and type -*"* declarations - *"* use this source file for any type of declarations (class -*"* definitions, interfaces or type declarations) you need for -*"* components in the private section - *"* use this source file for any macro definitions you need -*"* in the implementation part of the class - - - - - - - - - - method CREATE. - - -* Office 2007 file format is a cab of several xml files with extension .xlsx - - DATA: lo_zip TYPE REF TO cl_abap_zip, - lo_worksheet TYPE REF TO zcl_excel_worksheet, - lo_active_worksheet TYPE REF TO zcl_excel_worksheet, - lo_iterator TYPE REF TO cl_object_collection_iterator, - lo_nested_iterator TYPE REF TO cl_object_collection_iterator, - lo_table TYPE REF TO zcl_excel_table, - lo_drawing TYPE REF TO zcl_excel_drawing, - lo_drawings TYPE REF TO zcl_excel_drawings. - - DATA: lv_content TYPE xstring, - lv_active TYPE flag, - lv_xl_sheet TYPE string, - lv_xl_sheet_rels TYPE string, - lv_xl_drawing TYPE string, - lv_xl_drawing_rels TYPE string, - lv_syindex TYPE string, - lv_value TYPE string, - lv_drawing_index TYPE i. - -********************************************************************** -* Start of insertion # issue 139 - Dateretention of cellstyles - me->excel->add_static_styles( ). -* End of insertion # issue 139 - Dateretention of cellstyles - -********************************************************************** -* STEP 1: Create archive object file (ZIP) - CREATE OBJECT lo_zip. - -********************************************************************** -* STEP 2: Add [Content_Types].xml to zip - lv_content = me->create_content_types( ). - lo_zip->add( name = me->c_content_types - content = lv_content ). - -********************************************************************** -* STEP 3: Add _rels/.rels to zip - lv_content = me->create_relationships( ). - lo_zip->add( name = me->c_relationships - content = lv_content ). - -********************************************************************** -* STEP 4: Add docProps/app.xml to zip - lv_content = me->create_docprops_app( ). - lo_zip->add( name = me->c_docprops_app - content = lv_content ). - -********************************************************************** -* STEP 5: Add docProps/core.xml to zip - lv_content = me->create_docprops_core( ). - lo_zip->add( name = me->c_docprops_core - content = lv_content ). - -********************************************************************** -* STEP 6: Add xl/_rels/workbook.xml.rels to zip - lv_content = me->create_xl_relationships( ). - lo_zip->add( name = me->c_xl_relationships - content = lv_content ). - -********************************************************************** -* STEP 6: Add xl/_rels/workbook.xml.rels to zip - lv_content = me->create_xl_theme( ). - lo_zip->add( name = me->c_xl_theme - content = lv_content ). - -********************************************************************** -* STEP 7: Add xl/workbook.xml to zip - lv_content = me->create_xl_workbook( ). - lo_zip->add( name = me->c_xl_workbook - content = lv_content ). - -********************************************************************** -* STEP 8: Add xl/workbook.xml to zip -* lv_content = me->create_xl_styles_static( ). - lv_content = me->create_xl_styles( ). - lo_zip->add( name = me->c_xl_styles - content = lv_content ). - -********************************************************************** -* STEP 9: Add sharedStrings.xml to zip - lv_content = me->create_xl_sharedstrings( ). - lo_zip->add( name = me->c_xl_sharedstrings - content = lv_content ). - -********************************************************************** -* STEP 10: Add sheet#.xml and drawing#.xml to zip - lo_iterator = me->excel->get_worksheets_iterator( ). - lo_active_worksheet = me->excel->get_active_worksheet( ). - lv_drawing_index = 1. - - WHILE lo_iterator->if_object_collection_iterator~has_next( ) EQ abap_true. - lo_worksheet ?= lo_iterator->if_object_collection_iterator~get_next( ). - IF lo_active_worksheet->get_guid( ) EQ lo_worksheet->get_guid( ). - lv_active = abap_true. - ELSE. - lv_active = abap_false. - ENDIF. - - lv_content = me->create_xl_sheet( io_worksheet = lo_worksheet - iv_active = lv_active ). - lv_xl_sheet = me->c_xl_sheet. - MOVE sy-index TO lv_syindex. - SHIFT lv_syindex RIGHT DELETING TRAILING space. - SHIFT lv_syindex LEFT DELETING LEADING space. - REPLACE ALL OCCURRENCES OF '#' IN lv_xl_sheet WITH lv_syindex. - lo_zip->add( name = lv_xl_sheet - content = lv_content ). - - lv_xl_sheet_rels = me->c_xl_sheet_rels. - lv_content = me->create_xl_sheet_rels( io_worksheet = lo_worksheet - iv_drawing_index = lv_drawing_index ). - REPLACE ALL OCCURRENCES OF '#' IN lv_xl_sheet_rels WITH lv_syindex. - lo_zip->add( name = lv_xl_sheet_rels - content = lv_content ). - - lo_nested_iterator = lo_worksheet->get_tables_iterator( ). - - WHILE lo_nested_iterator->if_object_collection_iterator~has_next( ) EQ abap_true. - lo_table ?= lo_nested_iterator->if_object_collection_iterator~get_next( ). - lv_content = me->create_xl_table( lo_table ). - - lv_value = lo_table->get_name( ). - CONCATENATE 'xl/tables/' lv_value '.xml' INTO lv_value. - lo_zip->add( name = lv_value - content = lv_content ). - ENDWHILE. - -* Add drawings ********************************** - lo_drawings = lo_worksheet->get_drawings( ). - IF lo_drawings->is_empty( ) = abap_false. - MOVE lv_drawing_index TO lv_syindex. - SHIFT lv_syindex RIGHT DELETING TRAILING space. - SHIFT lv_syindex LEFT DELETING LEADING space. - - lv_content = me->create_xl_drawings( lo_worksheet ). - lv_xl_drawing = me->c_xl_drawings. - REPLACE ALL OCCURRENCES OF '#' IN lv_xl_drawing WITH lv_syindex. - lo_zip->add( name = lv_xl_drawing - content = lv_content ). - - lv_content = me->create_xl_drawings_rels( lo_worksheet ). - lv_xl_drawing_rels = me->c_xl_drawings_rels. - REPLACE ALL OCCURRENCES OF '#' IN lv_xl_drawing_rels WITH lv_syindex. - lo_zip->add( name = lv_xl_drawing_rels - content = lv_content ). - ADD 1 TO lv_drawing_index. - ENDIF. - ENDWHILE. - -********************************************************************** -* STEP 11: Add media - lo_iterator = me->excel->get_drawings_iterator( zcl_excel_drawing=>type_image ). - WHILE lo_iterator->if_object_collection_iterator~has_next( ) EQ abap_true. - lo_drawing ?= lo_iterator->if_object_collection_iterator~get_next( ). - - lv_content = lo_drawing->get_media( ). - lv_value = lo_drawing->get_media_name( ). - CONCATENATE 'xl/media/' lv_value INTO lv_value. - lo_zip->add( name = lv_value - content = lv_content ). - ENDWHILE. - -********************************************************************** -* STEP 12: Add charts - lo_iterator = me->excel->get_drawings_iterator( zcl_excel_drawing=>type_chart ). - WHILE lo_iterator->if_object_collection_iterator~has_next( ) EQ abap_true. - lo_drawing ?= lo_iterator->if_object_collection_iterator~get_next( ). - - lv_content = lo_drawing->get_media( ). - lv_value = lo_drawing->get_media_name( ). - CONCATENATE 'xl/charts/' lv_value INTO lv_value. - lo_zip->add( name = lv_value - content = lv_content ). - ENDWHILE. - -********************************************************************** -* STEP 9: Add vbaProject.bin to zip - lo_zip->add( name = me->c_xl_vbaproject - content = me->excel->zif_excel_book_vba_project~vbaproject ). - -********************************************************************** -* STEP 12: Create the final zip - ep_excel = lo_zip->save( ). - -endmethod. - - - method CREATE_CONTENT_TYPES. -** Constant node name - DATA: lc_xml_node_workb_ct TYPE string VALUE 'application/vnd.ms-excel.sheet.macroEnabled.main+xml', - lc_xml_node_default TYPE string VALUE 'Default', - " Node attributes - lc_xml_attr_partname TYPE string VALUE 'PartName', - lc_xml_attr_extension TYPE string VALUE 'Extension', - lc_xml_attr_contenttype TYPE string VALUE 'ContentType', - lc_xml_attr_codename TYPE string VALUE 'codeName', - lc_xml_node_workb_pn TYPE string VALUE '/xl/workbook.xml', - lc_xml_node_bin_ext TYPE string VALUE 'bin', - lc_xml_node_bin_ct TYPE string VALUE 'application/vnd.ms-office.vbaProject'. - - - DATA: lo_ixml TYPE REF TO if_ixml, - lo_document TYPE REF TO if_ixml_document, - lo_document_xml TYPE REF TO cl_xml_document, - lo_element_root TYPE REF TO if_ixml_node, - lo_element TYPE REF TO if_ixml_element, - lo_collection TYPE REF TO if_ixml_node_collection, - lo_iterator TYPE REF TO if_ixml_node_iterator, - lo_node TYPE REF TO if_ixml_node, - lo_encoding TYPE REF TO if_ixml_encoding, - lo_streamfactory TYPE REF TO if_ixml_stream_factory, - lo_ostream TYPE REF TO if_ixml_ostream, - lo_renderer TYPE REF TO if_ixml_renderer. - - DATA: lv_subrc TYPE sysubrc, - lv_contenttype TYPE string, - lv_syindex(2) TYPE c. - -********************************************************************** -* STEP 3: Create standard contentType - ep_content = super->create_content_types( ). - -********************************************************************** -* STEP 2: modify XML adding the extension bin definition - - CREATE OBJECT lo_document_xml. - lv_subrc = lo_document_xml->parse_xstring( ep_content ). - - lo_document ?= lo_document_xml->m_document. - lo_element_root = lo_document->if_ixml_node~get_first_child( ). - - " extension node - lo_element = lo_document->create_simple_element( name = lc_xml_node_default - parent = lo_document ). - lo_element->set_attribute_ns( name = lc_xml_attr_extension - value = lc_xml_node_bin_ext ). - lo_element->set_attribute_ns( name = lc_xml_attr_contenttype - value = lc_xml_node_bin_ct ). - lo_element_root->append_child( new_child = lo_element ). - -********************************************************************** -* STEP 3: modify XML changing the contentType of node Override /xl/workbook.xml - - lo_collection = lo_document->get_elements_by_tag_name( 'Override' ). - lo_iterator = lo_collection->create_iterator( ). - lo_element ?= lo_iterator->get_next( ). - WHILE lo_element IS BOUND. - lv_contenttype = lo_element->get_attribute_ns( lc_xml_attr_partname ). - IF lv_contenttype EQ lc_xml_node_workb_pn. - lo_element->remove_attribute_ns( lc_xml_attr_contenttype ). - lo_element->set_attribute_ns( name = lc_xml_attr_contenttype - value = lc_xml_node_workb_ct ). - EXIT. - ENDIF. - lo_element ?= lo_iterator->get_next( ). - ENDWHILE. - -********************************************************************** -* STEP 3: Create xstring stream - CLEAR ep_content. - lo_ixml = cl_ixml=>create( ). - lo_streamfactory = lo_ixml->create_stream_factory( ). - lo_ostream = lo_streamfactory->create_ostream_xstring( string = ep_content ). - lo_renderer = lo_ixml->create_renderer( ostream = lo_ostream document = lo_document ). - lo_renderer->render( ). - -endmethod. - - - method CREATE_XL_RELATIONSHIPS. - -** Constant node name - DATA: lc_xml_node_relationships TYPE string VALUE 'Relationships', - lc_xml_node_relationship TYPE string VALUE 'Relationship', - " Node attributes - lc_xml_attr_id TYPE string VALUE 'Id', - lc_xml_attr_type TYPE string VALUE 'Type', - lc_xml_attr_target TYPE string VALUE 'Target', - " Node id - lc_xml_node_ridx_id TYPE string VALUE 'rId#', - " Node type - lc_xml_node_rid_vba_tp TYPE string VALUE 'http://schemas.microsoft.com/office/2006/relationships/vbaProject', - " Node target - lc_xml_node_rid_vba_tg TYPE string VALUE 'vbaProject.bin'. - - DATA: lo_ixml TYPE REF TO if_ixml, - lo_document TYPE REF TO if_ixml_document, - lo_document_xml TYPE REF TO cl_xml_document, - lo_element_root TYPE REF TO if_ixml_node, - lo_element TYPE REF TO if_ixml_element, - lo_node TYPE REF TO if_ixml_node, - lo_encoding TYPE REF TO if_ixml_encoding, - lo_streamfactory TYPE REF TO if_ixml_stream_factory, - lo_ostream TYPE REF TO if_ixml_ostream, - lo_renderer TYPE REF TO if_ixml_renderer. - - DATA: lv_xml_node_ridx_tg TYPE string, - lv_xml_node_ridx_id TYPE string, - lv_size TYPE i, - lv_subrc TYPE sysubrc, - lv_syindex(2) TYPE c. - -********************************************************************** -* STEP 3: Create standard relationship - ep_content = super->create_xl_relationships( ). - -********************************************************************** -* STEP 2: modify XML adding the vbaProject relation - - CREATE OBJECT lo_document_xml. - lv_subrc = lo_document_xml->parse_xstring( ep_content ). - - lo_document ?= lo_document_xml->m_document. - lo_element_root = lo_document->if_ixml_node~get_first_child( ). - - - lv_size = excel->get_worksheets_size( ). - - " Relationship node - lo_element = lo_document->create_simple_element( name = lc_xml_node_relationship - parent = lo_document ). - ADD 4 TO lv_size. - lv_syindex = lv_size. - SHIFT lv_syindex RIGHT DELETING TRAILING space. - SHIFT lv_syindex LEFT DELETING LEADING space. - lv_xml_node_ridx_id = lc_xml_node_ridx_id. - REPLACE ALL OCCURRENCES OF '#' IN lv_xml_node_ridx_id WITH lv_syindex. - lo_element->set_attribute_ns( name = lc_xml_attr_id - value = lv_xml_node_ridx_id ). - lo_element->set_attribute_ns( name = lc_xml_attr_type - value = lc_xml_node_rid_vba_tp ). - lo_element->set_attribute_ns( name = lc_xml_attr_target - value = lc_xml_node_rid_vba_tg ). - lo_element_root->append_child( new_child = lo_element ). - -********************************************************************** -* STEP 3: Create xstring stream - CLEAR ep_content. - lo_ixml = cl_ixml=>create( ). - lo_streamfactory = lo_ixml->create_stream_factory( ). - lo_ostream = lo_streamfactory->create_ostream_xstring( string = ep_content ). - lo_renderer = lo_ixml->create_renderer( ostream = lo_ostream document = lo_document ). - lo_renderer->render( ). - -endmethod. - - - method CREATE_XL_SHEET. - -** Constant node name - DATA: lc_xml_attr_codename TYPE string VALUE 'codeName'. - - DATA: lo_ixml TYPE REF TO if_ixml, - lo_document TYPE REF TO if_ixml_document, - lo_document_xml TYPE REF TO cl_xml_document, - lo_element_root TYPE REF TO if_ixml_node, - lo_element TYPE REF TO if_ixml_element, - lo_collection TYPE REF TO if_ixml_node_collection, - lo_iterator TYPE REF TO if_ixml_node_iterator, - lo_node TYPE REF TO if_ixml_node, - lo_encoding TYPE REF TO if_ixml_encoding, - lo_streamfactory TYPE REF TO if_ixml_stream_factory, - lo_ostream TYPE REF TO if_ixml_ostream, - lo_renderer TYPE REF TO if_ixml_renderer. - - DATA: lv_subrc TYPE sysubrc, - lv_syindex(2) TYPE c. - -********************************************************************** -* STEP 3: Create standard relationship - ep_content = super->create_xl_sheet( io_worksheet = io_worksheet - iv_active = iv_active ). - -********************************************************************** -* STEP 2: modify XML adding the vbaProject relation - - CREATE OBJECT lo_document_xml. - lv_subrc = lo_document_xml->parse_xstring( ep_content ). - - lo_document ?= lo_document_xml->m_document. - lo_element_root = lo_document->if_ixml_node~get_first_child( ). - -* lo_collection = lo_document->get_elements_by_tag_name( 'fileVersion' ). -* lo_iterator = lo_collection->create_iterator( ). -* lo_element ?= lo_iterator->get_next( ). -* WHILE lo_element IS BOUND. -* lo_element->set_attribute_ns( name = lc_xml_attr_codename -* value = me->excel->zif_excel_book_vba_project~codename ). -* lo_element ?= lo_iterator->get_next( ). -* ENDWHILE. - - lo_collection = lo_document->get_elements_by_tag_name( 'sheetPr' ). - lo_iterator = lo_collection->create_iterator( ). - lo_element ?= lo_iterator->get_next( ). - WHILE lo_element IS BOUND. - lo_element->set_attribute_ns( name = lc_xml_attr_codename - value = io_worksheet->zif_excel_sheet_vba_project~codename_pr ). - lo_element ?= lo_iterator->get_next( ). - ENDWHILE. - -********************************************************************** -* STEP 3: Create xstring stream - CLEAR ep_content. - lo_ixml = cl_ixml=>create( ). - lo_streamfactory = lo_ixml->create_stream_factory( ). - lo_ostream = lo_streamfactory->create_ostream_xstring( string = ep_content ). - lo_renderer = lo_ixml->create_renderer( ostream = lo_ostream document = lo_document ). - lo_renderer->render( ). -endmethod. - - - method CREATE_XL_WORKBOOK. - -** Constant node name - DATA: lc_xml_attr_codename TYPE string VALUE 'codeName'. - - DATA: lo_ixml TYPE REF TO if_ixml, - lo_document TYPE REF TO if_ixml_document, - lo_document_xml TYPE REF TO cl_xml_document, - lo_element_root TYPE REF TO if_ixml_node, - lo_element TYPE REF TO if_ixml_element, - lo_collection TYPE REF TO if_ixml_node_collection, - lo_iterator TYPE REF TO if_ixml_node_iterator, - lo_node TYPE REF TO if_ixml_node, - lo_encoding TYPE REF TO if_ixml_encoding, - lo_streamfactory TYPE REF TO if_ixml_stream_factory, - lo_ostream TYPE REF TO if_ixml_ostream, - lo_renderer TYPE REF TO if_ixml_renderer. - - DATA: lv_subrc TYPE sysubrc, - lv_syindex(2) TYPE c. - -********************************************************************** -* STEP 3: Create standard relationship - ep_content = super->create_xl_workbook( ). - -********************************************************************** -* STEP 2: modify XML adding the vbaProject relation - - CREATE OBJECT lo_document_xml. - lv_subrc = lo_document_xml->parse_xstring( ep_content ). - - lo_document ?= lo_document_xml->m_document. - lo_element_root = lo_document->if_ixml_node~get_first_child( ). - - lo_collection = lo_document->get_elements_by_tag_name( 'fileVersion' ). - lo_iterator = lo_collection->create_iterator( ). - lo_element ?= lo_iterator->get_next( ). - WHILE lo_element IS BOUND. - lo_element->set_attribute_ns( name = lc_xml_attr_codename - value = me->excel->zif_excel_book_vba_project~codename ). - lo_element ?= lo_iterator->get_next( ). - ENDWHILE. - - lo_collection = lo_document->get_elements_by_tag_name( 'workbookPr' ). - lo_iterator = lo_collection->create_iterator( ). - lo_element ?= lo_iterator->get_next( ). - WHILE lo_element IS BOUND. - lo_element->set_attribute_ns( name = lc_xml_attr_codename - value = me->excel->zif_excel_book_vba_project~codename_pr ). - lo_element ?= lo_iterator->get_next( ). - ENDWHILE. - -********************************************************************** -* STEP 3: Create xstring stream - CLEAR ep_content. - lo_ixml = cl_ixml=>create( ). - lo_streamfactory = lo_ixml->create_stream_factory( ). - lo_ostream = lo_streamfactory->create_ostream_xstring( string = ep_content ). - lo_renderer = lo_ixml->create_renderer( ostream = lo_ostream document = lo_document ). - lo_renderer->render( ). -endmethod. - - - - *"* 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_converter~can_convert_object. - - DATA: lo_salv TYPE REF TO cl_salv_table. - - TRY. - lo_salv ?= io_object. - CATCH cx_sy_move_cast_error . - RAISE EXCEPTION TYPE zcx_excel. - ENDTRY. - -ENDMETHOD. - - - METHOD zif_excel_converter~create_fieldcatalog. - DATA: lo_salv TYPE REF TO cl_salv_table. - - TRY. - zif_excel_converter~can_convert_object( io_object = io_object ). - ENDTRY. - - ws_option = is_option. - - lo_salv ?= io_object. - - CLEAR: es_layout, - et_fieldcatalog, - et_colors . - - IF lo_salv IS BOUND. - load_data( EXPORTING io_salv = lo_salv - it_table = it_table ). - apply_sort( EXPORTING it_table = it_table - IMPORTING eo_table = eo_table ) . - - get_color( EXPORTING io_table = eo_table - IMPORTING et_colors = et_colors ) . - - get_filter( IMPORTING et_filter = et_filter - CHANGING xo_table = eo_table ) . - - update_catalog( CHANGING cs_layout = es_layout - ct_fieldcatalog = et_fieldcatalog ). - ENDIF. -ENDMETHOD. - - - - - METHOD load_data. - DATA: lo_columns TYPE REF TO cl_salv_columns_table, - lo_aggregations TYPE REF TO cl_salv_aggregations, - lo_sorts TYPE REF TO cl_salv_sorts, - lo_filters TYPE REF TO cl_salv_filters, - lo_functional TYPE REF TO cl_salv_functional_settings, - lo_display TYPE REF TO cl_salv_display_settings, - lo_selections TYPE REF TO cl_salv_selections. - - DATA: ls_vari TYPE disvariant, - lo_layout TYPE REF TO cl_salv_layout. - - DATA: lr_form_tol TYPE REF TO cl_salv_form, - lr_form_eol TYPE REF TO cl_salv_form. - - DATA lt_kkblo_fieldcat TYPE kkblo_t_fieldcat. - DATA ls_kkblo_layout TYPE kkblo_layout. - DATA lt_kkblo_filter TYPE kkblo_t_filter. - DATA lt_kkblo_sort TYPE kkblo_t_sortinfo. - - lo_layout = io_salv->get_layout( ) . - lo_columns = io_salv->get_columns( ). - lo_aggregations = io_salv->get_aggregations( ) . - lo_sorts = io_salv->get_sorts( ) . - lo_filters = io_salv->get_filters( ) . - lo_display = io_salv->get_display_settings( ) . - lo_functional = io_salv->get_functional_settings( ) . - - REFRESH: wt_fcat, - wt_sort, - wt_filt. - -* First update metadata if we can. - IF io_salv->is_offline( ) = abap_false. - io_salv->get_metadata( ) . - ELSE. -* If we are offline we need to build this. - cl_salv_controller_metadata=>get_variant( - EXPORTING - r_layout = lo_layout - CHANGING - s_variant = ls_vari ). - ENDIF. - -*... get the column information - wt_fcat = cl_salv_controller_metadata=>get_lvc_fieldcatalog( - r_columns = lo_columns - r_aggregations = lo_aggregations ). - -*... get the layout information - cl_salv_controller_metadata=>get_lvc_layout( - EXPORTING - r_functional_settings = lo_functional - r_display_settings = lo_display - r_columns = lo_columns - r_aggregations = lo_aggregations - CHANGING - s_layout = ws_layo ). - -* the fieldcatalog is not complete yet! - CALL FUNCTION 'LVC_FIELDCAT_COMPLETE' - EXPORTING - i_complete = 'X' - i_refresh_buffer = space - i_buffer_active = space - is_layout = ws_layo - i_test = '1' - i_fcat_complete = 'X' - IMPORTING -* E_EDIT = - es_layout = ws_layo - CHANGING - ct_fieldcat = wt_fcat. - - IF ls_vari IS NOT INITIAL AND io_salv->is_offline( ) = abap_true. - CALL FUNCTION 'LVC_TRANSFER_TO_KKBLO' - EXPORTING - it_fieldcat_lvc = wt_fcat - is_layout_lvc = ws_layo - IMPORTING - et_fieldcat_kkblo = lt_kkblo_fieldcat - es_layout_kkblo = ls_kkblo_layout - TABLES - it_data = it_table - EXCEPTIONS - it_data_missing = 1 - it_fieldcat_lvc_missing = 2 - OTHERS = 3. - IF sy-subrc <> 0. -* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO -* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. - ENDIF. - - CALL FUNCTION 'LT_VARIANT_LOAD' - EXPORTING -* I_TOOL = 'LT' - i_tabname = '1' -* I_TABNAME_SLAVE = - i_dialog = ' ' -* I_USER_SPECIFIC = ' ' -* I_DEFAULT = 'X' -* I_NO_REPTEXT_OPTIMIZE = -* I_VIA_GRID = - i_fcat_complete = 'X' - IMPORTING -* E_EXIT = - et_fieldcat = lt_kkblo_fieldcat - et_sort = lt_kkblo_sort - et_filter = lt_kkblo_filter - CHANGING - cs_layout = ls_kkblo_layout - ct_default_fieldcat = lt_kkblo_fieldcat - cs_variant = ls_vari - EXCEPTIONS - wrong_input = 1 - fc_not_complete = 2 - not_found = 3 - OTHERS = 4 - . - IF sy-subrc <> 0. -* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO -* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. - ENDIF. - - CALL FUNCTION 'LVC_TRANSFER_FROM_KKBLO' - EXPORTING -* I_TECH_COMPLETE = -* I_STRUCTURE_NAME = - it_fieldcat_kkblo = lt_kkblo_fieldcat - it_sort_kkblo = lt_kkblo_sort - it_filter_kkblo = lt_kkblo_filter -* IT_SPECIAL_GROUPS_KKBLO = -* IT_FILTERED_ENTRIES_KKBLO = -* IT_GROUPLEVELS_KKBLO = -* IS_SUBTOT_OPTIONS_KKBLO = - is_layout_kkblo = ls_kkblo_layout -* IS_REPREP_ID_KKBLO = -* I_CALLBACK_PROGRAM_KKBLO = -* IT_ADD_FIELDCAT = -* IT_EXCLUDING_KKBLO = -* IT_EXCEPT_QINFO_KKBLO = - IMPORTING - et_fieldcat_lvc = wt_fcat - et_sort_lvc = wt_sort - et_filter_lvc = wt_filt -* ET_SPECIAL_GROUPS_LVC = -* ET_FILTER_INDEX_LVC = -* ET_GROUPLEVELS_LVC = -* ES_TOTAL_OPTIONS_LVC = - es_layout_lvc = ws_layo -* ES_VARIANT_LVC = -* E_VARIANT_SAVE_LVC = -* ES_PRINT_INFO_LVC = -* ES_REPREP_LVC = -* E_REPREP_ACTIVE_LVC = -* ET_EXCLUDING_LVC = -* ET_EXCEPT_QINFO_LVC = - TABLES - it_data = it_table - EXCEPTIONS - it_data_missing = 1 - OTHERS = 2 - . - IF sy-subrc <> 0. -* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO -* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. - ENDIF. - - ELSE. -* ... get the sort information - wt_sort = cl_salv_controller_metadata=>get_lvc_sort( lo_sorts ). - -* ... get the filter information - wt_filt = cl_salv_controller_metadata=>get_lvc_filter( lo_filters ). - ENDIF. - -ENDMETHOD. - - - - - - - - - *"* 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 - -TYPES: BEGIN OF ts_alv_types, - seoclass TYPE seoclsname, - clsname TYPE seoclsname, - END OF ts_alv_types, - tt_alv_types TYPE HASHED TABLE OF ts_alv_types WITH UNIQUE KEY seoclass. - -TYPES: BEGIN OF ts_sort_values, - fieldname TYPE fieldname, - row_int TYPE zexcel_cell_row, - value TYPE REF TO data, - new TYPE flag, - sort_level TYPE int4, - is_collapsed type flag, - END OF ts_sort_values, - - tt_sort_values TYPE HASHED TABLE OF ts_sort_values WITH UNIQUE KEY fieldname. -TYPES: BEGIN OF ts_subtotal_rows, - row_int TYPE zexcel_cell_row, - row_int_start TYPE zexcel_cell_row, - columnname TYPE fieldname, - END OF ts_subtotal_rows, - - tt_subtotal_rows TYPE HASHED TABLE OF ts_subtotal_rows WITH UNIQUE KEY row_int. - -TYPES: BEGIN OF ts_styles, - type TYPE char1, - alignment TYPE zexcel_alignment, - inttype TYPE inttype, - decimals TYPE int1, - style TYPE REF TO zcl_excel_style, - guid TYPE zexcel_cell_style, - END OF ts_styles, - - tt_styles TYPE HASHED TABLE OF ts_styles WITH UNIQUE KEY type alignment inttype decimals. - -TYPES: BEGIN OF ts_color_styles, - guid_old TYPE zexcel_cell_style, - fontcolor TYPE zexcel_style_color_argb, - fillcolor TYPE zexcel_style_color_argb, - style_new TYPE REF TO zcl_excel_style, - END OF ts_color_styles, - - tt_color_styles TYPE HASHED TABLE OF ts_color_styles WITH UNIQUE KEY guid_old fontcolor fillcolor. - *"* use this source file for any macro definitions you need -*"* in the implementation part of the class - - - - - - - - - - - - - - - - ABAP - SLIS - SOI - - - - - - - - - - - - - - - - - - - - - - - - - - - - METHOD ask_option. - DATA: ls_sval TYPE sval, - lt_sval TYPE STANDARD TABLE OF sval, - l_returncode TYPE string, - lt_fields TYPE ddfields, - ls_fields TYPE dfies. - - FIELD-SYMBOLS: <fs> TYPE ANY. - - rs_option = ws_option. - - CALL FUNCTION 'DDIF_FIELDINFO_GET' - EXPORTING - tabname = 'ZEXCEL_S_CONVERTER_OPTION' -* FIELDNAME = ' ' -* LANGU = sy-langu -* LFIELDNAME = ' ' -* ALL_TYPES = ' ' -* GROUP_NAMES = ' ' -* UCLEN = -* IMPORTING -* X030L_WA = -* DDOBJTYPE = -* DFIES_WA = -* LINES_DESCR = - TABLES - dfies_tab = lt_fields -* FIXED_VALUES = - EXCEPTIONS - not_found = 1 - internal_error = 2 - OTHERS = 3 - . - IF sy-subrc <> 0. -* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO -* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. - ENDIF. - - LOOP AT lt_fields INTO ls_fields. - ASSIGN COMPONENT ls_fields-fieldname OF STRUCTURE ws_option TO <fs>. - IF sy-subrc = 0. - CLEAR ls_sval. - ls_sval-tabname = ls_fields-tabname. - ls_sval-fieldname = ls_fields-fieldname. - ls_sval-value = <fs>. - ls_sval-field_attr = space. - ls_sval-field_obl = space. - ls_sval-comp_code = space. - ls_sval-fieldtext = ls_fields-scrtext_m. - ls_sval-comp_tab = space. - ls_sval-comp_field = space. - ls_sval-novaluehlp = space. - INSERT ls_sval INTO TABLE lt_sval. - ENDIF. - ENDLOOP. - - CALL FUNCTION 'POPUP_GET_VALUES' - EXPORTING -* NO_VALUE_CHECK = space - popup_title = 'Excel creation options'(008) -* START_COLUMN = '5' -* START_ROW = '5' - IMPORTING - returncode = l_returncode - TABLES - fields = lt_sval - EXCEPTIONS - error_in_fields = 1 - OTHERS = 2 - . - IF sy-subrc <> 0. -* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO -* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. - ELSE. - IF l_returncode = 'A'. - RAISE EXCEPTION TYPE zcx_excel. - ELSE. - LOOP AT lt_sval INTO ls_sval. - ASSIGN COMPONENT ls_sval-fieldname OF STRUCTURE ws_option TO <fs>. - IF sy-subrc = 0. - <fs> = ls_sval-value. - ENDIF. - ENDLOOP. - set_option( is_option = ws_option ) . - rs_option = ws_option. - ENDIF. - ENDIF. -ENDMETHOD. - - - - - method BIND_CELLS. - -* Do we need subtotals with grouping - READ TABLE wt_fieldcatalog TRANSPORTING NO FIELDS WITH KEY is_subtotalled = abap_true. - IF sy-subrc = 0 . - r_freeze_col = loop_subtotal( i_row_int = w_row_int - i_col_int = w_col_int ) . - ELSE. - r_freeze_col = loop_normal( i_row_int = w_row_int - i_col_int = w_col_int ) . - ENDIF. - -endmethod. - - - - - - method BIND_TABLE. - data: lt_field_catalog type zexcel_t_fieldcatalog, - ls_field_catalog type zexcel_s_fieldcatalog, - ls_fcat type zexcel_s_converter_fcat, - lo_col_dim type ref to zcl_excel_worksheet_columndime, - lo_row_dim type ref to zcl_excel_worksheet_rowdimensi, - l_col_int type zexcel_cell_column, - l_col_alpha type zexcel_cell_column_alpha, - ls_settings type zexcel_s_table_settings, - l_line type i. - - field-symbols: <fs_tab> type any table. - - assign wo_data->* to <fs_tab> . - - ls_settings-table_style = i_style_table. - ls_settings-top_left_column = zcl_excel_common=>convert_column2alpha( ip_column = w_col_int ). - ls_settings-top_left_row = w_row_int. - ls_settings-show_row_stripes = ws_layout-is_stripped. - - describe table wt_fieldcatalog lines l_line. - l_line = l_line + 1 + w_col_int. - ls_settings-bottom_right_column = zcl_excel_common=>convert_column2alpha( ip_column = l_line ). - - describe table <fs_tab> lines l_line. - ls_settings-bottom_right_row = l_line + 1 + w_row_int. - sort wt_fieldcatalog by position. - loop at wt_fieldcatalog into ls_fcat. - move-corresponding ls_fcat to ls_field_catalog. - ls_field_catalog-dynpfld = abap_true. - insert ls_field_catalog into table lt_field_catalog. - endloop. - - wo_worksheet->bind_table( - exporting - ip_table = <fs_tab> - it_field_catalog = lt_field_catalog - is_table_settings = ls_settings - importing - es_table_settings = ls_settings - ). - loop at wt_fieldcatalog into ls_fcat. - l_col_int = w_col_int + ls_fcat-position - 1. - l_col_alpha = zcl_excel_common=>convert_column2alpha( l_col_int ). -* Freeze panes - if ls_fcat-fix_column = abap_true. - add 1 to r_freeze_col. - endif. -* Now let's check for optimized - if ls_fcat-is_optimized = abap_true. - lo_col_dim = wo_worksheet->get_column_dimension( ip_column = l_col_alpha ). - lo_col_dim->set_auto_size( ip_auto_size = abap_true ) . - endif. -* Now let's check for visible - if ls_fcat-is_hidden = abap_true. - lo_col_dim = wo_worksheet->get_column_dimension( ip_column = l_col_alpha ). - lo_col_dim->set_visible( ip_visible = abap_false ) . - endif. - endloop. - -endmethod. - - - METHOD class_constructor. - DATA: ls_objects TYPE ts_alv_types. - DATA: ls_option TYPE zexcel_s_converter_option, - l_uname TYPE sy-uname. - - GET PARAMETER ID 'ZUS' FIELD l_uname. - IF l_uname IS INITIAL OR l_uname = space. - l_uname = sy-uname. - ENDIF. - -* Object CL_GUI_ALV_GRID - ls_objects-seoclass = 'CL_GUI_ALV_GRID'. - ls_objects-clsname = 'ZCL_EXCEL_CONVERTER_ALV_GRID'. - INSERT ls_objects INTO TABLE wt_objects. - -* Object CL_SALV_TABLE - ls_objects-seoclass = 'CL_SALV_TABLE'. - ls_objects-clsname = 'ZCL_EXCEL_CONVERTER_SALV_TABLE'. - INSERT ls_objects INTO TABLE wt_objects. - -* Object CL_SALV_RESULT - ls_objects-seoclass = 'CL_SALV_EX_RESULT_DATA_TABLE '. - ls_objects-clsname = 'ZCL_EXCEL_CONVERTER_RESULT_EX'. - INSERT ls_objects INTO TABLE wt_objects. -* Object CL_SALV_WD_RESULT - ls_objects-seoclass = 'CL_SALV_WD_RESULT_DATA_TABLE '. - ls_objects-clsname = 'ZCL_EXCEL_CONVERTER_RESULT_WD'. - INSERT ls_objects INTO TABLE wt_objects. - - CONCATENATE 'EXCEL_' sy-uname INTO ws_indx-srtfd. - - IMPORT p1 = ls_option FROM DATABASE indx(xl) TO ws_indx ID ws_indx-srtfd. - - IF sy-subrc = 0. - ws_option = ls_option. - ELSE. - init_option( ) . - ENDIF. - -ENDMETHOD. - - - method CLEAN_FIELDCATALOG. - DATA: l_position TYPE int1. - - FIELD-SYMBOLS: <fs_sfcat> TYPE zexcel_s_converter_fcat. - - SORT wt_fieldcatalog BY position col_id. - - CLEAR l_position. - LOOP AT wt_fieldcatalog ASSIGNING <fs_sfcat>. - ADD 1 TO l_position. - <fs_sfcat>-position = l_position. -* Default stype with alignment and format - <fs_sfcat>-style_hdr = get_style( i_type = c_type_hdr - i_alignment = <fs_sfcat>-alignment ). - IF ws_layout-is_stripped = abap_true. - <fs_sfcat>-style_stripped = get_style( i_type = c_type_str - i_alignment = <fs_sfcat>-alignment - i_inttype = <fs_sfcat>-inttype - i_decimals = <fs_sfcat>-decimals ). - ENDIF. - <fs_sfcat>-style_normal = get_style( i_type = c_type_nor - i_alignment = <fs_sfcat>-alignment - i_inttype = <fs_sfcat>-inttype - i_decimals = <fs_sfcat>-decimals ). - <fs_sfcat>-style_subtotal = get_style( i_type = c_type_sub - i_alignment = <fs_sfcat>-alignment - i_inttype = <fs_sfcat>-inttype - i_decimals = <fs_sfcat>-decimals ). - <fs_sfcat>-style_total = get_style( i_type = c_type_tot - i_alignment = <fs_sfcat>-alignment - i_inttype = <fs_sfcat>-inttype - i_decimals = <fs_sfcat>-decimals ). - ENDLOOP. - -endmethod. - - - - - - - - - - - - - METHOD convert. - - IF is_option IS SUPPLIED. - ws_option = is_option. - ENDIF. - - TRY. - execute_converter( EXPORTING io_object = io_alv - it_table = it_table ) . - ENDTRY. - - IF io_worksheet IS SUPPLIED AND io_worksheet IS BOUND. - wo_worksheet = io_worksheet. - ENDIF. - IF co_excel IS SUPPLIED. - IF co_excel IS NOT BOUND. - CREATE OBJECT co_excel. - co_excel->zif_excel_book_properties~creator = sy-uname. - ENDIF. - wo_excel = co_excel. - ENDIF. - -* Move table to data object and clean it up - IF wt_fieldcatalog IS NOT INITIAL. - create_table( ). - ELSE. - wo_data = wo_table . - ENDIF. - - IF wo_excel IS NOT BOUND. - CREATE OBJECT wo_excel. - wo_excel->zif_excel_book_properties~creator = sy-uname. - ENDIF. - IF wo_worksheet IS NOT BOUND. - " Get active sheet - wo_worksheet = wo_excel->get_active_worksheet( ). - wo_worksheet->set_title( ip_title = 'Sheet1'(001) ). - ENDIF. - - IF i_row_int <= 0. - w_row_int = 1. - ELSE. - w_row_int = i_row_int. - ENDIF. - IF i_column_int <= 0. - w_col_int = 1. - ELSE. - w_col_int = i_column_int. - ENDIF. - - create_worksheet( i_table = i_table - i_style_table = i_style_table ) . - -ENDMETHOD. - - - - - - method CREATE_COLOR_STYLE. - DATA: ls_styles TYPE ts_styles. - DATA: lo_style TYPE REF TO zcl_excel_style. - - READ TABLE wt_styles INTO ls_styles WITH KEY guid = i_style. - IF sy-subrc = 0. - lo_style = wo_excel->add_new_style( ). -* lo_style->borders = ls_styles-style->borders. -* lo_style->protection = ls_styles-style->protection. - lo_style->font->bold = ls_styles-style->font->bold. - lo_style->alignment->horizontal = ls_styles-style->alignment->horizontal. - lo_style->number_format->format_code = ls_styles-style->number_format->format_code. - - lo_style->font->color-rgb = is_colors-fontcolor. - lo_style->fill->filltype = zcl_excel_style_fill=>c_fill_solid. - lo_style->fill->fgcolor-rgb = is_colors-fillcolor. - - ro_style = lo_style. - ENDIF. -endmethod. - - - - - - - - method CREATE_FORMULAR_SUBTOTAL. - data: l_row_alpha_start type string, - l_row_alpha_end type string, - l_func_num type string. - - l_row_alpha_start = i_row_int_start. - l_row_alpha_end = i_row_int_end. - - l_func_num = get_function_number( i_totals_function = i_totals_function ). - concatenate 'SUBTOTAL(' l_func_num ',' i_column l_row_alpha_start ':' i_column l_row_alpha_end ')' into r_formula. -endmethod. - - - - - - - method CREATE_FORMULAR_TOTAL. - data: l_row_alpha type string, - l_row_e_alpha type string. - - l_row_alpha = w_row_int + 1. - l_row_e_alpha = i_row_int. - - concatenate i_totals_function '(' i_column l_row_alpha ':' i_column l_row_e_alpha ')' into r_formula. -endmethod. - - - - method CREATE_PATH. - DATA: l_sep TYPE c , - l_path TYPE string, - l_return TYPE i . - - CLEAR r_path. - - " Save the file - cl_gui_frontend_services=>get_sapgui_workdir( - CHANGING - sapworkdir = l_path - EXCEPTIONS - get_sapworkdir_failed = 1 - cntl_error = 2 - error_no_gui = 3 - not_supported_by_gui = 4 - ). - IF sy-subrc <> 0. -* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO -* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. - CONCATENATE 'Excel_' w_fcount '.xlsx' INTO r_path. - ELSE. - DO. - ADD 1 TO w_fcount. -*-obtain file separator character--------------------------------------- - CALL METHOD cl_gui_frontend_services=>get_file_separator - CHANGING - file_separator = l_sep - EXCEPTIONS - cntl_error = 1 - error_no_gui = 2 - not_supported_by_gui = 3 - OTHERS = 4. - - IF sy-subrc <> 0. - l_sep = ''. - ENDIF. - - CONCATENATE l_path l_sep 'Excel_' w_fcount '.xlsx' INTO r_path. - - IF cl_gui_frontend_services=>file_exist( file = r_path ) = abap_true. - cl_gui_frontend_services=>file_delete( EXPORTING filename = r_path - CHANGING rc = l_return - EXCEPTIONS OTHERS = 1 ). - IF sy-subrc = 0 . - RETURN. - ENDIF. - ELSE. - RETURN. - ENDIF. - ENDDO. - ENDIF. - -endmethod. - - - - - method CREATE_STYLE_HDR. - data: lo_style type ref to zcl_excel_style. - - lo_style = wo_excel->add_new_style( ). - lo_style->font->bold = abap_true. - lo_style->font->color-rgb = zcl_excel_style_color=>c_white. - lo_style->fill->filltype = zcl_excel_style_fill=>c_fill_solid. - lo_style->fill->fgcolor-rgb = 'FF4F81BD'. - if i_alignment is supplied and i_alignment is not initial. - lo_style->alignment->horizontal = i_alignment. - endif. - ro_style = lo_style . -endmethod. - - - - - - - method CREATE_STYLE_NORMAL. - DATA: lo_style TYPE REF TO zcl_excel_style, - l_format TYPE zexcel_number_format. - - IF i_inttype IS SUPPLIED AND i_inttype IS NOT INITIAL. - l_format = set_cell_format( i_inttype = i_inttype - i_decimals = i_decimals ) . - ENDIF. - IF l_format IS NOT INITIAL OR - ( i_alignment IS SUPPLIED AND i_alignment IS NOT INITIAL ) . - - lo_style = wo_excel->add_new_style( ). - - IF i_alignment IS SUPPLIED AND i_alignment IS NOT INITIAL. - lo_style->alignment->horizontal = i_alignment. - ENDIF. - - IF l_format IS NOT INITIAL. - lo_style->number_format->format_code = l_format. - ENDIF. - - ro_style = lo_style . - - ENDIF. -endmethod. - - - - - - - method CREATE_STYLE_STRIPPED. - data: lo_style type ref to zcl_excel_style. - data: l_format type zexcel_number_format. - - lo_style = wo_excel->add_new_style( ). - lo_style->fill->filltype = zcl_excel_style_fill=>c_fill_solid. - lo_style->fill->fgcolor-rgb = 'FFDBE5F1'. - if i_alignment is supplied and i_alignment is not initial. - lo_style->alignment->horizontal = i_alignment. - endif. - if i_inttype is supplied and i_inttype is not initial. - l_format = set_cell_format( i_inttype = i_inttype - i_decimals = i_decimals ) . - if l_format is not initial. - lo_style->number_format->format_code = l_format. - endif. - endif. - ro_style = lo_style. - -endmethod. - - - - - - - method CREATE_STYLE_SUBTOTAL. - data: lo_style type ref to zcl_excel_style. - data: l_format type zexcel_number_format. - - lo_style = wo_excel->add_new_style( ). - lo_style->font->bold = abap_true. - - if i_alignment is supplied and i_alignment is not initial. - lo_style->alignment->horizontal = i_alignment. - endif. - if i_inttype is supplied and i_inttype is not initial. - l_format = set_cell_format( i_inttype = i_inttype - i_decimals = i_decimals ) . - if l_format is not initial. - lo_style->number_format->format_code = l_format. - endif. - endif. - - ro_style = lo_style . - -endmethod. - - - - - - - method CREATE_STYLE_TOTAL. - DATA: lo_style TYPE REF TO zcl_excel_style. - DATA: l_format TYPE zexcel_number_format. - - lo_style = wo_excel->add_new_style( ). - lo_style->font->bold = abap_true. - - CREATE OBJECT lo_style->borders->top. - lo_style->borders->top->border_style = zcl_excel_style_border=>c_border_thin. - lo_style->borders->top->border_color-rgb = zcl_excel_style_color=>c_black. - - CREATE OBJECT lo_style->borders->right. - lo_style->borders->right->border_style = zcl_excel_style_border=>c_border_none. - lo_style->borders->right->border_color-rgb = zcl_excel_style_color=>c_black. - - CREATE OBJECT lo_style->borders->down. - lo_style->borders->down->border_style = zcl_excel_style_border=>c_border_double. - lo_style->borders->down->border_color-rgb = zcl_excel_style_color=>c_black. - - CREATE OBJECT lo_style->borders->left. - lo_style->borders->left->border_style = zcl_excel_style_border=>c_border_none. - lo_style->borders->left->border_color-rgb = zcl_excel_style_color=>c_black. - - IF i_alignment IS SUPPLIED AND i_alignment IS NOT INITIAL. - lo_style->alignment->horizontal = i_alignment. - ENDIF. - IF i_inttype IS SUPPLIED AND i_inttype IS NOT INITIAL. - l_format = set_cell_format( i_inttype = i_inttype - i_decimals = i_decimals ) . - IF l_format IS NOT INITIAL. - lo_style->number_format->format_code = l_format. - ENDIF. - ENDIF. - - ro_style = lo_style . - -endmethod. - - - method CREATE_TABLE. - TYPES: BEGIN OF ts_output, - fieldname TYPE fieldname, - function TYPE funcname, - END OF ts_output. - - DATA: lo_data TYPE REF TO data. - DATA: lo_addit TYPE REF TO cl_abap_elemdescr, - lt_components_tab TYPE cl_abap_structdescr=>component_table, - ls_components TYPE abap_componentdescr, - lo_table TYPE REF TO cl_abap_tabledescr, - lo_struc TYPE REF TO cl_abap_structdescr, - lt_fieldcatalog TYPE zexcel_t_converter_fcat. - - FIELD-SYMBOLS: <fs_scat> TYPE zexcel_s_converter_fcat, - <fs_stab> TYPE ANY, - <fs_ttab> TYPE STANDARD TABLE, - <fs> TYPE ANY, - <fs_table> TYPE STANDARD TABLE. - - SORT wt_fieldcatalog BY position. - ASSIGN wo_table->* TO <fs_table>. - - READ TABLE <fs_table> ASSIGNING <fs_stab> INDEX 1. - IF sy-subrc EQ 0 . - LOOP AT wt_fieldcatalog ASSIGNING <fs_scat>. - ASSIGN COMPONENT <fs_scat>-columnname OF STRUCTURE <fs_stab> TO <fs>. - IF sy-subrc = 0. - ls_components-name = <fs_scat>-columnname. - TRY. - lo_addit ?= cl_abap_typedescr=>describe_by_data( <fs> ). - CATCH cx_sy_move_cast_error. - CLEAR lo_addit. - DELETE TABLE wt_fieldcatalog FROM <fs_scat>. - ENDTRY. - IF lo_addit IS BOUND. - ls_components-type = lo_addit . - INSERT ls_components INTO TABLE lt_components_tab. - ENDIF. - ENDIF. - ENDLOOP. - IF lt_components_tab IS NOT INITIAL. - "create new line type - TRY. - lo_struc = cl_abap_structdescr=>create( P_COMPONENTS = lt_components_tab - P_STRICT = abap_false ). - CATCH cx_sy_struct_creation. - RETURN. " We can not do anything in this case. - ENDTRY. - - lo_table = cl_abap_tabledescr=>create( lo_struc ). - - CREATE DATA wo_data TYPE HANDLE lo_table. - CREATE DATA lo_data TYPE HANDLE lo_struc. - - ASSIGN wo_data->* TO <fs_ttab>. - ASSIGN lo_data->* TO <fs_stab>. - LOOP AT <fs_table> ASSIGNING <fs>. - CLEAR <fs_stab>. - MOVE-CORRESPONDING <fs> TO <fs_stab>. - APPEND <fs_stab> TO <fs_ttab>. - ENDLOOP. - ENDIF. - ENDIF. - -endmethod. - - - - - - METHOD create_text_subtotal. - DATA: l_string(256) TYPE c, - l_func TYPE string. - - CASE i_totals_function. - WHEN zcl_excel_table=>totals_function_sum. " Total - l_func = 'Total'(003). - WHEN zcl_excel_table=>totals_function_min. " Minimum - l_func = 'Minimum'(004). - WHEN zcl_excel_table=>totals_function_max. " Maximum - l_func = 'Maximum'(005). - WHEN zcl_excel_table=>totals_function_average. " Mean Value - l_func = 'Average'(006). - WHEN zcl_excel_table=>totals_function_count. " Count - l_func = 'Count'(007). - WHEN OTHERS. - CLEAR l_func. - ENDCASE. - - WRITE i_value TO l_string. - - CONCATENATE l_string l_func INTO r_text SEPARATED BY space. - -ENDMETHOD. - - - - - - method CREATE_WORKSHEET. - DATA: l_freeze_col TYPE i. - DATA: l_guid TYPE oltpguid16. - - IF wo_data IS BOUND AND wo_worksheet IS BOUND. - - wo_worksheet->zif_excel_sheet_properties~summarybelow = zif_excel_sheet_properties=>c_below_on. " By default is on - - IF wt_fieldcatalog IS INITIAL. - set_fieldcatalog( ) . - ELSE. - clean_fieldcatalog( ) . - ENDIF. - - IF i_table = abap_true. - l_freeze_col = bind_table( i_style_table = i_style_table ) . - ELSE. -* Let's check for filter. - IF wt_filter IS NOT INITIAL. - wo_autofilter = wo_excel->add_new_autofilter( io_sheet = wo_worksheet ). - l_freeze_col = bind_cells( ) . - set_autofilter_area( ) . - ELSE. - l_freeze_col = bind_cells( ) . - ENDIF. - - ENDIF. - -* Check for freeze panes - IF ws_layout-is_fixed = abap_true. - IF l_freeze_col = 0. - l_freeze_col = w_col_int. - ENDIF. - wo_worksheet->freeze_panes( EXPORTING ip_num_columns = l_freeze_col - ip_num_rows = w_row_int ) . - ENDIF. - ENDIF. - -endmethod. - - - - - - method EXECUTE_CONVERTER. - DATA: lt_fieldcatalog TYPE zexcel_t_fieldcatalog, - ls_fieldcatalog TYPE zexcel_s_converter_fcat, - lo_if TYPE REF TO zif_excel_converter, - ls_types TYPE ts_alv_types, - lo_addit TYPE REF TO cl_abap_classdescr. - - IF io_object IS BOUND. - TRY. - lo_addit ?= cl_abap_typedescr=>describe_by_object_ref( io_object ). - CATCH cx_sy_move_cast_error. - RAISE EXCEPTION TYPE zcx_excel. - ENDTRY. - ls_types-seoclass = lo_addit->get_relative_name( ). - READ TABLE wt_objects INTO ls_types WITH TABLE KEY seoclass = ls_types-seoclass. - IF sy-subrc = 0. - CREATE OBJECT lo_if TYPE (ls_types-clsname). - - TRY. - lo_if->create_fieldcatalog( - EXPORTING - is_option = ws_option - io_object = io_object - it_table = it_table - IMPORTING - es_layout = ws_layout - et_fieldcatalog = wt_fieldcatalog - eo_table = wo_table - et_colors = wt_colors - et_filter = wt_filter - ). - ENDTRY. -* data lines of highest level. - IF ws_layout-max_subtotal_level > 0. - ADD 1 TO ws_layout-max_subtotal_level. - ENDIF. - ELSE. - RAISE EXCEPTION TYPE zcx_excel. - ENDIF. - ELSE. - REFRESH wt_fieldcatalog. - GET REFERENCE OF it_table INTO wo_table. - ENDIF. - -endmethod. - - - - - - - method GET_COLOR_STYLE. - DATA: ls_colors TYPE zexcel_s_converter_col, - ls_color_styles TYPE ts_color_styles, - lo_style TYPE REF TO zcl_excel_style. - - r_style = i_style. " Default we change nothing - - IF wt_colors IS NOT INITIAL. -* Full line has color - READ TABLE wt_colors INTO ls_colors WITH KEY rownumber = i_row - columnname = space. - IF sy-subrc = 0. - READ TABLE wt_color_styles INTO ls_color_styles WITH KEY guid_old = i_style - fontcolor = ls_colors-fontcolor - fillcolor = ls_colors-fillcolor. - IF sy-subrc = 0. - r_style = ls_color_styles-style_new->get_guid( ). - ELSE. - lo_style = create_color_style( i_style = i_style - is_colors = ls_colors ) . - r_style = lo_style->get_guid( ) . - ls_color_styles-guid_old = i_style. - ls_color_styles-fontcolor = ls_colors-fontcolor. - ls_color_styles-fillcolor = ls_colors-fillcolor. - ls_color_styles-style_new = lo_style. - INSERT ls_color_styles INTO TABLE wt_color_styles. - ENDIF. - ELSE. -* Only field has color - READ TABLE wt_colors INTO ls_colors WITH KEY rownumber = i_row - columnname = i_fieldname. - IF sy-subrc = 0. - READ TABLE wt_color_styles INTO ls_color_styles WITH KEY guid_old = i_style - fontcolor = ls_colors-fontcolor - fillcolor = ls_colors-fillcolor. - IF sy-subrc = 0. - r_style = ls_color_styles-style_new->get_guid( ). - ELSE. - lo_style = create_color_style( i_style = i_style - is_colors = ls_colors ) . - ls_color_styles-guid_old = i_style. - ls_color_styles-fontcolor = ls_colors-fontcolor. - ls_color_styles-fillcolor = ls_colors-fillcolor. - ls_color_styles-style_new = lo_style. - INSERT ls_color_styles INTO TABLE wt_color_styles. - r_style = ls_color_styles-style_new->get_guid( ). - ENDIF. - ELSE. - r_style = i_style. - ENDIF. - ENDIF. - ELSE. - r_style = i_style. - ENDIF. - -endmethod. - - - - - - method GET_FILE. - data: lo_excel_writer type ref to zif_excel_writer, - lo_excel type ref to zcl_excel. - - data: ls_seoclass type seoclass. - - - if wo_excel is bound. - create object lo_excel_writer type zcl_excel_writer_2007. - e_file = lo_excel_writer->write_file( wo_excel ). - - select single * into ls_seoclass - from seoclass - where clsname = 'CL_BCS_CONVERT'. - - if sy-subrc = 0. - call method (ls_seoclass-clsname)=>xstring_to_solix - exporting - iv_xstring = e_file - receiving - et_solix = et_file. - e_bytecount = xstrlen( e_file ). - else. - " Convert to binary - call function 'SCMS_XSTRING_TO_BINARY' - exporting - buffer = e_file - importing - output_length = e_bytecount - tables - binary_tab = et_file. - endif. - endif. - -endmethod. - - - - - method GET_FUNCTION_NUMBER. -*Number Function -*1 AVERAGE -*2 COUNT -*3 COUNTA -*4 MAX -*5 MIN -*6 PRODUCT -*7 STDEV -*8 STDEVP -*9 SUM -*10 VAR -*11 VARP - - case i_totals_function. - when ZCL_EXCEL_TABLE=>TOTALS_FUNCTION_SUM. " Total - r_function_number = 9. - when ZCL_EXCEL_TABLE=>TOTALS_FUNCTION_MIN. " Minimum - r_function_number = 5. - when ZCL_EXCEL_TABLE=>TOTALS_FUNCTION_MAX. " Maximum - r_function_number = 4. - when ZCL_EXCEL_TABLE=>TOTALS_FUNCTION_AVERAGE. " Mean Value - r_function_number = 1. - when ZCL_EXCEL_TABLE=>TOTALS_FUNCTION_count. " Count - r_function_number = 2. - when others. - clear r_function_number. - endcase. -endmethod. - - - - METHOD get_option. - - rs_option = ws_option. - -ENDMETHOD. - - - - - - - - method GET_STYLE. - DATA: ls_styles TYPE ts_styles, - lo_style TYPE REF TO zcl_excel_style. - - CLEAR r_style. - - READ TABLE wt_styles INTO ls_styles WITH TABLE KEY type = i_type - alignment = i_alignment - inttype = i_inttype - decimals = i_decimals. - IF sy-subrc = 0. - r_style = ls_styles-guid. - ELSE. - CASE i_type. - WHEN c_type_hdr. " Header - lo_style = create_style_hdr( i_alignment = i_alignment ). - WHEN c_type_str. "Stripped - lo_style = create_style_stripped( i_alignment = i_alignment - i_inttype = i_inttype - i_decimals = i_decimals ). - WHEN c_type_nor. "Normal - lo_style = create_style_normal( i_alignment = i_alignment - i_inttype = i_inttype - i_decimals = i_decimals ). - WHEN c_type_sub. "Subtotals - lo_style = create_style_subtotal( i_alignment = i_alignment - i_inttype = i_inttype - i_decimals = i_decimals ). - WHEN c_type_tot. "Totals - lo_style = create_style_total( i_alignment = i_alignment - i_inttype = i_inttype - i_decimals = i_decimals ). - ENDCASE. - IF lo_style IS NOT INITIAL. - r_style = lo_style->get_guid( ). - ls_styles-type = i_type. - ls_styles-alignment = i_alignment. - ls_styles-inttype = i_inttype. - ls_styles-decimals = i_decimals. - ls_styles-guid = r_style. - ls_styles-style = lo_style. - INSERT ls_styles INTO TABLE wt_styles. - ENDIF. - ENDIF. -endmethod. - - - METHOD init_option. - - ws_option-filter = abap_true. - ws_option-hidenc = abap_true. - ws_option-subtot = abap_true. - -ENDMETHOD. - - - - - - - METHOD loop_normal. - DATA: lo_data TYPE REF TO data, - l_row_header TYPE zexcel_cell_row VALUE '2', - l_col_header TYPE zexcel_cell_column_alpha VALUE 'B', - l_row_int_start TYPE zexcel_cell_row, - l_row_int_end TYPE zexcel_cell_row, - l_row_int TYPE zexcel_cell_row, - l_col_int TYPE zexcel_cell_column, - l_col_alpha TYPE zexcel_cell_column_alpha, - l_col_alpha_start TYPE zexcel_cell_column_alpha, - l_cell_value TYPE zexcel_cell_value, - l_s_color TYPE abap_bool, - lo_col_dim TYPE REF TO zcl_excel_worksheet_columndime, - lo_row_dim TYPE REF TO zcl_excel_worksheet_rowdimensi, - l_formula TYPE zexcel_cell_formula, - l_style TYPE zexcel_cell_style, - l_cells TYPE i, - l_count TYPE i, - l_table_row TYPE i. - - FIELD-SYMBOLS: <fs_stab> TYPE ANY, - <fs_tab> TYPE STANDARD TABLE, - <fs_sfcat> TYPE zexcel_s_converter_fcat, - <fs_fldval> TYPE ANY, - <fs_cell_value> TYPE zexcel_cell_value. - - ASSIGN wo_data->* TO <fs_tab> . - - DESCRIBE TABLE wt_fieldcatalog LINES l_cells. - DESCRIBE TABLE <fs_tab> LINES l_count. - l_cells = l_cells * l_count. - -* It is better to loop column by column - LOOP AT wt_fieldcatalog ASSIGNING <fs_sfcat>. - l_row_int = i_row_int. - l_col_int = i_col_int + <fs_sfcat>-position - 1. - -* Freeze panes - IF <fs_sfcat>-fix_column = abap_true. - ADD 1 TO r_freeze_col. - ENDIF. - l_s_color = abap_true. - - l_col_alpha = zcl_excel_common=>convert_column2alpha( l_col_int ). - -* Only if the Header is required create it. - IF ws_option-hidehd IS INITIAL. - " First of all write column header - l_cell_value = <fs_sfcat>-scrtext_m. - wo_worksheet->set_cell( ip_column = l_col_alpha - ip_row = l_row_int - ip_value = l_cell_value - ip_style = <fs_sfcat>-style_hdr ). - ADD 1 TO l_row_int. - ENDIF. - LOOP AT <fs_tab> ASSIGNING <fs_stab>. - l_table_row = sy-tabix. -* Now the cell values - ASSIGN COMPONENT <fs_sfcat>-columnname OF STRUCTURE <fs_stab> TO <fs_fldval>. -* Now let's write the cell values - IF ws_layout-is_stripped = abap_true AND l_s_color = abap_true. - l_style = get_color_style( i_row = l_table_row - i_fieldname = <fs_sfcat>-columnname - i_style = <fs_sfcat>-style_stripped ). - wo_worksheet->set_cell( ip_column = l_col_alpha - ip_row = l_row_int - ip_value = <fs_fldval> - ip_style = l_style ). - CLEAR l_s_color. - ELSE. - l_style = get_color_style( i_row = l_table_row - i_fieldname = <fs_sfcat>-columnname - i_style = <fs_sfcat>-style_normal ). - wo_worksheet->set_cell( ip_column = l_col_alpha - ip_row = l_row_int - ip_value = <fs_fldval> - ip_style = l_style ). - l_s_color = abap_true. - ENDIF. - READ TABLE wt_filter TRANSPORTING NO FIELDS WITH TABLE KEY rownumber = l_table_row - columnname = <fs_sfcat>-columnname. - IF sy-subrc = 0. - wo_worksheet->get_cell( EXPORTING - ip_column = l_col_alpha - ip_row = l_row_int - IMPORTING - ep_value = l_cell_value ). - wo_autofilter->set_value( i_column = l_col_int - i_value = l_cell_value ). - ENDIF. - ADD 1 TO l_row_int. - ENDLOOP. -* Now let's check for optimized - IF <fs_sfcat>-is_optimized = abap_true . - lo_col_dim = wo_worksheet->get_column_dimension( ip_column = l_col_alpha ). - lo_col_dim->set_auto_size( ip_auto_size = abap_true ) . - ENDIF. -* Now let's check for visible - IF <fs_sfcat>-is_hidden = abap_true. - lo_col_dim = wo_worksheet->get_column_dimension( ip_column = l_col_alpha ). - lo_col_dim->set_visible( ip_visible = abap_false ) . - ENDIF. -* Now let's check for total versus subtotal. - IF <fs_sfcat>-totals_function IS NOT INITIAL. - l_row_int_end = l_row_int - 1. - - l_formula = create_formular_total( i_row_int = l_row_int_end - i_column = l_col_alpha - i_totals_function = <fs_sfcat>-totals_function ). - wo_worksheet->set_cell( ip_column = l_col_alpha - ip_row = l_row_int - ip_formula = l_formula - ip_style = <fs_sfcat>-style_total ). - ENDIF. - ENDLOOP. -ENDMETHOD. - - - - - - - method LOOP_SUBTOTAL. - - DATA: lo_data TYPE REF TO data, - l_row_header TYPE zexcel_cell_row VALUE '2', - l_col_header TYPE zexcel_cell_column_alpha VALUE 'B', - l_row_int_start TYPE zexcel_cell_row, - l_row_int_end TYPE zexcel_cell_row, - l_row_int TYPE zexcel_cell_row, - l_col_int TYPE zexcel_cell_column, - l_col_alpha TYPE zexcel_cell_column_alpha, - l_col_alpha_start TYPE zexcel_cell_column_alpha, - l_cell_value TYPE zexcel_cell_value, - l_s_color TYPE abap_bool, - lo_col_dim TYPE REF TO zcl_excel_worksheet_columndime, - lo_row_dim TYPE REF TO zcl_excel_worksheet_rowdimensi, - l_formula TYPE zexcel_cell_formula, - l_style TYPE zexcel_cell_style, - l_subtotalled TYPE flag, - l_text TYPE string, - ls_sort_values TYPE ts_sort_values, - ls_subtotal_rows TYPE ts_subtotal_rows, - l_sort_level TYPE int4, - l_hidden TYPE int4, - l_line TYPE i, - l_guid TYPE guid_22, - l_tabix TYPE sy-tabix, - l_cells TYPE i, - l_count TYPE i, - l_table_row TYPE i, - lt_fcat TYPE zexcel_t_converter_fcat. - - FIELD-SYMBOLS: <fs_stab> TYPE ANY, - <fs_tab> TYPE STANDARD TABLE, - <fs_sfcat> TYPE zexcel_s_converter_fcat, - <fs_fldval> TYPE ANY, - <fs_sortval> TYPE ANY, - <fs_sortv> TYPE ts_sort_values, - <fs_cell_value> TYPE zexcel_cell_value. - - ASSIGN wo_data->* TO <fs_tab> . - - REFRESH: wt_sort_values, - wt_subtotal_rows. - - DESCRIBE TABLE wt_fieldcatalog LINES l_cells. - DESCRIBE TABLE <fs_tab> LINES l_count. - l_cells = l_cells * l_count. - - READ TABLE <fs_tab> ASSIGNING <fs_stab> INDEX 1. - IF sy-subrc = 0. - l_row_int = i_row_int + 1. - lt_fcat = wt_fieldcatalog. - SORT lt_fcat BY sort_level DESCENDING. - LOOP AT lt_fcat ASSIGNING <fs_sfcat> WHERE is_subtotalled = abap_true. - ASSIGN COMPONENT <fs_sfcat>-columnname OF STRUCTURE <fs_stab> TO <fs_fldval>. - ls_sort_values-fieldname = <fs_sfcat>-columnname. - ls_sort_values-row_int = l_row_int. - ls_sort_values-sort_level = <fs_sfcat>-sort_level. - ls_sort_values-is_collapsed = <fs_sfcat>-is_collapsed. - CREATE DATA ls_sort_values-value LIKE <fs_fldval>. - ASSIGN ls_sort_values-value->* TO <fs_sortval>. - <fs_sortval> = <fs_fldval>. - INSERT ls_sort_values INTO TABLE wt_sort_values. - ENDLOOP. - ENDIF. - l_row_int = i_row_int. -* Let's check if we need to hide a sort level. - DESCRIBE TABLE wt_sort_values LINES l_line. - IF l_line <= 1. - CLEAR l_hidden. - ELSE. - LOOP AT wt_sort_values INTO ls_sort_values WHERE is_collapsed = abap_false. - IF l_hidden < ls_sort_values-sort_level. - l_hidden = ls_sort_values-sort_level. - ENDIF. - ENDLOOP. - ENDIF. - ADD 1 TO l_hidden. " As this is the first level we show. -* First loop without formular only addtional rows with subtotal text. - LOOP AT <fs_tab> ASSIGNING <fs_stab>. - ADD 1 TO l_row_int. " 1 is for header row. - l_row_int_start = l_row_int. - SORT lt_fcat BY sort_level DESCENDING. - LOOP AT lt_fcat ASSIGNING <fs_sfcat> WHERE is_subtotalled = abap_true. - l_col_int = i_col_int + <fs_sfcat>-position - 1. - l_col_alpha = zcl_excel_common=>convert_column2alpha( l_col_int ). -* Now the cell values - ASSIGN COMPONENT <fs_sfcat>-columnname OF STRUCTURE <fs_stab> TO <fs_fldval>. - IF sy-subrc = 0. - READ TABLE wt_sort_values ASSIGNING <fs_sortv> WITH TABLE KEY fieldname = <fs_sfcat>-columnname. - IF sy-subrc = 0. - ASSIGN <fs_sortv>-value->* TO <fs_sortval>. - IF <fs_sortval> <> <fs_fldval> OR <fs_sortv>-new = abap_true. -* First let's remmember the subtotal values as it has to appear later. - ls_subtotal_rows-row_int = l_row_int. - ls_subtotal_rows-row_int_start = <fs_sortv>-row_int. - ls_subtotal_rows-columnname = <fs_sfcat>-columnname. - INSERT ls_subtotal_rows INTO TABLE wt_subtotal_rows. -* Now let's write the subtotal line - l_cell_value = create_text_subtotal( i_value = <fs_sortval> - i_totals_function = <fs_sfcat>-totals_function ). - wo_worksheet->set_cell( ip_column = l_col_alpha - ip_row = l_row_int - ip_value = l_cell_value - ip_abap_type = cl_abap_typedescr=>typekind_string - ip_style = <fs_sfcat>-style_subtotal ). - lo_row_dim = wo_worksheet->get_row_dimension( ip_row = l_row_int ). - lo_row_dim->set_outline_level( ip_outline_level = <fs_sfcat>-sort_level ) . - IF <fs_sfcat>-is_collapsed = abap_true. - IF <fs_sfcat>-sort_level > l_hidden. - lo_row_dim->set_visible( ip_visible = abap_false ) . - ENDIF. - lo_row_dim->set_collapsed( ip_collapsed = <fs_sfcat>-is_collapsed ) . - ENDIF. -* Now let's change the key - ADD 1 TO l_row_int. - <fs_sortval> = <fs_fldval>. - <fs_sortv>-new = abap_false. - l_line = <fs_sortv>-sort_level. - LOOP AT wt_sort_values ASSIGNING <fs_sortv> WHERE sort_level >= l_line. - <fs_sortv>-row_int = l_row_int. - ENDLOOP. - ENDIF. - ENDIF. - ENDIF. - ENDLOOP. - ENDLOOP. - ADD 1 TO l_row_int. - l_row_int_start = l_row_int. - SORT lt_fcat BY sort_level DESCENDING. - LOOP AT lt_fcat ASSIGNING <fs_sfcat> WHERE is_subtotalled = abap_true. - l_col_int = i_col_int + <fs_sfcat>-position - 1. - l_col_alpha = zcl_excel_common=>convert_column2alpha( l_col_int ). - READ TABLE wt_sort_values ASSIGNING <fs_sortv> WITH TABLE KEY fieldname = <fs_sfcat>-columnname. - IF sy-subrc = 0. - ASSIGN <fs_sortv>-value->* TO <fs_sortval>. - ls_subtotal_rows-row_int = l_row_int. - ls_subtotal_rows-row_int_start = <fs_sortv>-row_int. - ls_subtotal_rows-columnname = <fs_sfcat>-columnname. - INSERT ls_subtotal_rows INTO TABLE wt_subtotal_rows. -* First let's write the value as it has to appear. - l_cell_value = create_text_subtotal( i_value = <fs_sortval> - i_totals_function = <fs_sfcat>-totals_function ). - wo_worksheet->set_cell( ip_column = l_col_alpha - ip_row = l_row_int - ip_value = l_cell_value - ip_abap_type = cl_abap_typedescr=>typekind_string - ip_style = <fs_sfcat>-style_subtotal ). - - l_sort_level = <fs_sfcat>-sort_level. - lo_row_dim = wo_worksheet->get_row_dimension( ip_row = l_row_int ). - lo_row_dim->set_outline_level( ip_outline_level = l_sort_level ) . - IF <fs_sfcat>-is_collapsed = abap_true. - IF <fs_sfcat>-sort_level > l_hidden. - lo_row_dim->set_visible( ip_visible = abap_false ) . - ENDIF. - lo_row_dim->set_collapsed( ip_collapsed = <fs_sfcat>-is_collapsed ) . - ENDIF. - ADD 1 TO l_row_int. - ENDIF. - ENDLOOP. -* Let's write the Grand total - l_sort_level = 0. - lo_row_dim = wo_worksheet->get_row_dimension( ip_row = l_row_int ). - lo_row_dim->set_outline_level( ip_outline_level = l_sort_level ) . -* lo_row_dim->set_collapsed( ip_collapsed = <fs_sfcat>-is_collapsed ) . Not on grand total - - l_text = create_text_subtotal( i_value = 'Grand'(002) - i_totals_function = <fs_sfcat>-totals_function ). - - l_col_alpha_start = zcl_excel_common=>convert_column2alpha( i_col_int ). - wo_worksheet->set_cell( ip_column = l_col_alpha_start - ip_row = l_row_int - ip_value = l_text - ip_abap_type = cl_abap_typedescr=>typekind_string - ip_style = <fs_sfcat>-style_subtotal ). - -* It is better to loop column by column second time around -* Second loop with formular and data. - LOOP AT wt_fieldcatalog ASSIGNING <fs_sfcat>. - l_row_int = i_row_int. - l_col_int = i_col_int + <fs_sfcat>-position - 1. -* Freeze panes - IF <fs_sfcat>-fix_column = abap_true. - ADD 1 TO r_freeze_col. - ENDIF. - l_s_color = abap_true. - l_col_alpha = zcl_excel_common=>convert_column2alpha( l_col_int ). - " First of all write column header - l_cell_value = <fs_sfcat>-scrtext_m. - wo_worksheet->set_cell( ip_column = l_col_alpha - ip_row = l_row_int - ip_value = l_cell_value - ip_abap_type = cl_abap_typedescr=>typekind_string - ip_style = <fs_sfcat>-style_hdr ). - ADD 1 TO l_row_int. - LOOP AT <fs_tab> ASSIGNING <fs_stab>. - l_table_row = sy-tabix. -* Now the cell values - ASSIGN COMPONENT <fs_sfcat>-columnname OF STRUCTURE <fs_stab> TO <fs_fldval>. -* Let's check for subtotal lines - DO. - READ TABLE wt_subtotal_rows TRANSPORTING NO FIELDS WITH TABLE KEY row_int = l_row_int. - IF sy-subrc = 0. - IF <fs_sfcat>-is_subtotalled = abap_false AND - <fs_sfcat>-totals_function IS NOT INITIAL. - DO. - READ TABLE wt_subtotal_rows INTO ls_subtotal_rows WITH TABLE KEY row_int = l_row_int. - IF sy-subrc = 0. - l_row_int_start = ls_subtotal_rows-row_int_start. - l_row_int_end = l_row_int - 1. - - l_formula = create_formular_subtotal( i_row_int_start = l_row_int_start - i_row_int_end = l_row_int_end - i_column = l_col_alpha - i_totals_function = <fs_sfcat>-totals_function ). - wo_worksheet->set_cell( ip_column = l_col_alpha - ip_row = l_row_int - ip_formula = l_formula - ip_style = <fs_sfcat>-style_subtotal ). - IF <fs_sfcat>-is_collapsed = abap_true. - lo_row_dim = wo_worksheet->get_row_dimension( ip_row = l_row_int ). - lo_row_dim->set_collapsed( ip_collapsed = <fs_sfcat>-is_collapsed ). - IF <fs_sfcat>-sort_level > l_hidden. - lo_row_dim->set_visible( ip_visible = abap_false ) . - ENDIF. - ENDIF. - ADD 1 TO l_row_int. - ELSE. - EXIT. - ENDIF. - ENDDO. - ELSE. - ADD 1 TO l_row_int. - ENDIF. - ELSE. - EXIT. - ENDIF. - ENDDO. -* Let's set the row dimension values - lo_row_dim = wo_worksheet->get_row_dimension( ip_row = l_row_int ). - lo_row_dim->set_outline_level( ip_outline_level = ws_layout-max_subtotal_level ) . - IF <fs_sfcat>-is_collapsed = abap_true. - lo_row_dim->set_visible( ip_visible = abap_false ) . - lo_row_dim->set_collapsed( ip_collapsed = <fs_sfcat>-is_collapsed ) . - ENDIF. -* Now let's write the cell values - IF ws_layout-is_stripped = abap_true AND l_s_color = abap_true. - l_style = get_color_style( i_row = l_table_row - i_fieldname = <fs_sfcat>-columnname - i_style = <fs_sfcat>-style_stripped ). - wo_worksheet->set_cell( ip_column = l_col_alpha - ip_row = l_row_int - ip_value = <fs_fldval> - ip_style = l_style ). - CLEAR l_s_color. - ELSE. - l_style = get_color_style( i_row = l_table_row - i_fieldname = <fs_sfcat>-columnname - i_style = <fs_sfcat>-style_normal ). - wo_worksheet->set_cell( ip_column = l_col_alpha - ip_row = l_row_int - ip_value = <fs_fldval> - ip_style = l_style ). - l_s_color = abap_true. - ENDIF. - READ TABLE wt_filter TRANSPORTING NO FIELDS WITH TABLE KEY rownumber = l_table_row - columnname = <fs_sfcat>-columnname. - IF sy-subrc = 0. - wo_worksheet->get_cell( EXPORTING - ip_column = l_col_alpha - ip_row = l_row_int - IMPORTING - ep_value = l_cell_value ). - wo_autofilter->set_value( i_column = l_col_int - i_value = l_cell_value ). - ENDIF. - ADD 1 TO l_row_int. - ENDLOOP. -* Let's check for subtotal lines - DO. - READ TABLE wt_subtotal_rows TRANSPORTING NO FIELDS WITH TABLE KEY row_int = l_row_int. - IF sy-subrc = 0. - IF <fs_sfcat>-is_subtotalled = abap_false AND - <fs_sfcat>-totals_function IS NOT INITIAL. - DO. - READ TABLE wt_subtotal_rows INTO ls_subtotal_rows WITH TABLE KEY row_int = l_row_int. - IF sy-subrc = 0. - l_row_int_start = ls_subtotal_rows-row_int_start. - l_row_int_end = l_row_int - 1. - - l_formula = create_formular_subtotal( i_row_int_start = l_row_int_start - i_row_int_end = l_row_int_end - i_column = l_col_alpha - i_totals_function = <fs_sfcat>-totals_function ). - wo_worksheet->set_cell( ip_column = l_col_alpha - ip_row = l_row_int - ip_formula = l_formula - ip_style = <fs_sfcat>-style_subtotal ). - IF <fs_sfcat>-is_collapsed = abap_true. - lo_row_dim = wo_worksheet->get_row_dimension( ip_row = l_row_int ). - lo_row_dim->set_collapsed( ip_collapsed = <fs_sfcat>-is_collapsed ). - ENDIF. - ADD 1 TO l_row_int. - ELSE. - EXIT. - ENDIF. - ENDDO. - ELSE. - ADD 1 TO l_row_int. - ENDIF. - ELSE. - EXIT. - ENDIF. - ENDDO. -* Now let's check for Grand total - IF <fs_sfcat>-is_subtotalled = abap_false AND - <fs_sfcat>-totals_function IS NOT INITIAL. - l_row_int_start = i_row_int + 1. - l_row_int_end = l_row_int - 1. - - l_formula = create_formular_subtotal( i_row_int_start = l_row_int_start - i_row_int_end = l_row_int_end - i_column = l_col_alpha - i_totals_function = <fs_sfcat>-totals_function ). - wo_worksheet->set_cell( ip_column = l_col_alpha - ip_row = l_row_int - ip_formula = l_formula - ip_style = <fs_sfcat>-style_subtotal ). - ENDIF. -* Now let's check for optimized - IF <fs_sfcat>-is_optimized = abap_true. - lo_col_dim = wo_worksheet->get_column_dimension( ip_column = l_col_alpha ). - lo_col_dim->set_auto_size( ip_auto_size = abap_true ) . - ENDIF. -* Now let's check for visible - IF <fs_sfcat>-is_hidden = abap_true. - lo_col_dim = wo_worksheet->get_column_dimension( ip_column = l_col_alpha ). - lo_col_dim->set_visible( ip_visible = abap_false ) . - ENDIF. - ENDLOOP. - -endmethod. - - - method OPEN_FILE. - data: l_bytecount type i, - lt_file type solix_tab, - l_dir type string, - l_sep type c. - - field-symbols: <fs_data> type any table. - - assign wo_data->* to <fs_data>. - -* catch zcx_excel . -*endtry. - if wo_excel is bound. - get_file( importing e_bytecount = l_bytecount - et_file = lt_file ) . - - l_dir = create_path( ) . - - cl_gui_frontend_services=>gui_download( exporting bin_filesize = l_bytecount - filename = l_dir - filetype = 'BIN' - changing data_tab = lt_file ). - cl_gui_frontend_services=>execute( - exporting - document = l_dir -* application = -* parameter = -* default_directory = -* maximized = -* minimized = -* synchronous = -* operation = 'OPEN' - exceptions - cntl_error = 1 - error_no_gui = 2 - bad_parameter = 3 - file_not_found = 4 - path_not_found = 5 - file_extension_unknown = 6 - error_execute_failed = 7 - synchronous_failed = 8 - not_supported_by_gui = 9 - ). - if sy-subrc <> 0. - message id sy-msgid type sy-msgty number sy-msgno - with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. - endif. - - endif. - - -endmethod. - - - method SET_AUTOFILTER_AREA. - DATA: ls_area TYPE zexcel_s_autofilter_area, - l_lines TYPE i, - lt_values TYPE zexcel_t_autofilter_values, - ls_values TYPE zexcel_s_autofilter_values. - -* Let's check for filter. - IF wo_autofilter IS BOUND. - ls_area-row_start = 1. - lt_values = wo_autofilter->get_values( ) . - SORT lt_values BY column ASCENDING. - DESCRIBE TABLE lt_values LINES l_lines. - READ TABLE lt_values INTO ls_values INDEX 1. - IF sy-subrc = 0. - ls_area-col_start = ls_values-column. - ENDIF. - READ TABLE lt_values INTO ls_values INDEX l_lines. - IF sy-subrc = 0. - ls_area-col_end = ls_values-column. - ENDIF. - wo_autofilter->set_filter_area( is_area = ls_area ) . - ENDIF. - -endmethod. - - - - - - method SET_CELL_FORMAT. - DATA: l_format TYPE zexcel_number_format. - - CLEAR r_format. - CASE i_inttype. - WHEN cl_abap_typedescr=>typekind_date. - r_format = wo_worksheet->get_default_excel_date_format( ). - WHEN cl_abap_typedescr=>typekind_time. - r_format = wo_worksheet->get_default_excel_time_format( ). - WHEN cl_abap_typedescr=>typekind_float OR cl_abap_typedescr=>typekind_packed. - IF i_decimals > 0 . - l_format = '#,##0.'. - DO i_decimals TIMES. - CONCATENATE l_format '0' INTO l_format. - ENDDO. - r_format = l_format. - ENDIF. - WHEN cl_abap_typedescr=>typekind_int OR cl_abap_typedescr=>typekind_int1 OR cl_abap_typedescr=>typekind_int2. - r_format = '#,##0'. - ENDCASE. - -endmethod. - - - METHOD set_fieldcatalog. - - DATA: lr_data TYPE REF TO data, - lo_structdescr TYPE REF TO cl_abap_structdescr, - lt_dfies TYPE ddfields, - ls_dfies TYPE dfies, - ls_fieldcatalog TYPE zexcel_s_fieldcatalog. - DATA: ls_fcat TYPE zexcel_s_converter_fcat. - - FIELD-SYMBOLS: <fs_tab> TYPE ANY TABLE. - - ASSIGN wo_data->* TO <fs_tab> . - - CREATE DATA lr_data LIKE LINE OF <fs_tab>. - - lo_structdescr ?= cl_abap_structdescr=>describe_by_data_ref( lr_data ). - - lt_dfies = zcl_excel_common=>describe_structure( io_struct = lo_structdescr ). - - LOOP AT lt_dfies INTO ls_dfies. - MOVE-CORRESPONDING ls_dfies TO ls_fcat. - ls_fcat-columnname = ls_dfies-fieldname. - INSERT ls_fcat INTO TABLE wt_fieldcatalog. - ENDLOOP. - - clean_fieldcatalog( ). - -ENDMETHOD. - - - - METHOD set_option. - - IF ws_indx-begdt IS INITIAL. - ws_indx-begdt = sy-datum. - ENDIF. - - ws_indx-aedat = sy-datum. - ws_indx-usera = sy-uname. - ws_indx-pgmid = sy-cprog. - - EXPORT p1 = is_option TO DATABASE indx(xl) FROM ws_indx ID ws_indx-srtfd. - - IF sy-subrc = 0. - ws_option = is_option. - ENDIF. - -ENDMETHOD. - - - - method WRITE_FILE. - data: l_bytecount type i, - lt_file type solix_tab, - l_dir type string. - - field-symbols: <fs_data> type any table. - - assign wo_data->* to <fs_data>. - -* catch zcx_excel . -*endtry. - if wo_excel is bound. - get_file( importing e_bytecount = l_bytecount - et_file = lt_file ) . - if i_path is initial. - l_dir = create_path( ) . - else. - l_dir = i_path. - endif. - cl_gui_frontend_services=>gui_download( exporting bin_filesize = l_bytecount - filename = l_dir - filetype = 'BIN' - changing data_tab = lt_file ). - endif. -endmethod. - - - - *"* 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_CONVERTER~CAN_CONVERT_OBJECT. - data: lo_alv type REF TO cl_gui_alv_grid. - - try. - lo_alv ?= io_object. - catch cx_sy_move_cast_error . - raise exception type zcx_excel. - endtry. - -endmethod. - - - METHOD zif_excel_converter~create_fieldcatalog. - DATA: lo_alv TYPE REF TO cl_gui_alv_grid. - - TRY. - zif_excel_converter~can_convert_object( io_object = io_object ). - ENDTRY. - - ws_option = is_option. - - lo_alv ?= io_object. - - CLEAR: es_layout, - et_fieldcatalog. - - IF lo_alv IS BOUND. - lo_alv->get_frontend_fieldcatalog( IMPORTING et_fieldcatalog = wt_fcat ). - lo_alv->get_frontend_layout( IMPORTING es_layout = ws_layo ). - lo_alv->get_sort_criteria( IMPORTING et_sort = wt_sort ) . - lo_alv->get_filter_criteria( IMPORTING et_filter = wt_filt ) . - - apply_sort( EXPORTING it_table = it_table - IMPORTING eo_table = eo_table ) . - - get_color( EXPORTING io_table = eo_table - IMPORTING et_colors = et_colors ) . - - get_filter( IMPORTING et_filter = et_filter - CHANGING xo_table = eo_table ) . - - update_catalog( CHANGING cs_layout = es_layout - ct_fieldcatalog = et_fieldcatalog ). - ENDIF. -ENDMETHOD. - - - - *"* 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 CONSTRUCTOR. - worksheet = io_sheet. -endmethod. - - - - method GET_FILTER_AREA. - - validate_area( ). - - rs_area = filter_area. - -endmethod. - - - - method GET_FILTER_RANGE. - DATA: l_row_start_c TYPE string, - l_row_end_c TYPE string, - l_col_start_c TYPE string, - l_col_end_c TYPE string, - l_value TYPE string. - - validate_area( ). - - l_row_end_c = filter_area-row_end. - CONDENSE l_row_end_c NO-GAPS. - - l_row_start_c = filter_area-row_start. - CONDENSE l_row_start_c NO-GAPS. - - l_col_start_c = zcl_excel_common=>convert_column2alpha( ip_column = filter_area-col_start ) . - l_col_end_c = zcl_excel_common=>convert_column2alpha( ip_column = filter_area-col_end ) . - - CONCATENATE l_col_start_c l_row_start_c ':' l_col_end_c l_row_end_c INTO r_range. - -endmethod. - - - - method GET_FILTER_REFERENCE. - DATA: l_row_start_c TYPE string, - l_row_end_c TYPE string, - l_col_start_c TYPE string, - l_col_end_c TYPE string, - l_value TYPE string. - - validate_area( ). - - l_row_end_c = filter_area-row_end. - CONDENSE l_row_end_c NO-GAPS. - - l_row_start_c = filter_area-row_start. - CONDENSE l_row_start_c NO-GAPS. - - l_col_start_c = zcl_excel_common=>convert_column2alpha( ip_column = filter_area-col_start ) . - l_col_end_c = zcl_excel_common=>convert_column2alpha( ip_column = filter_area-col_end ) . - l_value = worksheet->get_title( ) . - - r_ref = zcl_excel_common=>escape_string( ip_value = l_value ). - - CONCATENATE r_ref '!$' l_col_start_c '$' l_row_start_c ':$' l_col_end_c '$' l_row_end_c INTO r_ref. - -endmethod. - - - - method GET_VALUES. - - rt_filter = values. - -endmethod. - - - - method SET_FILTER_AREA. - - filter_area = is_area. - -endmethod. - - - - - method SET_VALUE. - DATA: ls_values TYPE zexcel_s_autofilter_values. - -* Checks a re missing. - ls_values-column = i_column. - ls_values-value = i_value. - - INSERT ls_values INTO TABLE values. -* Now we need to be sure we don't get the same value again. - DELETE ADJACENT DUPLICATES FROM values COMPARING column value. - -endmethod. - - - - method SET_VALUES. - -* Checks are missing. - values = it_values. - DELETE ADJACENT DUPLICATES FROM values COMPARING column value. - -endmethod. - - - method VALIDATE_AREA. - DATA: l_col TYPE zexcel_cell_column, - l_row TYPE zexcel_cell_row. - - l_row = worksheet->get_highest_row( ) . - l_col = worksheet->get_highest_column( ) . - - IF filter_area IS INITIAL. - filter_area-row_start = 1. - filter_area-col_start = 1. - filter_area-row_end = l_row . - filter_area-col_end = l_col . - ENDIF. - - IF filter_area-row_start < 1. - filter_area-row_start = 1. - ENDIF. - IF filter_area-col_start < 1. - filter_area-col_start = 1. - ENDIF. - IF filter_area-row_end > l_row OR - filter_area-row_end < 1. - filter_area-row_end = l_row. - ENDIF. - IF filter_area-col_end > l_col OR - filter_area-col_end < 1. - filter_area-col_end = l_col. - ENDIF. - IF filter_area-row_start >= filter_area-row_end. - filter_area-row_start = filter_area-row_end - 1. - IF filter_area-row_start < 1. - filter_area-row_start = 1. - filter_area-row_end = 2. - ENDIF. - ENDIF. - IF filter_area-col_start > filter_area-col_end. - filter_area-col_start = filter_area-col_end. - ENDIF. -endmethod. - - - - *"* 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 -TYPES: BEGIN OF ts_objects, - sheet_guid TYPE uuid, - autofilter TYPE REF TO zcl_excel_autofilter, - END OF ts_objects, - - tt_objects TYPE HASHED TABLE OF ts_objects WITH UNIQUE KEY sheet_guid. - *"* use this source file for any macro definitions you need -*"* in the implementation part of the class - - ABAP - - - - - - METHOD add. - DATA: ls_autofilters TYPE ts_objects, - l_guid TYPE uuid. - l_guid = io_sheet->get_guid( ) . - READ TABLE autofilters INTO ls_autofilters WITH TABLE KEY sheet_guid = l_guid. - IF sy-subrc = 0. - ro_autofilter = ls_autofilters-autofilter. - ELSE. - CREATE OBJECT ro_autofilter - EXPORTING - io_sheet = io_sheet. - ls_autofilters-autofilter = ro_autofilter. - ls_autofilters-sheet_guid = l_guid. - INSERT ls_autofilters INTO TABLE autofilters . - ENDIF. -ENDMETHOD. - - - method CLEAR. - - REFRESH autofilters. - -endmethod. - - - - - method GET. - - DATA: ls_autofilters TYPE ts_objects. - - READ TABLE autofilters INTO ls_autofilters WITH TABLE KEY sheet_guid = i_sheet_guid. - IF sy-subrc = 0. - ro_autofilter = ls_autofilters-autofilter. - ELSE. - CLEAR ro_autofilter. - ENDIF. - -endmethod. - - - - method IS_EMPTY. - IF autofilters IS INITIAL. - r_empty = abap_true. - ENDIF. -endmethod. - - - - method REMOVE. - DATA: ls_autofilters TYPE ts_objects. - - DELETE autofilters WHERE sheet_guid = i_sheet_guid. - -endmethod. - - - - method SIZE. - DESCRIBE TABLE autofilters LINES r_size. -endmethod. - - - - - *"* 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 -TYPES: BEGIN OF ts_col_converter, - col TYPE lvc_col, - int TYPE lvc_int, - inv TYPE lvc_inv, - fontcolor TYPE zexcel_style_color_argb, - fillcolor TYPE zexcel_style_color_argb, - END OF ts_col_converter, - - tt_col_converter TYPE HASHED TABLE OF ts_col_converter WITH UNIQUE KEY col int inv. - *"* use this source file for any macro definitions you need -*"* in the implementation part of the class - - - ABAP - KKBLO - - - - - - - - - - METHOD apply_sort. - DATA: lt_otab TYPE abap_sortorder_tab, - ls_otab TYPE abap_sortorder. - - FIELD-SYMBOLS: <fs_table> TYPE STANDARD TABLE, - <fs_sort> TYPE lvc_s_sort. - - CREATE DATA eo_table LIKE it_table. - ASSIGN eo_table->* TO <fs_table>. - - <fs_table> = it_table. - - SORT wt_sort BY spos. - LOOP AT wt_sort ASSIGNING <fs_sort>. - IF <fs_sort>-up = abap_true. - ls_otab-name = <fs_sort>-fieldname. - ls_otab-descending = abap_false. -* ls_otab-astext = abap_true. " not only text fields - INSERT ls_otab INTO TABLE lt_otab. - ENDIF. - IF <fs_sort>-down = abap_true. - ls_otab-name = <fs_sort>-fieldname. - ls_otab-descending = abap_true. -* ls_otab-astext = abap_true. " not only text fields - INSERT ls_otab INTO TABLE lt_otab. - ENDIF. - ENDLOOP. - IF lt_otab IS NOT INITIAL. - SORT <fs_table> BY (lt_otab). - ENDIF. - -ENDMETHOD. - - - method CLASS_CONSTRUCTOR. -* let's fill the color conversion routines. - DATA: ls_color TYPE ts_col_converter. -* 0 all combination the same - ls_color-col = 0. - ls_color-int = 0. - ls_color-inv = 0. - ls_color-fontcolor = 'FF000000'. " 000 000 000 Black - ls_color-fillcolor = 'FFFFFFFF'. " 255 255 255 White - INSERT ls_color INTO TABLE wt_colors. - - ls_color-col = 0. - ls_color-int = 0. - ls_color-inv = 1. - ls_color-fontcolor = 'FF000000'. " 000 000 000 Black - ls_color-fillcolor = 'FFFFFFFF'. " 255 255 255 White - INSERT ls_color INTO TABLE wt_colors. - - ls_color-col = 0. - ls_color-int = 1. - ls_color-inv = 0. - ls_color-fontcolor = 'FF000000'. " 000 000 000 Black - ls_color-fillcolor = 'FFFFFFFF'. " 255 255 255 White - INSERT ls_color INTO TABLE wt_colors. - - ls_color-col = 0. - ls_color-int = 1. - ls_color-inv = 1. - ls_color-fontcolor = 'FF000000'. " 000 000 000 Black - ls_color-fillcolor = 'FFFFFFFF'. " 255 255 255 White - INSERT ls_color INTO TABLE wt_colors. - -* Blue - ls_color-col = 1. - ls_color-int = 0. - ls_color-inv = 0. - ls_color-fontcolor = 'FF000000'. " 000 000 000 Black - ls_color-fillcolor = 'FFB0E4FC'. " 176 228 252 blue - INSERT ls_color INTO TABLE wt_colors. - - ls_color-col = 1. - ls_color-int = 0. - ls_color-inv = 1. - ls_color-fontcolor = 'FFB0E4FC'. " 176 228 252 blue - ls_color-fillcolor = 'FFFFFFFF'. " 255 255 255 White - INSERT ls_color INTO TABLE wt_colors. - - ls_color-col = 1. - ls_color-int = 1. - ls_color-inv = 0. - ls_color-fontcolor = 'FF000000'. " 000 000 000 Black - ls_color-fillcolor = 'FF5FCBFE'. " 095 203 254 Int blue - INSERT ls_color INTO TABLE wt_colors. - - ls_color-col = 1. - ls_color-int = 1. - ls_color-inv = 1. - ls_color-fontcolor = 'FF5FCBFE'. " 095 203 254 - ls_color-fillcolor = 'FFFFFFFF'. " 255 255 255 - INSERT ls_color INTO TABLE wt_colors. - -* Gray - ls_color-col = 2. - ls_color-int = 0. - ls_color-inv = 0. - ls_color-fontcolor = 'FF000000'. - ls_color-fillcolor = 'FFE5EAF0'. " 229 234 240 gray - INSERT ls_color INTO TABLE wt_colors. - - ls_color-col = 2. - ls_color-int = 0. - ls_color-inv = 1. - ls_color-fontcolor = 'FFE5EAF0'. " 229 234 240 gray - ls_color-fillcolor = 'FFFFFFFF'. " 255 255 255 White - INSERT ls_color INTO TABLE wt_colors. - - ls_color-col = 2. - ls_color-int = 1. - ls_color-inv = 0. - ls_color-fontcolor = 'FF000000'. " 000 000 000 Black - ls_color-fillcolor = 'FFD8E8F4'. " 216 234 244 int gray - INSERT ls_color INTO TABLE wt_colors. - - ls_color-col = 2. - ls_color-int = 1. - ls_color-inv = 1. - ls_color-fontcolor = 'FFD8E8F4'. " 216 234 244 int gray - ls_color-fillcolor = 'FFFFFFFF'. " 255 255 255 White - INSERT ls_color INTO TABLE wt_colors. - -*Yellow - ls_color-col = 3. - ls_color-int = 0. - ls_color-inv = 0. - ls_color-fontcolor = 'FF000000'. " 000 000 000 Black - ls_color-fillcolor = 'FFFEFEB8'. " 254 254 184 yellow - INSERT ls_color INTO TABLE wt_colors. - - ls_color-col = 3. - ls_color-int = 0. - ls_color-inv = 1. - ls_color-fontcolor = 'FFFEFEB8'. " 254 254 184 yellow - ls_color-fillcolor = 'FFFFFFFF'. " 255 255 255 White - INSERT ls_color INTO TABLE wt_colors. - - ls_color-col = 3. - ls_color-int = 1. - ls_color-inv = 0. - ls_color-fontcolor = 'FF000000'. " 000 000 000 Black - ls_color-fillcolor = 'FFF9ED5D'. " 249 237 093 int yellow - INSERT ls_color INTO TABLE wt_colors. - - ls_color-col = 3. - ls_color-int = 1. - ls_color-inv = 1. - ls_color-fontcolor = 'FFF9ED5D'. " 249 237 093 int yellow - ls_color-fillcolor = 'FFFFFFFF'. " 255 255 255 White - INSERT ls_color INTO TABLE wt_colors. - -* light blue - ls_color-col = 4. - ls_color-int = 0. - ls_color-inv = 0. - ls_color-fontcolor = 'FF000000'. " 000 000 000 Black - ls_color-fillcolor = 'FFCEE7FB'. " 206 231 251 light blue - INSERT ls_color INTO TABLE wt_colors. - - ls_color-col = 4. - ls_color-int = 0. - ls_color-inv = 1. - ls_color-fontcolor = 'FFCEE7FB'. " 206 231 251 light blue - ls_color-fillcolor = 'FFFFFFFF'. " 255 255 255 White - INSERT ls_color INTO TABLE wt_colors. - - ls_color-col = 4. - ls_color-int = 1. - ls_color-inv = 0. - ls_color-fontcolor = 'FF000000'. " 000 000 000 Black - ls_color-fillcolor = 'FF9ACCEF'. " 154 204 239 int light blue - INSERT ls_color INTO TABLE wt_colors. - - ls_color-col = 4. - ls_color-int = 1. - ls_color-inv = 1. - ls_color-fontcolor = 'FF9ACCEF'. " 154 204 239 int light blue - ls_color-fillcolor = 'FFFFFFFF'. " 255 255 255 White - INSERT ls_color INTO TABLE wt_colors. - -* Green - ls_color-col = 5. - ls_color-int = 0. - ls_color-inv = 0. - ls_color-fontcolor = 'FF000000'. " 000 000 000 Black - ls_color-fillcolor = 'FFCEF8AE'. " 206 248 174 Green - INSERT ls_color INTO TABLE wt_colors. - - ls_color-col = 5. - ls_color-int = 0. - ls_color-inv = 1. - ls_color-fontcolor = 'FFCEF8AE'. " 206 248 174 Green - ls_color-fillcolor = 'FFFFFFFF'. " 255 255 255 White - INSERT ls_color INTO TABLE wt_colors. - - ls_color-col = 5. - ls_color-int = 1. - ls_color-inv = 0. - ls_color-fontcolor = 'FF000000'. " 000 000 000 Black - ls_color-fillcolor = 'FF7AC769'. " 122 199 105 int Green - INSERT ls_color INTO TABLE wt_colors. - - ls_color-col = 5. - ls_color-int = 1. - ls_color-inv = 1. - ls_color-fontcolor = 'FF7AC769'. " 122 199 105 int Green - ls_color-fillcolor = 'FFFFFFFF'. " 255 255 255 White - INSERT ls_color INTO TABLE wt_colors. - -* Red - ls_color-col = 6. - ls_color-int = 0. - ls_color-inv = 0. - ls_color-fontcolor = 'FF000000'. " 000 000 000 Black - ls_color-fillcolor = 'FFFDBBBC'. " 253 187 188 Red - INSERT ls_color INTO TABLE wt_colors. - - ls_color-col = 6. - ls_color-int = 0. - ls_color-inv = 1. - ls_color-fontcolor = 'FFFDBBBC'. " 253 187 188 Red - ls_color-fillcolor = 'FFFFFFFF'. " 255 255 255 White - INSERT ls_color INTO TABLE wt_colors. - - ls_color-col = 6. - ls_color-int = 1. - ls_color-inv = 0. - ls_color-fontcolor = 'FF000000'. " 000 000 000 Black - ls_color-fillcolor = 'FFFB6B6B'. " 251 107 107 int Red - INSERT ls_color INTO TABLE wt_colors. - - ls_color-col = 6. - ls_color-int = 1. - ls_color-inv = 1. - ls_color-fontcolor = 'FFFB6B6B'. " 251 107 107 int Red - ls_color-fillcolor = 'FFFFFFFF'. " 255 255 255 White - INSERT ls_color INTO TABLE wt_colors. - -endmethod. - - - - - METHOD get_color. - DATA: ls_con_col TYPE zexcel_s_converter_col, - ls_color TYPE ts_col_converter, - l_line TYPE i, - l_color(4) TYPE c. - FIELD-SYMBOLS: <fs_tab> TYPE STANDARD TABLE, - <fs_stab> TYPE ANY, - <fs> TYPE ANY, - <fs_tcol> TYPE lvc_t_scol, - <fs_scol> TYPE lvc_s_scol. - -* Loop trough the table to set the color properties of each line. The color properties field is -* Char 4 and the characters is set as follows: -* Char 1 = C = This is a color property -* Char 2 = 6 = Color code (1 - 7) -* Char 3 = Intensified on/of = 1 = on -* Char 4 = Inverse display = 0 = of - - ASSIGN io_table->* TO <fs_tab>. - - IF ws_layo-info_fname IS NOT INITIAL OR - ws_layo-ctab_fname IS NOT INITIAL. - LOOP AT <fs_tab> ASSIGNING <fs_stab>. - l_line = sy-tabix. - IF ws_layo-info_fname IS NOT INITIAL. - ASSIGN COMPONENT ws_layo-info_fname OF STRUCTURE <fs_stab> TO <fs>. - IF sy-subrc = 0. - IF <fs> IS NOT INITIAL. - l_color = <fs>. - IF l_color(1) = 'C'. - READ TABLE wt_colors INTO ls_color WITH TABLE KEY col = l_color+1(1) - int = l_color+2(1) - inv = l_color+3(1). - IF sy-subrc = 0. - ls_con_col-rownumber = l_line. - ls_con_col-columnname = space. - ls_con_col-fontcolor = ls_color-fontcolor. - ls_con_col-fillcolor = ls_color-fillcolor. - INSERT ls_con_col INTO TABLE et_colors. - ENDIF. - ENDIF. - ENDIF. - ENDIF. - ENDIF. - IF ws_layo-ctab_fname IS NOT INITIAL. - ASSIGN COMPONENT ws_layo-ctab_fname OF STRUCTURE <fs_stab> TO <fs_tcol>. - IF sy-subrc = 0. - LOOP AT <fs_tcol> ASSIGNING <fs_scol>. - READ TABLE wt_colors INTO ls_color WITH TABLE KEY col = <fs_scol>-color-col - int = <fs_scol>-color-int - inv = <fs_scol>-color-inv. - IF sy-subrc = 0. - ls_con_col-rownumber = l_line. - ls_con_col-columnname = <fs_scol>-fname. - ls_con_col-fontcolor = ls_color-fontcolor. - ls_con_col-fillcolor = ls_color-fillcolor. - ls_con_col-nokeycol = <fs_scol>-nokeycol. - INSERT ls_con_col INTO TABLE et_colors. - ENDIF. - ENDLOOP. - ENDIF. - ENDIF. - ENDLOOP. - ENDIF. -ENDMETHOD. - - - - - METHOD get_filter. - DATA: ls_filt TYPE lvc_s_filt, - l_line TYPE i, - ls_filter TYPE zexcel_s_converter_fil. - DATA: lo_addit TYPE REF TO cl_abap_elemdescr, - lt_components_tab TYPE cl_abap_structdescr=>component_table, - ls_components TYPE abap_componentdescr, - lo_table TYPE REF TO cl_abap_tabledescr, - lo_struc TYPE REF TO cl_abap_structdescr, - lo_trange TYPE REF TO data, - lo_srange TYPE REF TO data, - lo_ltabdata TYPE REF TO data. - - FIELD-SYMBOLS: <fs_tab> TYPE STANDARD TABLE, - <fs_ltab> TYPE STANDARD TABLE, - <fs_stab> TYPE ANY, - <fs> TYPE ANY, - <fs1> TYPE ANY, - <fs_srange> TYPE ANY, - <fs_trange> TYPE STANDARD TABLE. - - IF ws_option-filter = abap_false. - REFRESH et_filter. - RETURN. - ENDIF. - - ASSIGN xo_table->* TO <fs_tab>. - - CREATE DATA lo_ltabdata LIKE <fs_tab>. - ASSIGN lo_ltabdata->* TO <fs_ltab>. - - LOOP AT wt_filt INTO ls_filt. - LOOP AT <fs_tab> ASSIGNING <fs_stab>. - l_line = sy-tabix. - ASSIGN COMPONENT ls_filt-fieldname OF STRUCTURE <fs_stab> TO <fs>. - IF sy-subrc = 0. - IF l_line = 1. - REFRESH lt_components_tab. - ls_components-name = 'SIGN'. - lo_addit ?= cl_abap_typedescr=>describe_by_data( ls_filt-sign ). - ls_components-type = lo_addit . - INSERT ls_components INTO TABLE lt_components_tab. - ls_components-name = 'OPTION'. - lo_addit ?= cl_abap_typedescr=>describe_by_data( ls_filt-option ). - ls_components-type = lo_addit . - INSERT ls_components INTO TABLE lt_components_tab. - ls_components-name = 'LOW'. - lo_addit ?= cl_abap_typedescr=>describe_by_data( <fs> ). - ls_components-type = lo_addit . - INSERT ls_components INTO TABLE lt_components_tab. - ls_components-name = 'HIGH'. - lo_addit ?= cl_abap_typedescr=>describe_by_data( <fs> ). - ls_components-type = lo_addit . - INSERT ls_components INTO TABLE lt_components_tab. - "create new line type - TRY. - lo_struc = cl_abap_structdescr=>create( p_components = lt_components_tab - p_strict = abap_false ). - CATCH cx_sy_struct_creation. - CONTINUE. - ENDTRY. - lo_table = cl_abap_tabledescr=>create( lo_struc ). - - CREATE DATA lo_trange TYPE HANDLE lo_table. - CREATE DATA lo_srange TYPE HANDLE lo_struc. - - ASSIGN lo_trange->* TO <fs_trange>. - ASSIGN lo_srange->* TO <fs_srange>. - ENDIF. - REFRESH <fs_trange>. - ASSIGN COMPONENT 'SIGN' OF STRUCTURE <fs_srange> TO <fs1>. - <fs1> = ls_filt-sign. - ASSIGN COMPONENT 'OPTION' OF STRUCTURE <fs_srange> TO <fs1>. - <fs1> = ls_filt-option. - ASSIGN COMPONENT 'LOW' OF STRUCTURE <fs_srange> TO <fs1>. - <fs1> = ls_filt-low. - ASSIGN COMPONENT 'HIGH' OF STRUCTURE <fs_srange> TO <fs1>. - <fs1> = ls_filt-high. - INSERT <fs_srange> INTO TABLE <fs_trange>. - IF <fs> IN <fs_trange>. - IF ws_option-filter = abap_true. - ls_filter-rownumber = l_line. - ls_filter-columnname = ls_filt-fieldname. - INSERT ls_filter INTO TABLE et_filter. - ELSE. - INSERT <fs_stab> INTO TABLE <fs_ltab>. - ENDIF. - ENDIF. - ENDIF. - ENDLOOP. - IF ws_option-filter = abap_undefined. - <fs_tab> = <fs_ltab>. - REFRESH <fs_ltab>. - ENDIF. - ENDLOOP. - -ENDMETHOD. - - - - - METHOD update_catalog. - DATA: ls_fieldcatalog TYPE zexcel_s_converter_fcat, - ls_ref TYPE salv_s_ddic_reference, - ls_fcat TYPE lvc_s_fcat, - ls_sort TYPE lvc_s_sort, - l_decimals TYPE lvc_decmls. - - FIELD-SYMBOLS: <fs_scat> TYPE zexcel_s_converter_fcat. - - IF ws_layo-zebra IS NOT INITIAL. - cs_layout-is_stripped = abap_true. - ENDIF. - IF ws_layo-no_keyfix IS INITIAL OR - ws_layo-no_keyfix = '0'. - cs_layout-is_fixed = abap_true. - ENDIF. - - LOOP AT wt_fcat INTO ls_fcat. - CLEAR: ls_fieldcatalog, - l_decimals. - CASE ws_option-hidenc. - WHEN abap_false. " We make hiden columns visible - CLEAR ls_fcat-no_out. - WHEN abap_true. -* We convert column and hide it. - WHEN abap_undefined. "We don't convert hiden columns - IF ls_fcat-no_out = abap_true. - ls_fcat-tech = abap_true. - ENDIF. - ENDCASE. - IF ls_fcat-tech = abap_false. - ls_fieldcatalog-tabname = ls_fcat-tabname. - ls_fieldcatalog-fieldname = ls_fcat-fieldname . - ls_fieldcatalog-columnname = ls_fcat-fieldname . - ls_fieldcatalog-position = ls_fcat-col_pos. - ls_fieldcatalog-col_id = ls_fcat-col_id. - ls_fieldcatalog-convexit = ls_fcat-convexit. - ls_fieldcatalog-inttype = ls_fcat-inttype. - ls_fieldcatalog-scrtext_s = ls_fcat-scrtext_s . - ls_fieldcatalog-scrtext_m = ls_fcat-scrtext_m . - ls_fieldcatalog-scrtext_l = ls_fcat-scrtext_l. - l_decimals = ls_fcat-decimals_o. - IF l_decimals IS NOT INITIAL. - ls_fieldcatalog-decimals = l_decimals. - ELSE. - ls_fieldcatalog-decimals = ls_fcat-decimals . - ENDIF. - CASE ws_option-subtot. - WHEN abap_false. " We ignore subtotals - CLEAR ls_fcat-do_sum. - WHEN abap_true. " We convert subtotals and detail - - WHEN abap_undefined. " We should only take subtotals and displayed detail -* for now abap_true - ENDCASE. - CASE ls_fcat-do_sum. - WHEN abap_true. - ls_fieldcatalog-totals_function = zcl_excel_table=>totals_function_sum. - WHEN 'A'. - ls_fieldcatalog-totals_function = zcl_excel_table=>totals_function_min. - WHEN 'B' . - ls_fieldcatalog-totals_function = zcl_excel_table=>totals_function_max. - WHEN 'C' . - ls_fieldcatalog-totals_function = zcl_excel_table=>totals_function_average. - WHEN OTHERS. - CLEAR ls_fieldcatalog-totals_function . - ENDCASE. - ls_fieldcatalog-fix_column = ls_fcat-fix_column. - IF ws_layo-cwidth_opt IS INITIAL. - IF ls_fcat-col_opt IS NOT INITIAL. - ls_fieldcatalog-is_optimized = abap_true. - ENDIF. - ELSE. - ls_fieldcatalog-is_optimized = abap_true. - ENDIF. - IF ls_fcat-no_out IS NOT INITIAL. - ls_fieldcatalog-is_hidden = abap_true. - ls_fieldcatalog-position = ls_fieldcatalog-col_id. " We hide based on orginal data structure - ENDIF. -* Alignment in each cell - CASE ls_fcat-just. - WHEN 'R'. - ls_fieldcatalog-alignment = zcl_excel_style_alignment=>c_horizontal_right. - WHEN 'L'. - ls_fieldcatalog-alignment = zcl_excel_style_alignment=>c_horizontal_left. - WHEN 'C'. - ls_fieldcatalog-alignment = zcl_excel_style_alignment=>c_horizontal_center. - WHEN OTHERS. - CLEAR ls_fieldcatalog-alignment. - ENDCASE. -* Check for subtotals. - READ TABLE wt_sort INTO ls_sort WITH KEY fieldname = ls_fcat-fieldname. - IF sy-subrc = 0 AND ws_option-subtot <> abap_false. - ls_fieldcatalog-sort_level = 0 . -* IF ls_fieldcatalog-totals_function IS INITIAL. " Not clear why not -* CLEAR ls_fieldcatalog-is_subtotalled. -* ELSE. - ls_fieldcatalog-is_subtotalled = ls_sort-subtot. -* ENDIF. - ls_fieldcatalog-is_collapsed = ls_sort-expa. - IF ls_fieldcatalog-is_subtotalled = abap_true. - ls_fieldcatalog-sort_level = ls_sort-spos. - ls_fieldcatalog-totals_function = zcl_excel_table=>totals_function_sum. " we need function for text - ENDIF. - ENDIF. - APPEND ls_fieldcatalog TO ct_fieldcatalog. - ENDIF. - ENDLOOP. - - SORT ct_fieldcatalog BY sort_level ASCENDING. - cs_layout-max_subtotal_level = 0. - LOOP AT ct_fieldcatalog ASSIGNING <fs_scat> WHERE sort_level > 0. - cs_layout-max_subtotal_level = cs_layout-max_subtotal_level + 1. - <fs_scat>-sort_level = cs_layout-max_subtotal_level. - ENDLOOP. - -ENDMETHOD. - - - - *"* 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_CONVERTER~CAN_CONVERT_OBJECT. - - DATA: lo_result TYPE REF TO cl_salv_ex_result_data_table. - - TRY. - lo_result ?= io_object. - CATCH cx_sy_move_cast_error . - RAISE EXCEPTION TYPE zcx_excel. - ENDTRY. - -ENDMETHOD. - - - METHOD zif_excel_converter~create_fieldcatalog. - DATA: lo_result TYPE REF TO cl_salv_ex_result_data_table, - lo_ex_cm TYPE REF TO cl_salv_ex_cm, - lo_data TYPE REF TO data. - - FIELD-SYMBOLS: <fs_table> TYPE STANDARD TABLE. - - TRY. - zif_excel_converter~can_convert_object( io_object = io_object ). - ENDTRY. - - ws_option = is_option. - - lo_result ?= io_object. - - CLEAR: es_layout, - et_fieldcatalog. - - IF lo_result IS BOUND. - lo_data = get_table( io_object = lo_result->r_model->r_data ). - IF lo_data IS BOUND. - ASSIGN lo_data->* TO <fs_table> . - - lo_ex_cm ?= lo_result->r_model->r_model. - ws_layo = lo_ex_cm->s_layo. -* T_DRDN Instance Attribute Public Type LVC_T_DROP - wt_fcat = lo_ex_cm->t_fcat. - wt_filt = lo_ex_cm->t_filt. -* T_HYPE Instance Attribute Public Type LVC_T_HYPE -* T_SELECTED_CELLS Instance Attribute Public Type LVC_T_CELL -* T_SELECTED_COLUMNS Instance Attribute Public Type LVC_T_COL - wt_sort = lo_ex_cm->t_sort. - - apply_sort( EXPORTING it_table = <fs_table> - IMPORTING eo_table = eo_table ) . - - get_color( EXPORTING io_table = eo_table - IMPORTING et_colors = et_colors ) . - - get_filter( IMPORTING et_filter = et_filter - CHANGING xo_table = eo_table ) . - - update_catalog( CHANGING cs_layout = es_layout - ct_fieldcatalog = et_fieldcatalog ). - else. -* We have a problem and should stop here. - ENDIF. - ENDIF. -ENDMETHOD. - - - - *"* 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 GET_TABLE. - DATA: lo_object TYPE REF TO object, - ls_seoclass TYPE seoclass, - l_method TYPE string. - - SELECT SINGLE * INTO ls_seoclass - FROM seoclass - WHERE clsname = 'IF_SALV_BS_DATA_SOURCE'. - - IF sy-subrc = 0. - l_method = 'GET_TABLE_REF'. - lo_object ?= io_object. - CALL METHOD lo_object->(l_method) - RECEIVING - value = ro_data. - ELSE. - l_method = 'GET_REF_TO_TABLE'. - lo_object ?= io_object. - CALL METHOD lo_object->(l_method) - RECEIVING - value = ro_data. - ENDIF. - -endmethod. - - - - *"* 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_CONVERTER~CAN_CONVERT_OBJECT. - - DATA: lo_result TYPE REF TO cl_salv_wd_result_data_table. - - TRY. - lo_result ?= io_object. - CATCH cx_sy_move_cast_error . - RAISE EXCEPTION TYPE zcx_excel. - ENDTRY. - -ENDMETHOD. - - - METHOD zif_excel_converter~create_fieldcatalog. - DATA: lo_result TYPE REF TO cl_salv_wd_result_data_table, - lo_data TYPE REF TO data. - - FIELD-SYMBOLS: <fs_table> TYPE STANDARD TABLE. - - TRY. - zif_excel_converter~can_convert_object( io_object = io_object ). - ENDTRY. - - ws_option = is_option. - - lo_result ?= io_object. - - CLEAR: es_layout, - et_fieldcatalog. - - break rturnheim. - - IF lo_result IS BOUND. - lo_data = get_table( io_object = lo_result->r_model->r_data ). - IF lo_data IS BOUND. - ASSIGN lo_data->* TO <fs_table> . - - wo_config ?= lo_result->r_model->r_model. - - IF wo_config IS BOUND. - wt_fields = wo_config->if_salv_wd_field_settings~get_fields( ) . - wt_columns = wo_config->if_salv_wd_column_settings~get_columns( ) . - ENDIF. - - create_wt_fcat( io_table = lo_data ). - create_wt_sort( ). - create_wt_filt( ). - - apply_sort( EXPORTING it_table = <fs_table> - IMPORTING eo_table = eo_table ) . - -* get_color( EXPORTING io_table = eo_table -* IMPORTING et_colors = et_colors ) . - - get_filter( IMPORTING et_filter = et_filter - CHANGING xo_table = eo_table ) . - - update_catalog( CHANGING cs_layout = es_layout - ct_fieldcatalog = et_fieldcatalog ). - ELSE. -* We have a problem and should stop here - ENDIF. - ENDIF. -ENDMETHOD. - - - - METHOD create_wt_fcat. - DATA: lr_data TYPE REF TO data, - lo_structdescr TYPE REF TO cl_abap_structdescr, - lt_dfies TYPE ddfields, - ls_dfies TYPE dfies, - lv_sytabix TYPE sytabix. - - DATA: ls_fcat TYPE lvc_s_fcat. - - FIELD-SYMBOLS: <fs_tab> TYPE ANY TABLE. - - ASSIGN io_table->* TO <fs_tab> . - CREATE DATA lr_data LIKE LINE OF <fs_tab>. - - lo_structdescr ?= cl_abap_structdescr=>describe_by_data_ref( lr_data ). - - lt_dfies = zcl_excel_common=>describe_structure( io_struct = lo_structdescr ). - - loop at lt_dfies into ls_dfies. - MOVE-CORRESPONDING ls_dfies TO ls_fcat. -* ls_fcat-columnname = ls_dfies-fieldname. - ls_fcat-col_pos = ls_dfies-position. - ls_fcat-key = ls_dfies-keyflag. - get_fields_info( CHANGING xs_fcat = ls_fcat ) . - - ls_fcat-col_opt = abap_true. - - get_columns_info( CHANGING xs_fcat = ls_fcat ) . - - INSERT ls_fcat INTO TABLE wt_fcat. - endloop. - -ENDMETHOD. - - - METHOD create_wt_filt. -* No neeed for superclass. -* Only for WD - DATA: lt_otab TYPE abap_sortorder_tab, - ls_otab TYPE abap_sortorder. - DATA: lt_filters TYPE salv_wd_t_filter_rule_ref, - ls_filt TYPE lvc_s_filt. - - FIELD-SYMBOLS: <fs_fields> TYPE salv_wd_s_field_ref, - <fs_filter> TYPE salv_wd_s_filter_rule_ref. - - LOOP AT wt_fields ASSIGNING <fs_fields>. - REFRESH lt_filters. - lt_filters = <fs_fields>-r_field->if_salv_wd_filter~get_filter_rules( ) . - LOOP AT lt_filters ASSIGNING <fs_filter>. - ls_filt-fieldname = <fs_fields>-fieldname. - IF <fs_filter>-r_filter_rule->get_included( ) = abap_true. - ls_filt-sign = 'I'. - ELSE. - ls_filt-sign = 'E'. - ENDIF. - ls_filt-option = <fs_filter>-r_filter_rule->get_operator( ). - ls_filt-high = <fs_filter>-r_filter_rule->get_high_value( ) . - ls_filt-low = <fs_filter>-r_filter_rule->get_low_value( ) . - INSERT ls_filt INTO TABLE wt_filt. - ENDLOOP. - ENDLOOP. - -ENDMETHOD. - - - METHOD create_wt_sort. - DATA: lo_sort TYPE REF TO cl_salv_wd_sort_rule, - l_sort_order TYPE salv_wd_constant, - ls_sort TYPE lvc_s_sort. - - FIELD-SYMBOLS: <fs_fields> TYPE salv_wd_s_field_ref. - - LOOP AT wt_fields ASSIGNING <fs_fields>. - lo_sort = <fs_fields>-r_field->if_salv_wd_sort~get_sort_rule( ) . - IF lo_sort IS BOUND. - l_sort_order = lo_sort->get_sort_order( ). - IF l_sort_order <> if_salv_wd_c_sort=>sort_order. - CLEAR ls_sort. - ls_sort-spos = lo_sort->get_sort_position( ). - ls_sort-fieldname = <fs_fields>-fieldname. -* ls_sort-GROUP - ls_sort-subtot = lo_sort->get_group_aggregation( ). -* ls_sort-COMP -* ls_sort-EXPA -* ls_sort-SELTEXT -* ls_sort-OBLIGATORY -* ls_sort-LEVEL -* ls_sort-NO_OUT - IF l_sort_order = if_salv_wd_c_sort=>sort_order_ascending. - ls_sort-up = abap_true. - ELSE. - ls_sort-down = abap_true. - ENDIF. - INSERT ls_sort INTO TABLE wt_sort. - ENDIF. - ENDIF. - ENDLOOP. - -ENDMETHOD. - - - - METHOD get_columns_info. - DATA: l_numc2 TYPE salv_wd_constant. - - - FIELD-SYMBOLS: <fs_column> TYPE salv_wd_s_column_ref. - - READ TABLE wt_columns ASSIGNING <fs_column> WITH KEY id = xs_fcat-fieldname . - IF sy-subrc = 0. - xs_fcat-col_pos = <fs_column>-r_column->get_position( ) . - l_numc2 = <fs_column>-r_column->get_fixed_position( ). - IF l_numc2 = '02'. - xs_fcat-fix_column = abap_true . - ENDIF. - l_numc2 = <fs_column>-r_column->get_visible( ). - IF l_numc2 = '01'. - xs_fcat-no_out = abap_true . - ENDIF. - ENDIF. - -ENDMETHOD. - - - - METHOD get_fields_info. - DATA: lo_aggr TYPE REF TO cl_salv_wd_aggr_rule, - l_aggrtype TYPE salv_wd_constant. - - FIELD-SYMBOLS: <fs_fields> TYPE salv_wd_s_field_ref. - - READ TABLE wt_fields ASSIGNING <fs_fields> WITH KEY fieldname = xs_fcat-fieldname. - IF sy-subrc = 0. - lo_aggr = <fs_fields>-r_field->if_salv_wd_aggr~get_aggr_rule( ) . - IF lo_aggr IS BOUND. - l_aggrtype = lo_aggr->get_aggregation_type( ) . - CASE l_aggrtype. - WHEN if_salv_wd_c_aggregation=>aggrtype_total. - xs_fcat-do_sum = abap_true. - WHEN if_salv_wd_c_aggregation=>aggrtype_minimum. - xs_fcat-do_sum = 'A'. - WHEN if_salv_wd_c_aggregation=>aggrtype_maximum . - xs_fcat-do_sum = 'B'. - WHEN if_salv_wd_c_aggregation=>aggrtype_average . - xs_fcat-do_sum = 'C'. - WHEN OTHERS. - CLEAR xs_fcat-do_sum . - ENDCASE. - ENDIF. - ENDIF. - -ENDMETHOD. - - - - *"* use this source file for the definition and implementation of -*"* local helper classes, interface definitions and type -*"* declarations - *"* use this source file for any type of declarations (class -*"* definitions, interfaces or type declarations) you need for -*"* components in the private section - *"* use this source file for any macro definitions you need -*"* in the implementation part of the class - - - - - - - - method LOAD_VBAPROJECT. - - DATA lv_content TYPE xstring. - - lv_content = me->get_from_zip_archive( ip_path ). - - ip_excel->zif_excel_book_vba_project~set_vbaproject( lv_content ). - -endmethod. - - - method LOAD_WORKBOOK. - super->load_workbook( EXPORTING iv_workbook_full_filename = iv_workbook_full_filename - io_excel = io_excel ). - - CONSTANTS: lc_vba_project TYPE string VALUE 'http://schemas.microsoft.com/office/2006/relationships/vbaProject'. - - DATA: rels_workbook_path TYPE string, - rels_workbook TYPE REF TO if_ixml_document, - path TYPE string, - node TYPE REF TO if_ixml_element, - workbook TYPE REF TO if_ixml_document, - stripped_name TYPE chkfile, - dirname TYPE string, - relationship TYPE t_relationship, - fileversion TYPE t_fileversion, - workbookpr TYPE t_workbookpr. - - FIELD-SYMBOLS: <worksheet> TYPE t_relationship. - - CALL FUNCTION 'TRINT_SPLIT_FILE_AND_PATH' - EXPORTING - full_name = iv_workbook_full_filename - IMPORTING - stripped_name = stripped_name - file_path = dirname. - - " Read Workbook Relationships - CONCATENATE dirname '_rels/' stripped_name '.rels' - INTO rels_workbook_path. - - rels_workbook = me->get_ixml_from_zip_archive( rels_workbook_path ). - - node ?= rels_workbook->find_from_name( 'Relationship' ). - WHILE node IS BOUND. - me->fill_struct_from_attributes( EXPORTING ip_element = node CHANGING cp_structure = relationship ). - - CASE relationship-type. - WHEN lc_vba_project. - " Read VBA binary - CONCATENATE dirname relationship-target INTO path. - me->load_vbaproject( ip_path = path - ip_excel = io_excel ). - WHEN OTHERS. - ENDCASE. - - node ?= node->get_next( ). - ENDWHILE. - - " Read Workbook codeName - workbook = me->get_ixml_from_zip_archive( iv_workbook_full_filename ). - node ?= workbook->find_from_name( 'fileVersion' ). - IF node IS BOUND. - - fill_struct_from_attributes( EXPORTING ip_element = node - CHANGING cp_structure = fileversion ). - - io_excel->zif_excel_book_vba_project~set_codename( fileversion-codename ). - ENDIF. - - " Read Workbook codeName - workbook = me->get_ixml_from_zip_archive( iv_workbook_full_filename ). - node ?= workbook->find_from_name( 'workbookPr' ). - IF node IS BOUND. - - fill_struct_from_attributes( EXPORTING ip_element = node - CHANGING cp_structure = workbookpr ). - - io_excel->zif_excel_book_vba_project~set_codename_pr( workbookpr-codename ). - ENDIF. - -endmethod. - - - method LOAD_WORKSHEET. - - super->load_worksheet( EXPORTING ip_path = ip_path - io_worksheet = io_worksheet ). - - DATA: path TYPE string, - node TYPE REF TO if_ixml_element, - worksheet TYPE REF TO if_ixml_document, - sheetpr TYPE t_sheetpr. - - -* " Read Workbook codeName -* workbook = me->get_ixml_from_zip_archive( ip_path ). -* node ?= workbook->find_from_name( 'fileVersion' ). -* IF node IS BOUND. -* -* fill_struct_from_attributes( EXPORTING ip_element = node -* CHANGING cp_structure = fileversion ). -* -* IO_WORKSHEET->zif_excel_book_vba_project~set_codename( fileversion-codename ). -* ENDIF. - - " Read Workbook codeName - worksheet = me->get_ixml_from_zip_archive( ip_path ). - node ?= worksheet->find_from_name( 'sheetPr' ). - IF node IS BOUND. - - fill_struct_from_attributes( EXPORTING ip_element = node - CHANGING cp_structure = sheetpr ). - - io_worksheet->zif_excel_sheet_vba_project~set_codename_pr( sheetpr-codename ). - ENDIF. -endmethod. - - - - *"* use this source file for the definition and implementation of -*"* local helper classes, interface definitions and type -*"* declarations - *"* use this source file for any type of declarations (class -*"* definitions, interfaces or type declarations) you need for -*"* components in the private section - *"* use this source file for any macro definitions you need -*"* in the implementation part of the class - - - *"* use this source file for the definition and implementation of -*"* local helper classes, interface definitions and type -*"* declarations - *"* use this source file for any type of declarations (class -*"* definitions, interfaces or type declarations) you need for -*"* components in the private section - *"* use this source file for any macro definitions you need -*"* in the implementation part of the class - - ABAP - - - - method CONSTRUCTOR. - " default Excel palette based on - " http://msdn.microsoft.com/en-us/library/documentformat.openxml.spreadsheet.indexedcolors.aspx - - APPEND '00000000' TO colors. - APPEND '00FFFFFF' TO colors. - APPEND '00FF0000' TO colors. - APPEND '0000FF00' TO colors. - APPEND '000000FF' TO colors. - APPEND '00FFFF00' TO colors. - APPEND '00FF00FF' TO colors. - APPEND '0000FFFF' TO colors. - APPEND '00000000' TO colors. - APPEND '00FFFFFF' TO colors. - - APPEND '00FF0000' TO colors. - APPEND '0000FF00' TO colors. - APPEND '000000FF' TO colors. - APPEND '00FFFF00' TO colors. - APPEND '00FF00FF' TO colors. - APPEND '0000FFFF' TO colors. - APPEND '00800000' TO colors. - APPEND '00008000' TO colors. - APPEND '00000080' TO colors. - APPEND '00808000' TO colors. - - APPEND '00800080' TO colors. - APPEND '00008080' TO colors. - APPEND '00C0C0C0' TO colors. - APPEND '00808080' TO colors. - APPEND '009999FF' TO colors. - APPEND '00993366' TO colors. - APPEND '00FFFFCC' TO colors. - APPEND '00CCFFFF' TO colors. - APPEND '00660066' TO colors. - APPEND '00FF8080' TO colors. - - APPEND '000066CC' TO colors. - APPEND '00CCCCFF' TO colors. - APPEND '00000080' TO colors. - APPEND '00FF00FF' TO colors. - APPEND '00FFFF00' TO colors. - APPEND '0000FFFF' TO colors. - APPEND '00800080' TO colors. - APPEND '00800000' TO colors. - APPEND '00008080' TO colors. - APPEND '000000FF' TO colors. - - APPEND '0000CCFF' TO colors. - APPEND '00CCFFFF' TO colors. - APPEND '00CCFFCC' TO colors. - APPEND '00FFFF99' TO colors. - APPEND '0099CCFF' TO colors. - APPEND '00FF99CC' TO colors. - APPEND '00CC99FF' TO colors. - APPEND '00FFCC99' TO colors. - APPEND '003366FF' TO colors. - APPEND '0033CCCC' TO colors. - - APPEND '0099CC00' TO colors. - APPEND '00FFCC00' TO colors. - APPEND '00FF9900' TO colors. - APPEND '00FF6600' TO colors. - APPEND '00666699' TO colors. - APPEND '00969696' TO colors. - APPEND '00003366' TO colors. - APPEND '00339966' TO colors. - APPEND '00003300' TO colors. - APPEND '00333300' TO colors. - - APPEND '00993300' TO colors. - APPEND '00993366' TO colors. - APPEND '00333399' TO colors. - APPEND '00333333' TO colors. - -endmethod. - - - - - - method GET_COLOR. - DATA: lv_index type i. - - lv_index = ip_index + 1. - READ TABLE colors INTO ep_color INDEX lv_index. - IF sy-subrc <> 0. - RAISE EXCEPTION TYPE zcx_excel - EXPORTING - error = 'Invalid color index'. - ENDIF. -endmethod. - - - - method GET_COLORS. - ep_colors = colors. -endmethod. - - - - method IS_MODIFIED. - ep_modified = modified. -endmethod. - - - - - method SET_COLOR. - DATA: lv_index TYPE i. - - FIELD-SYMBOLS: <lv_color> LIKE LINE OF colors. - - lv_index = ip_index + 1. - READ TABLE colors ASSIGNING <lv_color> INDEX lv_index. - IF sy-subrc <> 0. - RAISE EXCEPTION TYPE zcx_excel - EXPORTING - error = 'Invalid color index'. - ENDIF. - - IF <lv_color> <> ip_color. - modified = abap_true. - <lv_color> = ip_color. - ENDIF. - -endmethod. - - - - - *"* use this source file for the definition and implementation of -*"* local helper classes, interface definitions and type -*"* declarations - *"* use this source file for any type of declarations (class -*"* definitions, interfaces or type declarations) you need for -*"* components in the private section - *"* use this source file for any macro definitions you need -*"* in the implementation part of the class - - - *"* 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 if_message~get_longtext. - - IF me->error IS NOT INITIAL - OR me->syst_at_raise IS NOT INITIAL. -*--------------------------------------------------------------------* -* If message was supplied explicitly use this as longtext as well -*--------------------------------------------------------------------* - result = me->get_text( ). - ELSE. -*--------------------------------------------------------------------* -* otherwise use standard method to derive text -*--------------------------------------------------------------------* - super->if_message~get_longtext( EXPORTING - preserve_newlines = preserve_newlines - RECEIVING - result = result ). - ENDIF. -ENDMETHOD. - - - METHOD if_message~get_text. - - IF me->error IS NOT INITIAL. -*--------------------------------------------------------------------* -* If message was supplied explicitly use this -*--------------------------------------------------------------------* - result = me->error . - ELSEIF me->syst_at_raise IS NOT INITIAL. -*--------------------------------------------------------------------* -* If message was supplied by syst create messagetext now -*--------------------------------------------------------------------* - MESSAGE ID syst_at_raise-msgid TYPE syst_at_raise-msgty NUMBER syst_at_raise-msgno - WITH syst_at_raise-msgv1 syst_at_raise-msgv2 syst_at_raise-msgv3 syst_at_raise-msgv4 - INTO result. - ELSE. -*--------------------------------------------------------------------* -* otherwise use standard method to derive text -*--------------------------------------------------------------------* - CALL METHOD super->if_message~get_text - RECEIVING - result = result. - ENDIF. -ENDMETHOD. - - - - *"* 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 CONSTRUCTOR. -endmethod. - - - - method GET_STRUCTURE. -*initialize colors to 'not set' - es_fill-left_color-indexed = zcl_excel_style_color=>c_indexed_not_set. - es_fill-left_color-theme = zcl_excel_style_color=>c_theme_not_set. - es_fill-right_color-indexed = zcl_excel_style_color=>c_indexed_not_set. - es_fill-right_color-theme = zcl_excel_style_color=>c_theme_not_set. - es_fill-top_color-indexed = zcl_excel_style_color=>c_indexed_not_set. - es_fill-top_color-theme = zcl_excel_style_color=>c_theme_not_set. - es_fill-bottom_color-indexed = zcl_excel_style_color=>c_indexed_not_set. - es_fill-bottom_color-theme = zcl_excel_style_color=>c_theme_not_set. - es_fill-diagonal_color-indexed = zcl_excel_style_color=>c_indexed_not_set. - es_fill-diagonal_color-theme = zcl_excel_style_color=>c_theme_not_set. - -* Check if all borders is set otherwise check single border - IF me->allborders IS BOUND. - es_fill-left_color = me->allborders->border_color. - es_fill-left_style = me->allborders->border_style. - es_fill-right_color = me->allborders->border_color. - es_fill-right_style = me->allborders->border_style. - es_fill-top_color = me->allborders->border_color. - es_fill-top_style = me->allborders->border_style. - es_fill-bottom_color = me->allborders->border_color. - es_fill-bottom_style = me->allborders->border_style. - ELSE. - IF me->left IS BOUND. - es_fill-left_color = me->left->border_color. - es_fill-left_style = me->left->border_style. - ENDIF. - IF me->right IS BOUND. - es_fill-right_color = me->right->border_color. - es_fill-right_style = me->right->border_style. - ENDIF. - IF me->top IS BOUND. - es_fill-top_color = me->top->border_color. - es_fill-top_style = me->top->border_style. - ENDIF. - IF me->down IS BOUND. - es_fill-bottom_color = me->down->border_color. - es_fill-bottom_style = me->down->border_style. - ENDIF. - ENDIF. - -* Check if diagonal is set - IF me->diagonal IS BOUND. - es_fill-diagonal_color = me->diagonal->border_color. - es_fill-diagonal_style = me->diagonal->border_style. - CASE me->diagonal_mode. - WHEN 1. - es_fill-diagonalup = 1. - es_fill-diagonaldown = 0. - WHEN 2. - es_fill-diagonalup = 0. - es_fill-diagonaldown = 1. - WHEN 3. - es_fill-diagonalup = 1. - es_fill-diagonaldown = 1. - WHEN OTHERS. - es_fill-diagonalup = 0. - es_fill-diagonaldown = 0. - ENDCASE. - ENDIF. - -endmethod. - - - - *"* 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 CONSTRUCTOR. - - -endmethod. - - - - - - - method CREATE_NEW_ARGB. - - - CONCATENATE zcl_excel_style_color=>c_alpha ip_red ip_green ip_blu INTO ep_color_argb. - -endmethod. - - - - *"* 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 CONSTRUCTOR. - - DATA: ls_iconset TYPE zexcel_conditional_iconset. - ls_iconset-iconset = zcl_excel_style_conditional=>c_iconset_3trafficlights. - ls_iconset-cfvo1_type = zcl_excel_style_conditional=>c_cfvo_type_percent. - ls_iconset-cfvo1_value = '0'. - ls_iconset-cfvo2_type = zcl_excel_style_conditional=>c_cfvo_type_percent. - ls_iconset-cfvo2_value = '20'. - ls_iconset-cfvo3_type = zcl_excel_style_conditional=>c_cfvo_type_percent. - ls_iconset-cfvo3_value = '40'. - ls_iconset-cfvo4_type = zcl_excel_style_conditional=>c_cfvo_type_percent. - ls_iconset-cfvo4_value = '60'. - ls_iconset-cfvo5_type = zcl_excel_style_conditional=>c_cfvo_type_percent. - ls_iconset-cfvo5_value = '80'. - - - me->rule = zcl_excel_style_conditional=>c_rule_none. -* me->iconset->operator = zcl_excel_style_conditional=>c_operator_none. - me->mode_iconset = ls_iconset. - me->priority = 1. - -* inizialize dimension range - me->stop_cell-cell_row = 1. - me->stop_cell-cell_column = 1. - me->start_cell-cell_row = 1. - me->start_cell-cell_column = 1. -endmethod. - - - - method GET_DIMENSION_RANGE. - IF stop_cell EQ start_cell. "only one cell - ep_dimension_range = start_cell-cell_coords. - ELSE. - CONCATENATE start_cell-cell_coords ':' stop_cell-cell_coords INTO ep_dimension_range. - ENDIF. -endmethod. - - - - - - - method SET_RANGE. - DATA: lv_column TYPE zexcel_cell_column, - lv_row_alpha TYPE string. - - lv_column = zcl_excel_common=>convert_column2int( ip_stop_column ). - stop_cell-cell_row = 1. - stop_cell-cell_column = lv_column. - lv_row_alpha = ip_stop_row. - SHIFT lv_row_alpha RIGHT DELETING TRAILING space. - SHIFT lv_row_alpha LEFT DELETING LEADING space. - CONCATENATE ip_stop_column lv_row_alpha INTO stop_cell-cell_coords. - - lv_column = zcl_excel_common=>convert_column2int( ip_start_column ). - start_cell-cell_row = 1. - start_cell-cell_column = lv_column. - lv_row_alpha = ip_start_row. - SHIFT lv_row_alpha RIGHT DELETING TRAILING space. - SHIFT lv_row_alpha LEFT DELETING LEADING space. - CONCATENATE ip_start_column lv_row_alpha INTO start_cell-cell_coords. -endmethod. - - - - *"* 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 CONSTRUCTOR. - filltype = zcl_excel_style_fill=>c_fill_none. - fgcolor-theme = zcl_excel_style_color=>c_theme_not_set. - fgcolor-indexed = zcl_excel_style_color=>c_indexed_not_set. - bgcolor-theme = zcl_excel_style_color=>c_theme_not_set. - bgcolor-indexed = zcl_excel_style_color=>c_indexed_sys_foreground. - rotation = 0. -endmethod. - - - - method GET_STRUCTURE. - es_fill-rotation = me->rotation. - es_fill-filltype = me->filltype. - es_fill-fgColor = me->fgColor. - es_fill-bgColor = me->bgColor. -endmethod. - - - - *"* 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 - - ABAP - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - method CALCULATE_TEXT_WIDTH. - " Addition to solve issue #120, contribution by Stefan Schmöcker - r_width = strlen( i_text ). - " use scale factor based on default 11 - " ( don't know where defaultsetting is stored currently ) - r_width = r_width * me->size / 11. -endmethod. - - - method CONSTRUCTOR. - me->color-rgb = zcl_excel_style_color=>c_black. - me->color-theme = zcl_excel_style_color=>c_theme_not_set. - me->color-indexed = zcl_excel_style_color=>c_indexed_not_set. - me->scheme = zcl_excel_style_font=>c_scheme_minor. - me->underline_mode = zcl_excel_style_font=>c_underline_single. -endmethod. - - - - method GET_STRUCTURE. - - es_font-bold = me->bold. - es_font-italic = me->italic. - es_font-underline = me->underline. - es_font-underline_mode = me->underline_mode. - es_font-strikethrough = me->strikethrough. - es_font-size = me->size. - es_font-color = me->color. - es_font-name = me->name. - es_font-family = me->family. - es_font-scheme = me->scheme. - -endmethod. - - - - *"* 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 CONSTRUCTOR. - format_code = me->c_format_general. -endmethod. - - - - method GET_STRUCTURE. - ep_number_format-numfmt = me->format_code. -endmethod. - - - - *"* 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 CONSTRUCTOR. - locked = me->c_protection_locked. - hidden = me->c_protection_unhidden. -endmethod. - - - - method GET_STRUCTURE. - ep_protection-locked = me->locked. - ep_protection-hidden = me->hidden. -endmethod. - - - - *"* 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 - - ABAP - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - method CONSTRUCTOR. - -endmethod. - - - - METHOD get_bottom_row_integer. - DATA: lv_table_lines TYPE i. - FIELD-SYMBOLS: <fs_table> TYPE STANDARD TABLE. - - IF settings-bottom_right_row IS NOT INITIAL. -* ev_row = zcl_excel_common=>convert_column2int( settings-bottom_right_row ). " del issue #246 - ev_row = settings-bottom_right_row . " ins issue #246 - EXIT. - ENDIF. - - ASSIGN table_data->* TO <fs_table>. - DESCRIBE TABLE <fs_table> LINES lv_table_lines. - IF lv_table_lines = 0. - lv_table_lines = 1. "table needs at least 1 data row - ENDIF. - - ev_row = settings-top_left_row + lv_table_lines. - - IF me->has_totals( ) = abap_true." ???? AND ip_include_totals_row = abap_true. - ADD 1 TO ev_row. - ENDIF. -ENDMETHOD. - - - - method GET_ID. - ov_id = id. -endmethod. - - - - method GET_NAME. - - IF me->name IS INITIAL. - me->name = zcl_excel_common=>number_to_excel_string( ip_value = me->id ). - CONCATENATE 'table' me->name INTO me->name. - ENDIF. - - ov_name = me->name. -endmethod. - - - - - method GET_REFERENCE. - DATA: lv_column TYPE zexcel_cell_column, - lv_table_lines TYPE i, - lv_right_column TYPE zexcel_cell_column_alpha, - ls_field_catalog TYPE zexcel_s_fieldcatalog, - lv_bottom_row TYPE zexcel_cell_row, - lv_top_row_string(10) TYPE c, - lv_bottom_row_string(10) TYPE c. - - FIELD-SYMBOLS: <fs_table> TYPE STANDARD TABLE. - -*column - lv_column = zcl_excel_common=>convert_column2int( settings-top_left_column ). - lv_table_lines = 0. - LOOP AT fieldcat INTO ls_field_catalog WHERE dynpfld EQ abap_true. - ADD 1 TO lv_table_lines. - ENDLOOP. - lv_column = lv_column + lv_table_lines - 1. - lv_right_column = zcl_excel_common=>convert_column2alpha( lv_column ). - -*row - ASSIGN table_data->* TO <fs_table>. - DESCRIBE TABLE <fs_table> LINES lv_table_lines. - IF lv_table_lines = 0. - lv_table_lines = 1. "table needs at least 1 data row - ENDIF. - lv_bottom_row = settings-top_left_row + lv_table_lines . - - IF me->has_totals( ) = abap_true AND ip_include_totals_row = abap_true. - ADD 1 TO lv_bottom_row. - ENDIF. - - lv_top_row_string = zcl_excel_common=>number_to_excel_string( settings-top_left_row ). - lv_bottom_row_string = zcl_excel_common=>number_to_excel_string( lv_bottom_row ). - - CONCATENATE settings-top_left_column lv_top_row_string - ':' - lv_right_column lv_bottom_row_string INTO ov_reference. - -endmethod. - - - - - METHOD get_right_column_integer. - DATA: lv_column TYPE zexcel_cell_column, - lv_table_lines TYPE i, - ls_field_catalog TYPE zexcel_s_fieldcatalog. - - IF settings-bottom_right_column IS NOT INITIAL. - ev_column = zcl_excel_common=>convert_column2int( settings-bottom_right_column ). - EXIT. - ENDIF. - - ev_column = zcl_excel_common=>convert_column2int( settings-top_left_column ). - LOOP AT fieldcat INTO ls_field_catalog WHERE dynpfld EQ abap_true. - ADD 1 TO ev_column. - ENDLOOP. - -ENDMETHOD. - - - - - - method GET_TOTALS_FORMULA. - CONSTANTS: lc_function_id_sum TYPE string VALUE '109', - lc_function_id_min TYPE string VALUE '105', - lc_function_id_max TYPE string VALUE '104', - lc_function_id_count TYPE string VALUE '103', - lc_function_id_average TYPE string VALUE '101'. - - DATA: lv_function_id TYPE string. - - CASE ip_function. - WHEN zcl_excel_table=>totals_function_sum. - lv_function_id = lc_function_id_sum. - - WHEN zcl_excel_table=>totals_function_min. - lv_function_id = lc_function_id_min. - - WHEN zcl_excel_table=>totals_function_max. - lv_function_id = lc_function_id_max. - - WHEN zcl_excel_table=>totals_function_count. - lv_function_id = lc_function_id_count. - - WHEN zcl_excel_table=>totals_function_average. - lv_function_id = lc_function_id_average. - - WHEN zcl_excel_table=>totals_function_custom. " issue #292 - RETURN. - - WHEN OTHERS. - RAISE EXCEPTION TYPE zcx_excel - EXPORTING - error = 'Invalid totals formula. See ZCL_ for possible values'. - ENDCASE. - - CONCATENATE 'SUBTOTAL(' lv_function_id ',[' ip_column '])' INTO ep_formula. -endmethod. - - - - method HAS_TOTALS. - DATA: ls_field_catalog TYPE zexcel_s_fieldcatalog. - - ep_result = abap_false. - - LOOP AT fieldcat INTO ls_field_catalog. - IF ls_field_catalog-totals_function IS NOT INITIAL. - ep_result = abap_true. - EXIT. - ENDIF. - ENDLOOP. - -endmethod. - - - - method SET_DATA. - GET REFERENCE OF ir_data INTO me->table_data. -endmethod. - - - - method SET_ID. - id = iv_id. -endmethod. - - - - - - - - *"* local class implementation for public class -*"* use this source file for the implementation part of -*"* local helper classes - -*&---------------------------------------------------------------------* -*& Class (Implementation) C_OI_PROXY_ERROR -*&---------------------------------------------------------------------* -CLASS c_oi_proxy_error IMPLEMENTATION. - METHOD constructor. -* IMPORTING object_name TYPE c -* method_name TYPE c. - error_nr = ret_call_not_flushed. - me->i_oi_error~error_code = c_oi_errors=>ret_call_not_flushed. - me->i_oi_error~is_flushed = ' '. - me->i_oi_error~has_failed = 'X'. - me->i_oi_error~has_succeeded = ' '. - me->message_id = 'SOFFICEINTEGRATION'. - me->message_nr = '899'. - me->param1 = object_name. - me->param2 = method_name. - ENDMETHOD. "constructor - - METHOD i_oi_error~flush_error. - IF error_nr EQ 0. - me->i_oi_error~error_code = c_oi_errors=>ret_ok. - me->i_oi_error~is_flushed = 'X'. - me->i_oi_error~has_failed = ' '. - me->i_oi_error~has_succeeded = 'X'. - me->message_id = ''. - me->message_nr = '000'. - CALL METHOD c_oi_errors=>translate_proxy_error_code - EXPORTING - errorcode = error_nr - IMPORTING - retcode = me->i_oi_error~error_code. - ELSEIF error_nr EQ ret_call_not_flushed. - "call still not flushed - CALL METHOD c_oi_errors=>translate_proxy_error_code - EXPORTING - errorcode = error_nr - errorstring = me->param2 "method name - objectname = me->param1 - IMPORTING - retcode = me->i_oi_error~error_code. - ELSE. - me->i_oi_error~is_flushed = 'X'. - me->i_oi_error~has_succeeded = ' '. - me->i_oi_error~has_failed = 'X'. - CALL METHOD c_oi_errors=>translate_proxy_error_code - EXPORTING - errorcode = error_nr - errorstring = error_string - IMPORTING - retcode = me->i_oi_error~error_code. - CALL METHOD c_oi_errors=>get_message - IMPORTING - message_id = me->message_id - message_number = me->message_nr - param1 = me->param1 - param2 = me->param2 - param3 = me->param3 - param4 = me->param4. - ENDIF. - ENDMETHOD. "i_oi_error~flush_error - - METHOD i_oi_error~raise_message. -* IMPORTING type TYPE c. -* EXCEPTIONS message_raised flush_failed. - IF me->i_oi_error~has_succeeded IS INITIAL. - IF NOT me->i_oi_error~is_flushed IS INITIAL. - MESSAGE ID message_id TYPE type - NUMBER message_nr WITH param1 param2 param3 param4 - RAISING message_raised. - ELSE. - RAISE flush_failed. - ENDIF. - ENDIF. - ENDMETHOD. "i_oi_error~raise_message - - METHOD i_oi_error~get_message. -* EXPORTING message_id TYPE c -* message_number TYPE c -* param1 TYPE c -* param2 TYPE c -* param3 TYPE c -* param4 TYPE c. - param1 = me->param1. param2 = me->param2. - param3 = me->param3. param4 = me->param4. - - message_id = me->message_id. - message_number = me->message_nr. - ENDMETHOD. "i_oi_error~get_message -ENDCLASS. "C_OI_PROXY_ERROR - -*&---------------------------------------------------------------------* -*& Class (Implementation) CL_GRID_ACCESSION -*&---------------------------------------------------------------------* -CLASS lcl_gui_alv_grid IMPLEMENTATION. - - METHOD get_alv_attributes. - CREATE DATA et_table LIKE io_grid->mt_outtab. - et_table = io_grid->mt_outtab. - ENDMETHOD. "get_data - -ENDCLASS. "CL_GRID_ACCESSION - *"* use this source file for any type declarations (class -*"* definitions, interfaces or data types) you need for method -*"* implementation or private method's signature -TYPE-POOLS: sydes. -TYPE-POOLS: slis. -*--------------------------------------------------------------------* -* CLASS c_oi_proxy_error -*--------------------------------------------------------------------* -* use for method bind_ALV -*--------------------------------------------------------------------* -CLASS c_oi_proxy_error DEFINITION. - PUBLIC SECTION. - INTERFACES: i_oi_error. - DATA: error_nr TYPE i. - DATA: error_string TYPE sy-msgv1. - - METHODS: constructor IMPORTING object_name TYPE c - method_name TYPE c. - PRIVATE SECTION. - CONSTANTS: - ret_call_not_flushed TYPE i VALUE -999999. - - DATA: message_id TYPE sy-msgid, - message_nr TYPE sy-msgno, - param1 TYPE sy-msgv1, - param2 TYPE sy-msgv2, - param3 TYPE sy-msgv3, - param4 TYPE sy-msgv4. -ENDCLASS. "c_oi_proxy_error DEFINITION - -*--------------------------------------------------------------------* -* CLASS lcl_gui_alv_grid -*--------------------------------------------------------------------* -* to get protected attribute and method of cl_gui_alv_grid -* use for method bind_ALV -*--------------------------------------------------------------------* -CLASS lcl_gui_alv_grid DEFINITION INHERITING FROM cl_gui_alv_grid. - - PUBLIC SECTION. -* get ALV grid data - METHODS: get_alv_attributes - IMPORTING - io_grid TYPE REF TO cl_gui_alv_grid " ALV grid - EXPORTING - et_table TYPE REF TO data. " dta table - -ENDCLASS. "lcl_gui_alv_grid DEFINITION - *"* use this source file for any macro definitions you need -*"* in the implementation part of the class - - - - - - - - - - - - - - - - - - - - ABAP - SLIS - SOI - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - METHOD zif_excel_sheet_printsettings~clear_print_repeat_columns. - -*--------------------------------------------------------------------* -* adjust internal representation -*--------------------------------------------------------------------* - CLEAR: me->print_title_col_from, - me->print_title_col_to . - - -*--------------------------------------------------------------------* -* adjust corresponding range -*--------------------------------------------------------------------* - me->print_title_set_range( ). - - -ENDMETHOD. - - - METHOD zif_excel_sheet_printsettings~clear_print_repeat_rows. - -*--------------------------------------------------------------------* -* adjust internal representation -*--------------------------------------------------------------------* - CLEAR: me->print_title_row_from, - me->print_title_row_to . - - -*--------------------------------------------------------------------* -* adjust corresponding range -*--------------------------------------------------------------------* - me->print_title_set_range( ). - - -ENDMETHOD. - - - METHOD zif_excel_sheet_printsettings~get_print_repeat_columns. - ev_columns_from = me->print_title_col_from. - ev_columns_to = me->print_title_col_to. -ENDMETHOD. - - - METHOD zif_excel_sheet_printsettings~get_print_repeat_rows. - ev_rows_from = me->print_title_row_from. - ev_rows_to = me->print_title_row_to. -ENDMETHOD. - - - METHOD zif_excel_sheet_printsettings~set_print_repeat_columns. -*--------------------------------------------------------------------* -* issue#235 - repeat rows/columns -* - Stefan Schmöcker, 2012-12-02 -*--------------------------------------------------------------------* - - DATA: lv_col_from_int TYPE i, - lv_col_to_int TYPE i, - lv_errormessage TYPE string. - - DATA: lo_range_iterator TYPE REF TO cl_object_collection_iterator, - lo_range TYPE REF TO zcl_excel_range. - - - lv_col_from_int = zcl_excel_common=>convert_column2int( iv_columns_from ). - lv_col_to_int = zcl_excel_common=>convert_column2int( iv_columns_to ). - -*--------------------------------------------------------------------* -* Check if valid range is supplied -*--------------------------------------------------------------------* - IF lv_col_from_int < 1. - lv_errormessage = 'Invalid range supplied for print-title repeatable columns'(401). - RAISE EXCEPTION TYPE zcx_excel - EXPORTING - error = lv_errormessage. - ENDIF. - - IF lv_col_from_int > lv_col_to_int. - lv_errormessage = 'Invalid range supplied for print-title repeatable columns'(401). - RAISE EXCEPTION TYPE zcx_excel - EXPORTING - error = lv_errormessage. - ENDIF. - -*--------------------------------------------------------------------* -* adjust internal representation -*--------------------------------------------------------------------* - me->print_title_col_from = iv_columns_from. - me->print_title_col_to = iv_columns_to. - - -*--------------------------------------------------------------------* -* adjust corresponding range -*--------------------------------------------------------------------* - me->print_title_set_range( ). - -ENDMETHOD. - - - METHOD zif_excel_sheet_printsettings~set_print_repeat_rows. -*--------------------------------------------------------------------* -* issue#235 - repeat rows/columns -* - Stefan Schmöcker, 2012-12-02 -*--------------------------------------------------------------------* - - DATA: lv_errormessage TYPE string. - - DATA: lo_range_iterator TYPE REF TO cl_object_collection_iterator, - lo_range TYPE REF TO zcl_excel_range. - - - -*--------------------------------------------------------------------* -* Check if valid range is supplied -*--------------------------------------------------------------------* - IF iv_rows_from < 1. - lv_errormessage = 'Invalid range supplied for print-title repeatable rowumns'(401). - RAISE EXCEPTION TYPE zcx_excel - EXPORTING - error = lv_errormessage. - ENDIF. - - IF iv_rows_from > iv_rows_to. - lv_errormessage = 'Invalid range supplied for print-title repeatable rowumns'(401). - RAISE EXCEPTION TYPE zcx_excel - EXPORTING - error = lv_errormessage. - ENDIF. - -*--------------------------------------------------------------------* -* adjust internal representation -*--------------------------------------------------------------------* - me->print_title_row_from = iv_rows_from. - me->print_title_row_to = iv_rows_to. - - -*--------------------------------------------------------------------* -* adjust corresponding range -*--------------------------------------------------------------------* - me->print_title_set_range( ). - - -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. - - zif_excel_sheet_properties~show_zeros = zif_excel_sheet_properties=>c_showzero. - zif_excel_sheet_properties~summarybelow = zif_excel_sheet_properties=>c_below_on. - zif_excel_sheet_properties~summaryright = zif_excel_sheet_properties=>c_right_on. - -* inizialize zoomscale values - ZIF_EXCEL_SHEET_PROPERTIES~zoomscale = 100. - ZIF_EXCEL_SHEET_PROPERTIES~zoomscale_normal = 100. - ZIF_EXCEL_SHEET_PROPERTIES~zoomscale_pagelayoutview = 100 . - ZIF_EXCEL_SHEET_PROPERTIES~zoomscale_sheetlayoutview = 100 . -endmethod. - - - method ZIF_EXCEL_SHEET_PROPERTIES~SET_STYLE. - zif_excel_sheet_properties~style = ip_style. -endmethod. - - - method ZIF_EXCEL_SHEET_PROTECTION~INITIALIZE. - - me->zif_excel_sheet_protection~protected = zif_excel_sheet_protection=>c_unprotected. - CLEAR me->zif_excel_sheet_protection~password. - me->zif_excel_sheet_protection~auto_filter = zif_excel_sheet_protection=>c_noactive. - me->zif_excel_sheet_protection~delete_columns = zif_excel_sheet_protection=>c_noactive. - me->zif_excel_sheet_protection~delete_rows = zif_excel_sheet_protection=>c_noactive. - me->zif_excel_sheet_protection~format_cells = zif_excel_sheet_protection=>c_noactive. - me->zif_excel_sheet_protection~format_columns = zif_excel_sheet_protection=>c_noactive. - me->zif_excel_sheet_protection~format_rows = zif_excel_sheet_protection=>c_noactive. - me->zif_excel_sheet_protection~insert_columns = zif_excel_sheet_protection=>c_noactive. - me->zif_excel_sheet_protection~insert_hyperlinks = zif_excel_sheet_protection=>c_noactive. - me->zif_excel_sheet_protection~insert_rows = zif_excel_sheet_protection=>c_noactive. - me->zif_excel_sheet_protection~objects = zif_excel_sheet_protection=>c_noactive. -* me->zif_excel_sheet_protection~password = zif_excel_sheet_protection=>c_noactive. "issue #68 - me->zif_excel_sheet_protection~pivot_tables = zif_excel_sheet_protection=>c_noactive. - me->zif_excel_sheet_protection~protected = zif_excel_sheet_protection=>c_noactive. - me->zif_excel_sheet_protection~scenarios = zif_excel_sheet_protection=>c_noactive. - me->zif_excel_sheet_protection~select_locked_cells = zif_excel_sheet_protection=>c_noactive. - me->zif_excel_sheet_protection~select_unlocked_cells = zif_excel_sheet_protection=>c_noactive. - me->zif_excel_sheet_protection~sheet = zif_excel_sheet_protection=>c_noactive. - me->zif_excel_sheet_protection~sort = zif_excel_sheet_protection=>c_noactive. - -endmethod. - - - method ZIF_EXCEL_SHEET_VBA_PROJECT~SET_CODENAME. - me->zif_excel_sheet_vba_project~codename = ip_codename. -endmethod. - - - method ZIF_EXCEL_SHEET_VBA_PROJECT~SET_CODENAME_PR. - me->zif_excel_sheet_vba_project~codename_pr = ip_codename_pr. -endmethod. - - - - method ADD_DRAWING. - CASE ip_drawing->get_type( ). - WHEN zcl_excel_drawing=>type_image. - drawings->include( ip_drawing ). - WHEN zcl_excel_drawing=>type_chart. - charts->include( ip_drawing ). - ENDCASE. -endmethod. - - - - method ADD_NEW_CONDITIONAL_STYLE. - - CREATE OBJECT eo_conditional_style. - conditional_styles->add( eo_conditional_style ). -endmethod. - - - - method ADD_NEW_DATA_VALIDATION. - - CREATE OBJECT eo_data_validation. - data_validations->add( eo_data_validation ). -endmethod. - - - - method ADD_NEW_RANGE. -* Create default blank range - CREATE OBJECT eo_range. - ranges->add( eo_range ). -endmethod. - - - - - - - - - method BIND_ALV. - data: lo_converter type ref to zcl_excel_converter. - - create object lo_converter. - - try. - lo_converter->convert( - exporting - io_alv = io_alv - it_table = it_table - i_row_int = i_top - i_column_int = i_left - i_table = abap_true - i_style_table = table_style - io_worksheet = me - changing - co_excel = excel ). - catch zcx_excel . - endtry. - -endmethod. - - - - - - - - - - - - - - - - - - - - - - method BIND_ALV_OLE2. -*--------------------------------------------------------------------* -* Method description: -* Method use to export a CL_GUI_ALV_GRID object to xlsx/xls file -* with list header and characteristics of ALV field catalog such as: -* + Total, group's subtotal -* + Quantity fields, amount fields (dependent fields) -* + No_out, no_zero, ... -* Technique use in method: -* SAP Desktop Office Integration (DOI) -*--------------------------------------------------------------------* - -* Data for session 0: DOI constructor -* ------------------------------------------ - - data: lo_control type ref to I_OI_CONTAINER_CONTROL. - data: lo_proxy type ref to I_OI_DOCUMENT_PROXY. - data: lo_spreadsheet type ref to I_OI_SPREADSHEET. - data: lo_error type ref to I_OI_ERROR. - data: lc_retcode type SOI_RET_STRING. - data: li_has type i. "Proxy has spreadsheet interface? - data: l_is_closed type i. - -* Data for session 1: Get LVC data from ALV object -* ------------------------------------------ - - data: l_has_activex, - l_doctype_excel_sheet(11) type c. - data: wa_DOC_HANDLE Type CNTL_HANDLE. - -* LVC - data: lt_fieldcat_lvc type LVC_T_FCAT. - data: wa_fieldcat_lvc type lvc_s_fcat. - data: lt_sort_lvc type LVC_T_SORT. - data: lt_filter_idx_lvc type LVC_T_FIDX. - data: lt_GROUPLEVELS_LVC type LVC_T_GRPL. - -* KKBLO - DATA: LT_FIELDCAT_KKBLO Type KKBLO_T_FIELDCAT. - DATA: LT_SORT_KKBLO Type KKBLO_T_SORTINFO. - DATA: LT_GROUPLEVELS_KKBLO Type KKBLO_T_GROUPLEVELS. - DATA: LT_FILTER_IDX_KKBLO Type KKBLO_T_SFINFO. - data: wa_listheader like line of it_listheader. - -* Subtotal - data: lt_collect00 type ref to data. - data: lt_collect01 type ref to data. - data: lt_collect02 type ref to data. - data: lt_collect03 type ref to data. - data: lt_collect04 type ref to data. - data: lt_collect05 type ref to data. - data: lt_collect06 type ref to data. - data: lt_collect07 type ref to data. - data: lt_collect08 type ref to data. - data: lt_collect09 type ref to data. - -* data table name - data: l_tabname type kkblo_tabname. - -* local object - data: lo_grid type ref to lcl_gui_alv_grid. - -* data table get from ALV - data: lt_alv type ref to data. - -* total / subtotal data - field-symbols: <f_collect00> type standard table. - field-symbols: <f_collect01> type standard table. - field-symbols: <f_collect02> type standard table. - field-symbols: <f_collect03> type standard table. - field-symbols: <f_collect04> type standard table. - field-symbols: <f_collect05> type standard table. - field-symbols: <f_collect06> type standard table. - field-symbols: <f_collect07> type standard table. - field-symbols: <f_collect08> type standard table. - field-symbols: <f_collect09> type standard table. - -* table before append subtotal lines - field-symbols: <f_alv_tab> type standard table. - -* data for session 2: sort, filter and calculate total/subtotal -* ------------------------------------------ - -* table to save index of subotal / total line in excel tanle -* this ideal to control index of subtotal / total line later -* for ex, when get subtotal / total line to format - types: begin of st_subtot_indexs, - index type i, - end of st_subtot_indexs. - data: lt_subtot_indexs type table of st_subtot_indexs. - data: wa_subtot_indexs like line of lt_subtot_indexs. - -* data table after append subtotal - data: lt_excel type ref to data. - - data: l_tabix type i. - data: l_save_index type i. - -* dyn subtotal table name - data: l_collect type string. - -* subtotal range, to format subtotal (and total) - data: subranges type soi_range_list. - data: subrangeitem type soi_range_item. - data: l_sub_index type i. - - -* table after append subtotal lines - field-symbols: <f_excel_tab> type standard table. - field-symbols: <f_excel_line> type any. - -* dyn subtotal tables - field-symbols: <f_collect_tab> type standard table. - field-symbols: <f_collect_line> type any. - - field-symbols: <f_filter_idx_line> like line of LT_FILTER_IDX_KKBLO. - field-symbols: <f_fieldcat_line> like line of LT_FIELDCAT_KKBLO. - field-symbols: <f_grouplevels_line> like line of LT_GROUPLEVELS_KKBLO. - field-symbols: <f_line> type any. - -* Data for session 3: map data to semantic table -* ------------------------------------------ - - types: begin of st_column_index, - fieldname type kkblo_fieldname, - tabname type kkblo_tabname, - col like sy-index, - end of st_column_index. - -* columns index - data: lt_column_index type table of st_column_index. - data: wa_column_index like line of lt_column_index. - -* table of dependent field ( currency and quantity unit field) - data: lt_fieldcat_depf type kkblo_t_fieldcat. - data: wa_fieldcat_depf type kkblo_fieldcat. - -* XXL interface: -* -XXL: contain exporting columns characteristic - data: lt_sema type table of gxxlt_s initial size 0. - data: wa_sema like line of lt_sema. - -* -XXL interface: header - data: lt_hkey type table of gxxlt_h initial size 0. - data: wa_hkey like line of lt_hkey. - -* -XXL interface: header keys - data: lt_vkey type table of gxxlt_v initial size 0. - data: wa_vkey like line of lt_vkey. - -* Number of H Keys: number of key columns - data: l_n_hrz_keys type i. -* Number of data columns in the list object: non-key columns no - data: l_n_att_cols type i. -* Number of V Keys: number of header row - data: l_n_vrt_keys type i. - -* curency to format amount - data: lt_tcurx type table of tcurx. - data: wa_tcurx like line of lt_tcurx. - data: l_def type flag. " currency / quantity flag - data: wa_t006 type t006. " decimal place of unit - - data: l_num type i. " table columns number - data: l_typ type c. " table type - data: wa type ref to data. - data: l_int type i. - data: l_counter type i. - - field-symbols: <f_excel_column> type any. - field-symbols: <f_fcat_column> type any. - -* Data for session 4: write to excel -* ------------------------------------------ - - data: data_starting_at type i value 1. - data: data_ending_at type i value -1. - data: sema_type type c. - - data l_error type ref to c_oi_proxy_error. - data count type i. - data datac type i. - data datareal type i. " exporting column number - data vkeycount type i. - data all type i. - data mit type i value 1. " index of recent row? - data li_col_pos type i value 1. " column position - data li_col_num type i. " table columns number - field-symbols: <line> type any. - field-symbols: <item> type any. - - data td type sydes_desc. - - data: typ. - data: ranges type soi_range_list. - data: rangeitem type soi_range_item. - data: contents type soi_generic_table. - data: contentsitem type soi_generic_item. - data: semaitem type gxxlt_s. - data: hkeyitem type gxxlt_h. - data: vkeyitem type gxxlt_v. - data: li_commentary_rows type i. "row number of title lines + 1 - data: lo_error_w type ref to i_oi_error. - data: l_retcode type soi_ret_string. - data: no_flush type c value 'X'. - data: li_head_top type i. "header rows position - -* Data for session 5: Save and clode document -* ------------------------------------------ - - data: li_document_size type i. - data: ls_path type RLGRAP-FILENAME. - -* MACRO: Close_document -*------------------------------------------- - - DEFINE close_document. - clear: l_is_closed. - IF lo_proxy is not initial. - -* check proxy detroyed adi - - call method lo_proxy->is_destroyed - IMPORTING - ret_value = l_is_closed. - -* if dun detroyed yet: close -> release proxy - - IF l_is_closed is initial. - call method lo_proxy->close_document -* EXPORTING -* do_save = do_save - IMPORTING - error = lo_error - retcode = lc_retcode. - ENDIF. - - call method lo_proxy->release_document - IMPORTING - error = lo_error - retcode = lC_retcode. - - else. - lc_retcode = c_oi_errors=>ret_document_not_open. - ENDIF. - -* Detroy control container - - IF lo_control is not initial. - CALL METHOD lo_control->destroy_control. - ENDIF. - - clear: - lo_spreadsheet, - lo_proxy, - lo_control. - -* free local - - clear: l_is_closed. - - END-OF-DEFINITION. - -* Macro to catch DOI error -*------------------------------------------- - - DEFINE error_doi. - if lc_retcode ne c_oi_errors=>ret_ok. - close_document. - call method lo_error->raise_message - EXPORTING - type = 'E'. - clear: lo_error. - endif. - END-OF-DEFINITION. - -*--------------------------------------------------------------------* -* SESSION 0: DOI CONSTRUCTOR -*--------------------------------------------------------------------* - -* check active windown - - call function 'GUI_HAS_ACTIVEX' - IMPORTING - return = l_has_activex. - - if l_has_activex is initial. - raise MISS_GUIDE. - endif. - -* Get Container Object of Screen - - call method c_oi_container_control_creator=>get_container_control - IMPORTING - control = lo_control - retcode = lC_retcode. - - error_doi. - -* Initialize Container control - - CALL METHOD lo_control->init_control - EXPORTING - parent = CL_GUI_CONTAINER=>DEFAULT_SCREEN - r3_application_name = '' - inplace_enabled = 'X' - no_flush = 'X' - register_on_close_event = 'X' - register_on_custom_event = 'X' - IMPORTING - error = lO_ERROR - retcode = lc_retcode. - - error_doi. - -* Get Proxy Document: -* check exist of document proxy, if exist -> close first - - if not lo_proxy is initial. - close_document. - endif. - - IF i_xls is not initial. -* xls format, doctype = soi_doctype_excel97_sheet - l_doctype_excel_sheet = 'Excel.Sheet.8'. - else. -* xlsx format, doctype = soi_doctype_excel_sheet - l_doctype_excel_sheet = 'Excel.Sheet'. - ENDIF. - - CALL METHOD lo_control->get_document_proxy - EXPORTING - document_type = l_doctype_excel_sheet - register_container = 'X' - IMPORTING - document_proxy = lo_proxy - error = lO_ERROR - retcode = lc_retcode. - - error_doi. - - IF I_DOCUMENT_URL is initial. - -* create new excel document - - call method lo_proxy->create_document - EXPORTING - create_view_data = 'X' - open_inplace = 'X' - no_flush = 'X' - IMPORTING - ERROR = lO_ERROR - retcode = lc_retcode. - - error_doi. - - else. - -* Read excel template for i_DOCUMENT_URL -* this excel template can be store in local or server - - CALL METHOD lo_proxy->open_document - EXPORTING - document_url = i_document_url - open_inplace = 'X' - no_flush = 'X' - IMPORTING - error = lo_error - retcode = lc_retcode. - - error_doi. - - endif. - -* Check Spreadsheet Interface of Document Proxy - - CALL METHOD lo_proxy->has_spreadsheet_interface - IMPORTING - is_available = li_has - error = lO_ERROR - retcode = lc_retcode. - - error_doi. - -* create Spreadsheet object - - CHECK li_has IS NOT INITIAL. - - CALL METHOD lo_proxy->get_spreadsheet_interface - IMPORTING - sheet_interface = lo_spreadsheet - error = lO_ERROR - retcode = lc_retcode. - - error_doi. - -*--------------------------------------------------------------------* -* SESSION 1: GET LVC DATA FROM ALV OBJECT -*--------------------------------------------------------------------* - -* data table - - create object lo_grid - EXPORTING - i_parent = CL_GUI_CONTAINER=>SCREEN0. - - call method lo_grid->get_alv_attributes - EXPORTING - io_grid = io_alv - IMPORTING - Et_table = lt_alv. - - assign lt_alv->* to <f_alv_tab>. - -* fieldcat - - CALL METHOD iO_alv->GET_FRONTEND_FIELDCATALOG - IMPORTING - ET_FIELDCATALOG = lt_fieldcat_LVC. - -* table name - - loop at lt_fieldcat_LVC into wa_fieldcat_lvc - where not tabname is initial. - l_tabname = wa_fieldcat_lvc-tabname. - exit. - endloop. - - if sy-subrc ne 0. - l_tabname = '1'. - endif. - clear: wa_fieldcat_lvc. - -* sort table - - CALL METHOD IO_ALV->GET_SORT_CRITERIA - IMPORTING - ET_SORT = lt_sort_lvc. - - -* filter index - - CALL METHOD IO_ALV->GET_FILTERED_ENTRIES - IMPORTING - ET_FILTERED_ENTRIES = lt_filter_idx_lvc. - -* group level + subtotal - - CALL METHOD IO_ALV->GET_SUBTOTALS - IMPORTING - EP_COLLECT00 = lt_collect00 - EP_COLLECT01 = lt_collect01 - EP_COLLECT02 = lt_collect02 - EP_COLLECT03 = lt_collect03 - EP_COLLECT04 = lt_collect04 - EP_COLLECT05 = lt_collect05 - EP_COLLECT06 = lt_collect06 - EP_COLLECT07 = lt_collect07 - EP_COLLECT08 = lt_collect08 - EP_COLLECT09 = lt_collect09 - ET_GROUPLEVELS = lt_GROUPLEVELS_LVC. - - assign lt_collect00->* to <f_collect00>. - assign lt_collect01->* to <f_collect01>. - assign lt_collect02->* to <f_collect02>. - assign lt_collect03->* to <f_collect03>. - assign lt_collect04->* to <f_collect04>. - assign lt_collect05->* to <f_collect05>. - assign lt_collect06->* to <f_collect06>. - assign lt_collect07->* to <f_collect07>. - assign lt_collect08->* to <f_collect08>. - assign lt_collect09->* to <f_collect09>. - -* transfer to KKBLO struct - - CALL FUNCTION 'LVC_TRANSFER_TO_KKBLO' - EXPORTING - IT_FIELDCAT_LVC = lt_fieldcat_lvc - IT_SORT_LVC = lt_sort_lvc - IT_FILTER_INDEX_LVC = lt_filter_idx_lvc - IT_GROUPLEVELS_LVC = lt_grouplevels_lvc - IMPORTING - ET_FIELDCAT_KKBLO = lt_fieldcat_kkblo - ET_SORT_KKBLO = lt_sort_kkblo - ET_FILTERED_ENTRIES_KKBLO = lt_filter_idx_kkblo - ET_GROUPLEVELS_KKBLO = lt_grouplevels_kkblo - TABLES - IT_DATA = <f_alv_tab> - EXCEPTIONS - IT_DATA_MISSING = 1 - IT_FIELDCAT_LVC_MISSING = 2 - OTHERS = 3. - IF SY-SUBRC <> 0. - raise ex_transfer_KKBLO_ERROR. - ENDIF. - - clear: - wa_fieldcat_lvc, - lt_fieldcat_lvc, - lt_sort_lvc, - lt_filter_idx_lvc, - lt_GROUPLEVELS_LVC. - - clear: - lo_grid. - - -*--------------------------------------------------------------------* -* SESSION 2: SORT, FILTER AND CALCULATE TOTAL / SUBTOTAL -*--------------------------------------------------------------------* - -* append subtotal & total line - - create data lt_excel like <f_ALV_TAB>. - assign lt_excel->* to <f_excel_tab>. - - loop at <f_alv_tab> assigning <f_line>. - l_save_index = sy-tabix. - -* filter base on filter index table - - read table LT_FILTER_IDX_KKBLO assigning <f_filter_idx_line> - with key index = l_save_index - binary search. - if sy-subrc ne 0. - append <f_line> to <f_excel_tab>. - endif. - -* append subtotal lines - - read table LT_GROUPLEVELS_KKBLO assigning <f_grouplevels_line> - with key index_to = l_save_index - binary search. - if sy-subrc = 0. - l_tabix = sy-tabix. - do. - if <f_grouplevels_line>-subtot eq 'X' and - <f_grouplevels_line>-hide_level is initial and - <f_grouplevels_line>-cindex_from ne 0. - -* dynamic append subtotal line to excel table base on grouplevel table -* ex <f_GROUPLEVELS_line>-level = 1 -* then <f_collect_tab> = '<F_COLLECT01>' - - l_collect = <f_grouplevels_line>-level. - condense l_collect. - concatenate '<F_COLLECT0' - l_collect '>' -* '->*' - into l_collect. - - assign (l_collect) to <f_collect_tab>. - -* incase there're more than 1 total line of group, at the same level -* for example: subtotal of multi currency - - LOOP AT <f_collect_tab> assigning <f_collect_line>. - IF sy-tabix between <f_grouplevels_line>-cindex_from - and <f_grouplevels_line>-cindex_to. - - - append <f_collect_line> to <f_excel_tab>. - -* save subtotal lines index - - wa_subtot_indexs-index = sy-tabix. - append wa_subtot_indexs to lt_subtot_indexs. - -* append sub total ranges table for format later - - add 1 to l_sub_index. - subrangeitem-name = l_sub_index. - condense subrangeitem-name. - concatenate 'SUBTOT' - subrangeitem-name - into subrangeitem-name. - - subrangeitem-rows = wa_subtot_indexs-index. - subrangeitem-columns = 1. " start col - append subrangeitem to subranges. - clear: subrangeitem. - - ENDIF. - ENDLOOP. - unassign: <f_collect_tab>. - unassign: <f_collect_line>. - clear: l_collect. - endif. - -* check next subtotal level of group - - unassign: <f_grouplevels_line>. - add 1 to l_tabix. - - read table LT_GROUPLEVELS_KKBLO assigning <f_grouplevels_line> - index l_tabix. - if sy-subrc ne 0 - or <f_grouplevels_line>-index_to ne l_save_index. - exit. - endif. - - unassign: - <f_collect_tab>, - <f_collect_line>. - - enddo. - endif. - - clear: - l_tabix, - l_save_index. - - unassign: - <f_filter_idx_line>, - <f_grouplevels_line>. - - endloop. - -* free local data - - unassign: - <f_line>, - <f_collect_tab>, - <f_collect_line>, - <f_fieldcat_line>. - -* append grand total line - - IF <f_collect00> is assigned. - assign <f_collect00> to <f_collect_tab>. - if <f_collect_tab> is not initial. - LOOP AT <f_collect_tab> assigning <f_collect_line>. - - append <f_collect_line> to <f_excel_tab>. - -* save total line index - - wa_subtot_indexs-index = sy-tabix. - append wa_subtot_indexs to lt_subtot_indexs. - -* append grand total range (to format) - - add 1 to l_sub_index. - subrangeitem-name = l_sub_index. - condense subrangeitem-name. - concatenate 'TOTAL' - subrangeitem-name - into subrangeitem-name. - - subrangeitem-rows = wa_subtot_indexs-index. - subrangeitem-columns = 1. " start col - append subrangeitem to subranges. - ENDLOOP. - endif. - ENDIF. - - clear: - subrangeitem, - LT_SORT_KKBLO, - <f_collect00>, - <f_collect01>, - <f_collect02>, - <f_collect03>, - <f_collect04>, - <f_collect05>, - <f_collect06>, - <f_collect07>, - <f_collect08>, - <f_collect09>. - - unassign: - <f_collect00>, - <f_collect01>, - <f_collect02>, - <f_collect03>, - <f_collect04>, - <f_collect05>, - <f_collect06>, - <f_collect07>, - <f_collect08>, - <f_collect09>, - <f_collect_tab>, - <f_collect_line>. - -*--------------------------------------------------------------------* -* SESSION 3: MAP DATA TO SEMANTIC TABLE -*--------------------------------------------------------------------* - -* get dependent field field: currency and quantity - - create data wa like line of <f_excel_tab>. - assign wa->* to <f_excel_line>. - - describe field <f_excel_line> type l_typ components l_num. - - do l_num times. - l_save_index = sy-index. - assign component l_save_index of structure <f_excel_line> - to <f_excel_column>. - if sy-subrc ne 0. - message e059(0k) with 'FATAL ERROR' raising fatal_error. - endif. - - loop at LT_FIELDCAT_KKBLO assigning <f_fieldcat_line> - where tabname = l_tabname. - assign component <f_fieldcat_line>-fieldname - of structure <f_excel_line> to <f_fcat_column>. - - describe distance between <f_excel_column> and <f_fcat_column> - into l_int in byte mode. - -* append column index -* this columns index is of table, not fieldcat - - if l_int = 0. - wa_column_index-fieldname = <f_fieldcat_line>-fieldname. - wa_column_index-tabname = <f_fieldcat_line>-tabname. - wa_column_index-col = l_save_index. - append wa_column_index to lt_column_index. - endif. - -* append dependent fields (currency and quantity unit) - - if <f_fieldcat_line>-cfieldname is not initial. - clear wa_fieldcat_depf. - wa_fieldcat_depf-fieldname = <f_fieldcat_line>-cfieldname. - wa_fieldcat_depf-tabname = <f_fieldcat_line>-ctabname. - collect wa_fieldcat_depf into lt_fieldcat_depf. - endif. - - if <f_fieldcat_line>-qfieldname is not initial. - clear wa_fieldcat_depf. - wa_fieldcat_depf-fieldname = <f_fieldcat_line>-qfieldname. - wa_fieldcat_depf-tabname = <f_fieldcat_line>-qtabname. - collect wa_fieldcat_depf into lt_fieldcat_depf. - endif. - -* rewrite field data type - - if <f_fieldcat_line>-inttype = 'X' - and <f_fieldcat_line>-datatype(3) = 'INT'. - <f_fieldcat_line>-inttype = 'I'. - endif. - - endloop. - - clear: l_save_index. - unassign: <f_fieldcat_line>. - - enddo. - -* build semantic tables - - l_n_hrz_keys = 1. - -* Get keyfigures - - loop at LT_FIELDCAT_KKBLO assigning <f_fieldcat_line> - where tabname = l_tabname - and tech ne 'X' - and no_out ne 'X'. - - clear wa_sema. - clear wa_hkey. - -* Units belong to keyfigures -> display as str - - read table lt_fieldcat_depf into wa_fieldcat_depf with key - fieldname = <f_fieldcat_line>-fieldname - tabname = <f_fieldcat_line>-tabname. - - if sy-subrc = 0. - wa_sema-col_typ = 'STR'. - wa_sema-col_ops = 'DFT'. - -* Keyfigures - - else. - case <f_fieldcat_line>-datatype. - when 'QUAN'. - wa_sema-col_typ = 'N03'. - - if <f_fieldcat_line>-no_sum ne 'X'. - wa_sema-col_ops = 'ADD'. - else. - wa_sema-col_ops = 'NOP'. " no dependent field - endif. - - when 'DATS'. - wa_sema-col_typ = 'DAT'. - wa_sema-col_ops = 'NOP'. - - when 'CHAR' OR 'UNIT' OR 'CUKY'. " Added fieldformats UNIT and CUKY - dd. 26-10-2012 Wouter Heuvelmans - wa_sema-col_typ = 'STR'. - wa_sema-col_ops = 'DFT'. " dependent field - -* incase numeric, ex '00120' -> display as '12' - - when 'NUMC'. - wa_sema-col_typ = 'STR'. - wa_sema-col_ops = 'DFT'. - - when others. - wa_sema-col_typ = 'NUM'. - - if <f_fieldcat_line>-no_sum ne 'X'. - wa_sema-col_ops = 'ADD'. - else. - wa_sema-col_ops = 'NOP'. - endif. - endcase. - endif. - - l_counter = l_counter + 1. - l_n_att_cols = l_n_att_cols + 1. - - wa_sema-col_no = l_counter. - - read table lt_column_index into wa_column_index with key - fieldname = <f_fieldcat_line>-fieldname - tabname = <f_fieldcat_line>-tabname. - - if sy-subrc = 0. - wa_sema-col_src = wa_column_index-col. - else. - raise fatal_error. - endif. - -* columns index of ref currency field in table - - if not <f_fieldcat_line>-cfieldname is initial. - read table lt_column_index into wa_column_index with key - fieldname = <f_fieldcat_line>-cfieldname - tabname = <f_fieldcat_line>-ctabname. - - if sy-subrc = 0. - wa_sema-col_cur = wa_column_index-col. - endif. - -* quantities fields -* treat as currency when display on excel - - elseif not <f_fieldcat_line>-qfieldname is initial. - read table lt_column_index into wa_column_index with key - fieldname = <f_fieldcat_line>-qfieldname - tabname = <f_fieldcat_line>-qtabname. - if sy-subrc = 0. - wa_sema-col_cur = wa_column_index-col. - endif. - - endif. - -* Treat of fixed currency in the fieldcatalog for column - - data: l_num_help(2) type n. - - if not <f_fieldcat_line>-currency is initial. - - select * from tcurx into table lt_tcurx. - sort lt_tcurx. - read table lt_tcurx into wa_tcurx - with key currkey = <f_fieldcat_line>-currency. - if sy-subrc = 0. - l_num_help = wa_tcurx-currdec. - concatenate 'N' l_num_help into wa_sema-col_typ. - wa_sema-col_cur = sy-tabix * ( -1 ). - endif. - - endif. - - wa_hkey-col_no = l_n_att_cols. - wa_hkey-row_no = l_n_hrz_keys. - wa_hkey-col_name = <f_fieldcat_line>-reptext. - append wa_hkey to lt_hkey. - append wa_sema to lt_sema. - - endloop. - -* free local data - - clear: - lt_column_index, - wa_column_index, - lt_fieldcat_depf, - wa_fieldcat_depf, - lt_tcurx, - wa_tcurx, - l_num, - l_typ, - wa, - l_int, - l_counter. - - unassign: - <f_fieldcat_line>, - <f_excel_line>, - <f_excel_column>, - <f_fcat_column>. - -*--------------------------------------------------------------------* -* SESSION 4: WRITE TO EXCEL -*--------------------------------------------------------------------* - - clear: wa_tcurx. - refresh: lt_tcurx. - -* if spreadsheet dun have proxy yet - - if li_has is initial. - l_retcode = c_oi_errors=>ret_interface_not_supported. - call method c_oi_errors=>create_error_for_retcode - EXPORTING - retcode = l_retcode - no_flush = no_flush - IMPORTING - error = lo_error_w. - exit. - endif. - - create object l_error - EXPORTING - object_name = 'OLE_DOCUMENT_PROXY' - method_name = 'get_ranges_names'. - - call method c_oi_errors=>add_error - EXPORTING - error = l_error. - - - describe table lt_sema lines datareal. - describe table <f_excel_tab> lines datac. - describe table lt_vkey lines vkeycount. - - if datac = 0. - raise inv_data_range. - endif. - - - if vkeycount ne l_n_vrt_keys. - raise dim_mismatch_vkey. - endif. - - all = l_n_vrt_keys + l_n_att_cols. - - if datareal ne all. - raise dim_mismatch_sema. - endif. - - data: decimal type c. - -* get decimal separator format ('.', ',', ...) in Office config - - call method lo_proxy->get_application_property - EXPORTING - property_name = 'INTERNATIONAL' - subproperty_name = 'DECIMAL_SEPARATOR' - CHANGING - retvalue = decimal. - - data: wa_usr type usr01. - select * from usr01 into wa_usr where bname = sy-uname. - endselect. - - data: comma_elim(4) type c. - data: help6 type i. - field-symbols <g> type any. - data search_item(4) value ' #'. - - concatenate ',' decimal '.' decimal into comma_elim. - - data help type i. " table (with subtotal) line number - - help = datac. - - data: rowmax type i value 1. " header row number - data: columnmax type i value 0. " header columns number - - loop at lt_hkey into hkeyitem. - if hkeyitem-col_no > columnmax. - columnmax = hkeyitem-col_no. - endif. - - if hkeyitem-row_no > rowmax. - rowmax = hkeyitem-row_no. - endif. - endloop. - - data: hkeycolumns type i. " header columns no - - hkeycolumns = columnmax. - - if hkeycolumns < l_n_att_cols. - hkeycolumns = l_n_att_cols. - endif. - - columnmax = 0. - - loop at lt_vkey into vkeyitem. - if vkeyitem-col_no > columnmax. - columnmax = vkeyitem-col_no. - endif. - endloop. - - data overflow type i value 1. - data testname(10) type c. - data temp2 type i. " 1st item row position in excel - data realmit type i value 1. - data realoverflow type i value 1. " row index in content - - call method lo_spreadsheet->screen_update - EXPORTING - updating = ''. - - call method lo_spreadsheet->load_lib. - - data: str(40) type c. " range names of columns range (w/o col header) - data: rows type i. " row postion of 1st item line in ecxel - -* calculate row position of data table - - describe table iT_LISTHEADER lines li_commentary_rows. - -* if grid had title, add 1 empy line between title and table - - if li_commentary_rows ne 0. - add 1 to li_commentary_rows. - endif. - -* add top position of block data - - li_commentary_rows = li_commentary_rows + i_top - 1. - -* write header (commentary rows) - - data: li_commentary_row_index type i value 1. - data: li_content_index type i value 1. - data: ls_index(10) type c. - data ls_commentary_range(40) type c value 'TITLE'. - data: li_font_bold type i. - data: li_font_italic type i. - data: li_font_size type i. - - loop at iT_LISTHEADER into wa_listheader. - li_commentary_row_index = i_top + li_content_index - 1. - ls_index = li_content_index. - condense ls_index. - concatenate ls_commentary_range(5) ls_index - into ls_commentary_range. - condense ls_commentary_range. - -* insert title range - - call method lo_spreadsheet->insert_range_dim - EXPORTING - name = ls_commentary_range - top = li_commentary_row_index - left = i_left - rows = 1 - columns = 1 - no_flush = no_flush. - -* format range - - case wa_listheader-typ. - when 'H'. "title - li_font_size = 16. - li_font_bold = 1. - li_font_italic = -1. - when 'S'. "subtile - li_font_size = -1. - li_font_bold = 1. - li_font_italic = -1. - when others. "'A' comment - li_font_size = -1. - li_font_bold = -1. - li_font_italic = 1. - endcase. - - call method lo_spreadsheet->set_font - EXPORTING - rangename = ls_commentary_range - family = '' - size = li_font_size - bold = li_font_bold - italic = li_font_italic - align = 0 - no_flush = no_flush. - -* title: range content - - rangeitem-name = ls_commentary_range. - rangeitem-columns = 1. - rangeitem-rows = 1. - append rangeitem to ranges. - - contentsitem-row = li_content_index. - contentsitem-column = 1. - concatenate wa_listheader-key - wa_listheader-info - into contentsitem-value - separated by space. - condense contentsitem-value. - append contentsitem to contents. - - add 1 to li_content_index. - - clear: - rangeitem, - contentsitem, - ls_index. - - endloop. - -* set range data title - - call method lo_spreadsheet->set_ranges_data - EXPORTING - ranges = ranges - contents = contents - no_flush = no_flush. - - refresh: - ranges, - contents. - - rows = rowmax + li_commentary_rows + 1. - - all = wa_usr-datfm. - all = all + 3. - - loop at lt_sema into semaitem. - if semaitem-col_typ = 'DAT' or semaitem-col_typ = 'MON' or - semaitem-col_typ = 'N00' or semaitem-col_typ = 'N01' or - semaitem-col_typ = 'N01' or semaitem-col_typ = 'N02' or - semaitem-col_typ = 'N03' or semaitem-col_typ = 'PCT' or - semaitem-col_typ = 'STR' or semaitem-col_typ = 'NUM'. - clear str. - str = semaitem-col_no. - condense str. - concatenate 'DATA' str into str. - mit = semaitem-col_no. - li_col_pos = semaitem-col_no + i_left - 1. - -* range from data1 to data(n), for each columns of table - - call method lo_spreadsheet->insert_range_dim - EXPORTING - name = str - top = rows - left = li_col_pos - rows = help - columns = 1 - no_flush = no_flush. - - data dec type i value -1. - data typeinfo type sydes_typeinfo. - loop at <f_excel_tab> assigning <line>. - assign component semaitem-col_no of structure <line> to <item>. - describe field <item> into td. - read table td-types index 1 into typeinfo. - if typeinfo-type = 'P'. - dec = typeinfo-decimals. - elseif typeinfo-type = 'I'. - dec = 0. - endif. - - describe field <line> type typ components count. - mit = 1. - do count times. - if mit = semaitem-col_src. - assign component sy-index of structure <line> to <item>. - describe field <item> into td. - read table td-types index 1 into typeinfo. - if typeinfo-type = 'P'. - dec = typeinfo-decimals. - endif. - exit. - endif. - mit = mit + 1. - enddo. - exit. - endloop. - -* format for each columns of table (w/o columns headers) - - if semaitem-col_typ = 'DAT'. - if semaitem-col_no > vkeycount. - call method lo_spreadsheet->set_format - EXPORTING - rangename = str - currency = '' - typ = all - no_flush = no_flush. - else. - call method lo_spreadsheet->set_format - EXPORTING - rangename = str - currency = '' - typ = 0 - no_flush = no_flush. - endif. - elseif semaitem-col_typ = 'STR'. - call method lo_spreadsheet->set_format - EXPORTING - rangename = str - currency = '' - typ = 0 - no_flush = no_flush. - elseif semaitem-col_typ = 'MON'. - call method lo_spreadsheet->set_format - EXPORTING - rangename = str - currency = '' - typ = 10 - no_flush = no_flush. - elseif semaitem-col_typ = 'N00'. - call method lo_spreadsheet->set_format - EXPORTING - rangename = str - currency = '' - typ = 1 - decimals = 0 - no_flush = no_flush. - elseif semaitem-col_typ = 'N01'. - call method lo_spreadsheet->set_format - EXPORTING - rangename = str - currency = '' - typ = 1 - decimals = 1 - no_flush = no_flush. - elseif semaitem-col_typ = 'N02'. - call method lo_spreadsheet->set_format - EXPORTING - rangename = str - currency = '' - typ = 1 - decimals = 2 - no_flush = no_flush. - elseif semaitem-col_typ = 'N03'. - call method lo_spreadsheet->set_format - EXPORTING - rangename = str - currency = '' - typ = 1 - decimals = 3 - no_flush = no_flush. - elseif semaitem-col_typ = 'N04'. - call method lo_spreadsheet->set_format - EXPORTING - rangename = str - currency = '' - typ = 1 - decimals = 4 - no_flush = no_flush. - elseif semaitem-col_typ = 'NUM'. - if dec eq -1. - call method lo_spreadsheet->set_format - EXPORTING - rangename = str - currency = '' - typ = 1 - decimals = 2 - no_flush = no_flush. - else. - call method lo_spreadsheet->set_format - EXPORTING - rangename = str - currency = '' - typ = 1 - decimals = dec - no_flush = no_flush. - endif. - elseif semaitem-col_typ = 'PCT'. - call method lo_spreadsheet->set_format - EXPORTING - rangename = str - currency = '' - typ = 3 - decimals = 0 - no_flush = no_flush. - endif. - - endif. - endloop. - -* get item contents for set_range_data method -* get currency cell also - - mit = 1. - - data: currcells type soi_cell_table. - data: curritem type soi_cell_item. - - curritem-rows = 1. - curritem-columns = 1. - curritem-front = -1. - curritem-back = -1. - curritem-font = ''. - curritem-size = -1. - curritem-bold = -1. - curritem-italic = -1. - curritem-align = -1. - curritem-frametyp = -1. - curritem-framecolor = -1. - curritem-currency = ''. - curritem-number = 1. - curritem-input = -1. - - data: conv_exit(10) type c. - data: const type i. - -* Change for Correction request -* Initial 10000 lines are missing in Excel Export -* if there are only 2 columns in exported List object. - - if datareal gt 2. - const = 20000 / datareal. - else. - const = 20000 / ( datareal + 2 ). - endif. - - data: lines type i. - data: innerlines type i. - data: counter type i. - data: curritem2 like curritem. - data: curritem3 like curritem. - data: length type i. - data: found. - -* append content table (for method set_range_content) - - loop at <f_excel_tab> assigning <line>. - -* save line index to compare with lt_subtot_indexs, -* to discover line is a subtotal / totale line or not -* ex use to set 'dun display zero in subtotal / total line' - - l_save_index = sy-tabix. - - do datareal times. - read table lt_sema into semaitem with key col_no = sy-index. - if semaitem-col_src ne 0. - assign component semaitem-col_src - of structure <line> to <item>. - else. - assign component sy-index - of structure <line> to <item>. - endif. - - contentsitem-row = realoverflow. - - if sy-subrc = 0. - move semaitem-col_ops to search_item(3). - search 'ADD#CNT#MIN#MAX#AVG#NOP#DFT#' - for search_item. - if sy-subrc ne 0. - raise error_in_sema. - endif. - move semaitem-col_typ to search_item(3). - search 'NUM#N00#N01#N02#N03#N04#PCT#DAT#MON#STR#' - for search_item. - if sy-subrc ne 0. - raise error_in_sema. - endif. - contentsitem-column = sy-index. - if semaitem-col_typ eq 'DAT' or semaitem-col_typ eq 'MON'. - if semaitem-col_no > vkeycount. - - " Hinweis 512418 - " EXCEL bezieht Datumsangaben - " auf den 31.12.1899, behandelt - " aber 1900 als ein Schaltjahr - " d.h. ab 1.3.1900 korrekt - " 1.3.1900 als Zahl = 61 - - data: genesis type d value '18991230'. - data: number_of_days type p. -* change for date in char format & sema_type = X - data: temp_date type d. - - if not <item> is initial and not <item> co ' ' and not - <item> co '0'. -* change for date in char format & sema_type = X starts - if sema_type = 'X'. - describe field <item> type typ. - if typ = 'C'. - temp_date = <item>. - number_of_days = temp_date - genesis. - else. - number_of_days = <item> - genesis. - endif. - else. - number_of_days = <item> - genesis. - endif. -* change for date in char format & sema_type = X ends - if number_of_days < 61. - number_of_days = number_of_days - 1. - endif. - - set country 'DE'. - write number_of_days to contentsitem-value - no-grouping - left-justified. - set country space. - translate contentsitem-value using comma_elim. - else. - clear contentsitem-value. - endif. - else. - move <item> to contentsitem-value. - endif. - elseif semaitem-col_typ eq 'NUM' or - semaitem-col_typ eq 'N00' or - semaitem-col_typ eq 'N01' or - semaitem-col_typ eq 'N02' or - semaitem-col_typ eq 'N03' or - semaitem-col_typ eq 'N04' or - semaitem-col_typ eq 'PCT'. - set country 'DE'. - describe field <item> type typ. - - if semaitem-col_cur is initial. - if typ ne 'F'. - write <item> to contentsitem-value no-grouping - no-sign decimals 14. - else. - write <item> to contentsitem-value no-grouping - no-sign. - endif. - else. -* Treat of fixed curreny for column >>Y9CK007319 - if semaitem-col_cur < 0. - semaitem-col_cur = semaitem-col_cur * ( -1 ). - select * from tcurx into table lt_tcurx. - sort lt_tcurx. - read table lt_tcurx into - wa_tcurx index semaitem-col_cur. - if sy-subrc = 0. - if typ ne 'F'. - write <item> to contentsitem-value no-grouping - currency wa_tcurx-currkey no-sign decimals 14. - else. - write <item> to contentsitem-value no-grouping - currency wa_tcurx-currkey no-sign. - endif. - endif. - else. - assign component semaitem-col_cur - of structure <line> to <g>. -* mit = index of recent row - curritem-top = rowmax + mit + li_commentary_rows. - - li_col_pos = sy-index + i_left - 1. - curritem-left = li_col_pos. - -* if filed is quantity field (qfieldname ne space) -* or amount field (cfieldname ne space), then format decimal place -* corresponding with config - - clear: l_def. - read table LT_FIELDCAT_KKBLO assigning <f_fieldcat_line> - with key tabname = l_tabname - tech = space - no_out = space - col_pos = semaitem-col_no. - IF sy-subrc = 0. - IF <f_fieldcat_line>-cfieldname is not initial. - l_def = 'C'. - else."if <f_fieldcat_line>-qfieldname is not initial. - l_def = 'Q'. - ENDIF. - ENDIF. - -* if field is amount field -* exporting of amount field base on currency decimal table: TCURX - IF l_def = 'C'. "field is amount field - select single * from tcurx into wa_tcurx - where currkey = <g>. -* if amount ref to un-know currency -> default decimal = 2 - if sy-subrc eq 0. - curritem-decimals = wa_tcurx-currdec. - else. - curritem-decimals = 2. - endif. - - append curritem to currcells. - if typ ne 'F'. - write <item> to contentsitem-value - currency <g> - no-sign no-grouping. - else. - write <item> to contentsitem-value - decimals 14 currency <g> - no-sign no-grouping. - endif. - -* if field is quantity field -* exporting of quantity field base on quantity decimal table: T006 - - else."if l_def = 'Q'. " field is quantity field - clear: wa_t006. - select single * from t006 into wa_t006 - where MSEHI = <g>. -* if quantity ref to un-know unit-> default decimal = 2 - if sy-subrc eq 0. - curritem-decimals = wa_t006-decan. - else. - curritem-decimals = 2. - endif. - append curritem to currcells. - - write <item> to contentsitem-value - unit <g> - no-sign no-grouping. - condense contentsitem-value. - - ENDIF. - - endif. "Y9CK007319 - endif. - condense contentsitem-value. - -* add function fieldcat-no zero display - - loop at LT_FIELDCAT_KKBLO assigning <f_fieldcat_line> - where tabname = l_tabname - and tech ne 'X' - and no_out ne 'X'. - if <f_fieldcat_line>-col_pos = semaitem-col_no. - if <f_fieldcat_line>-no_zero = 'X'. - if <item> = '0'. - clear: contentsitem-value. - endif. - -* dun display zero in total/subtotal line too - - else. - clear: wa_subtot_indexs. - read table lt_subtot_indexs into wa_subtot_indexs - with key index = l_save_index. - IF sy-subrc = 0. - if <item> = '0'. - clear: contentsitem-value. - endif. - ENDIF. - endif. - endif. - endloop. - unassign: <f_fieldcat_line>. - - if <item> lt 0. - search contentsitem-value for 'E'. - if sy-fdpos eq 0. - -* bring negative sign to front of amount - - translate contentsitem-value using '- '. - condense contentsitem-value no-gaps. - concatenate '-' contentsitem-value - into contentsitem-value. - else. - concatenate '-' contentsitem-value - into contentsitem-value. - endif. - endif. - set country space. -* Hier wird nur die korrekte Kommaseparatierung gemacht, wenn die -* Zeichen einer -* Zahl enthalten sind. Das ist f#ƒÂ#r Timestamps, die auch ":" enthalten. -* F#ƒÂ#r die -* darf keine Kommaseparierung stattfinden. -* Changing for correction request - Y6BK041073 - if contentsitem-value co '0123456789.,-+E '. - translate contentsitem-value using comma_elim. - endif. - else. - clear contentsitem-value. - -* if type is not numeric -> dun display with zero - - write <item> to contentsitem-value no-zero. - - shift contentsitem-value left deleting leading space. - - endif. - append contentsitem to contents. - endif. - enddo. - - realmit = realmit + 1. - realoverflow = realoverflow + 1. - - mit = mit + 1. -* overflow = current row index in content table - overflow = overflow + 1. - endloop. - - unassign: <f_fieldcat_line>. - -* set item range for set_range_data method - - testname = mit / const. - condense testname. - - concatenate 'TEST' testname into testname. - - realoverflow = realoverflow - 1. - realmit = realmit - 1. - help = realoverflow. - - rangeitem-name = testname. - rangeitem-columns = datareal. - rangeitem-rows = help. - append rangeitem to ranges. - -* insert item range dim - - temp2 = rowmax + 1 + li_commentary_rows + realmit - realoverflow. - -* items data - - call method lo_spreadsheet->insert_range_dim - EXPORTING - name = testname - top = temp2 - left = i_left - rows = help - columns = datareal - no_flush = no_flush. - -* get columns header contents for set_range_data method -* export columns header only if no columns header option = space - - data: rowcount type i. - data: columncount type i. - - if i_columns_header = 'X'. - -* append columns header to contents: hkey - - rowcount = 1. - do rowmax times. - columncount = 1. - do hkeycolumns times. - loop at lt_hkey into hkeyitem where col_no = columncount - and row_no = rowcount. - endloop. - if sy-subrc = 0. - str = hkeyitem-col_name. - contentsitem-value = hkeyitem-col_name. - else. - contentsitem-value = str. - endif. - contentsitem-column = columncount. - contentsitem-row = rowcount. - append contentsitem to contents. - columncount = columncount + 1. - enddo. - rowcount = rowcount + 1. - enddo. - -* incase columns header in multiline - - data: rowmaxtemp type i. - if rowmax > 1. - rowmaxtemp = rowmax - 1. - rowcount = 1. - do rowmaxtemp times. - columncount = 1. - do columnmax times. - contentsitem-column = columncount. - contentsitem-row = rowcount. - contentsitem-value = ''. - append contentsitem to contents. - columncount = columncount + 1. - enddo. - rowcount = rowcount + 1. - enddo. - endif. - -* append columns header to contents: vkey - - columncount = 1. - do columnmax times. - loop at lt_vkey into vkeyitem where col_no = columncount. - endloop. - contentsitem-value = vkeyitem-col_name. - contentsitem-row = rowmax. - contentsitem-column = columncount. - append contentsitem to contents. - columncount = columncount + 1. - enddo. -*--------------------------------------------------------------------* -* set header range for method set_range_data -* insert header keys range dim - - li_head_top = li_commentary_rows + 1. - li_col_pos = i_left. - -* insert range headers - - if hkeycolumns ne 0. - rangeitem-name = 'TESTHKEY'. - rangeitem-rows = rowmax. - rangeitem-columns = hkeycolumns. - append rangeitem to ranges. - clear: rangeitem. - - call method lo_spreadsheet->insert_range_dim - EXPORTING - name = 'TESTHKEY' - top = li_head_top - left = li_col_pos - rows = rowmax - columns = hkeycolumns - no_flush = no_flush. - endif. - endif. - -* format for columns header + total + subtotal -* ------------------------------------------ - - help = rowmax + realmit. " table + header lines - - data: item type colxxl_t. - data: lt_format type soi_format_table. - data: wa_format like line of lt_format. - data: wa_format_temp like line of lt_format. - - field-symbols: <f_source> type any. - field-symbols: <f_des> type any. - -* columns header format - - wa_format-front = -1. - wa_format-back = 15. "grey - wa_format-font = space. - wa_format-size = -1. - wa_format-bold = 1. - wa_format-align = 0. - wa_format-frametyp = -1. - wa_format-framecolor = -1. - -* get column header format from input record -* -> map input format - - if i_columns_header = 'X'. - wa_format-name = 'TESTHKEY'. - if i_format_col_header is not initial. - describe field i_format_col_header type l_typ components - li_col_num. - do li_col_num times. - if sy-index ne 1. " dun map range name - assign component sy-index of structure i_format_col_header - to <f_source>. - if <f_source> is not initial. - assign component sy-index of structure wa_format to <f_des>. - <f_des> = <f_source>. - unassign: <f_des>. - endif. - unassign: <f_source>. - endif. - enddo. - - clear: li_col_num. - endif. - - append wa_format to lt_format. - endif. - -* Zusammenfassen der Spalten mit gleicher Nachkommastellenzahl -* collect vertical cells (col) with the same number of decimal places -* to increase perfomance in currency cell format - - describe table currcells lines lines. - lines = lines - 1. - do lines times. - describe table currcells lines innerlines. - innerlines = innerlines - 1. - sort currcells by left top. - clear found. - do innerlines times. - read table currcells index sy-index into curritem. - counter = sy-index + 1. - read table currcells index counter into curritem2. - if curritem-left eq curritem2-left. - length = curritem-top + curritem-rows. - if length eq curritem2-top. - if curritem-decimals eq curritem2-decimals. - move curritem to curritem3. - curritem3-rows = curritem3-rows + curritem2-rows. - curritem-left = -1. - modify currcells index sy-index from curritem. - curritem2-left = -1. - modify currcells index counter from curritem2. - append curritem3 to currcells. - found = 'X'. - endif. - endif. - endif. - enddo. - if found is initial. - exit. - endif. - delete currcells where left = -1. - enddo. - -* Zusammenfassen der Zeilen mit gleicher Nachkommastellenzahl -* collect horizontal cells (row) with the same number of decimal places -* to increase perfomance in currency cell format - - describe table currcells lines lines. - lines = lines - 1. - do lines times. - describe table currcells lines innerlines. - innerlines = innerlines - 1. - sort currcells by top left. - clear found. - do innerlines times. - read table currcells index sy-index into curritem. - counter = sy-index + 1. - read table currcells index counter into curritem2. - if curritem-top eq curritem2-top and curritem-rows eq - curritem2-rows. - length = curritem-left + curritem-columns. - if length eq curritem2-left. - if curritem-decimals eq curritem2-decimals. - move curritem to curritem3. - curritem3-columns = curritem3-columns + curritem2-columns. - curritem-left = -1. - modify currcells index sy-index from curritem. - curritem2-left = -1. - modify currcells index counter from curritem2. - append curritem3 to currcells. - found = 'X'. - endif. - endif. - endif. - enddo. - if found is initial. - exit. - endif. - delete currcells where left = -1. - enddo. -* Ende der Zusammenfassung - - -* item data: format for currency cell, corresponding with currency - - call method lo_spreadsheet->cell_format - EXPORTING - cells = currcells - no_flush = no_flush. - -* item data: write item table content - - call method lo_spreadsheet->set_ranges_data - EXPORTING - ranges = ranges - contents = contents - no_flush = no_flush. - -* whole table range to format all table - - if i_columns_header = 'X'. - li_head_top = li_commentary_rows + 1. - else. - li_head_top = li_commentary_rows + 2. - help = help - 1. - endif. - - call method lo_spreadsheet->insert_range_dim - EXPORTING - name = 'WHOLE_TABLE' - top = li_head_top - left = i_left - rows = help - columns = datareal - no_flush = no_flush. - -* columns width auto fix -* this parameter = space in case use with exist template - - IF i_columns_autofit = 'X'. - call method lo_spreadsheet->fit_widest - EXPORTING - name = 'WHOLE_TABLE' - no_flush = no_flush. - ENDIF. - -* frame -* The parameter has 8 bits -*0 Left margin -*1 Top marginT -*2 Bottom margin -*3 Right margin -*4 Horizontal line -*5 Vertical line -*6 Thinness -*7 Thickness -* here 127 = 1111111 6-5-4-3-2-1 mean Thin-ver-hor-right-bot-top-left - -* ( final DOI method call, set no_flush = space -* equal to call method CL_GUI_CFW=>FLUSH ) - - call method lo_spreadsheet->set_frame - EXPORTING - rangename = 'WHOLE_TABLE' - typ = 127 - color = 1 - no_flush = space - IMPORTING - error = lo_error - retcode = lc_retcode. - - error_doi. - -* reformat subtotal / total line after format wholw table - - loop at subranges into subrangeitem. - l_sub_index = subrangeitem-rows + li_commentary_rows + rowmax. - - call method lo_spreadsheet->insert_range_dim - EXPORTING - name = subrangeitem-name - left = i_left - top = l_sub_index - rows = 1 - columns = datareal - no_flush = no_flush. - - wa_format-name = subrangeitem-name. - -* default format: -* - clolor: subtotal = light yellow, subtotal = yellow -* - frame: box - - IF subrangeitem-name(3) = 'SUB'. - wa_format-back = 36. "subtotal line - wa_format_temp = i_format_subtotal. - else. - wa_format-back = 27. "total line - wa_format_temp = i_format_total. - endif. - wa_format-FRAMETYP = 79. - wa_format-FRAMEcolor = 1. - wa_format-number = -1. - wa_format-align = -1. - -* get subtoal + total format from intput parameter -* overwrite default format - - if wa_format_temp is not initial. - describe field wa_format_temp type l_typ components li_col_num. - do li_col_num times. - if sy-index ne 1. " dun map range name - assign component sy-index of structure wa_format_temp - to <f_source>. - if <f_source> is not initial. - assign component sy-index of structure wa_format to <f_des>. - <f_des> = <f_source>. - unassign: <f_des>. - endif. - unassign: <f_source>. - endif. - enddo. - - clear: li_col_num. - endif. - - append wa_format to lt_format. - clear: wa_format-name. - clear: l_sub_index. - clear: wa_format_temp. - - endloop. - - if lt_format[] is not initial. - call method lo_spreadsheet->set_ranges_format - EXPORTING - formattable = lt_format - no_flush = no_flush. - refresh: lt_format. - endif. -*--------------------------------------------------------------------* - call method lo_spreadsheet->screen_update - EXPORTING - updating = 'X'. - - call method c_oi_errors=>flush_errors. - - lo_error_w = l_error. - lc_retcode = lo_error_w->error_code. - -** catch no_flush -> led to dump ( optional ) -* go_error = l_error. -* gc_retcode = go_error->error_code. -* error_doi. - - clear: - lt_sema, - wa_sema, - lt_hkey, - wa_hkey, - lt_vkey, - wa_vkey, - l_n_hrz_keys, - l_n_att_cols, - l_n_vrt_keys, - count, - datac, - datareal, - vkeycount, - all, - mit, - li_col_pos, - li_col_num, - ranges, - rangeitem, - contents, - contentsitem, - semaitem, - hkeyitem, - vkeyitem, - li_commentary_rows, - l_retcode, - li_head_top, - <f_excel_tab>. - - clear: - lo_error_w. - - unassign: - <line>, - <item>, - <f_excel_tab>. - -*--------------------------------------------------------------------* -* SESSION 5: SAVE AND CLOSE FILE -*--------------------------------------------------------------------* - -* ex of save path: 'FILE://C:\temp\test.xlsx' - concatenate 'FILE://' I_save_path - into ls_path. - - call method lo_proxy->save_document_to_url - EXPORTING - no_flush = 'X' - url = ls_path - IMPORTING - error = lo_error - retcode = lc_retcode - CHANGING - document_size = li_document_size. - - error_doi. - -* if save successfully -> raise successful message -* message i499(sy) with 'Document is Exported to ' p_path. - message i499(sy) with 'Data has been exported successfully'. - - clear: - ls_path, - li_document_size. - - close_document. -endmethod. - - - - - - - - METHOD bind_table. -*--------------------------------------------------------------------* -* issue #230 - Pimp my Code -* - Stefan Schmöcker, (wi p) 2012-12-01 -* - ... -* aligning code -* message made to support multilinguality -*--------------------------------------------------------------------* -* issue #237 - Check if overlapping areas exist -* - Alessandro Iannacci 2012-12-01 -* changes: - Added raise if overlaps are detected -*--------------------------------------------------------------------* - - CONSTANTS: - lc_top_left_column TYPE zexcel_cell_column_alpha VALUE 'B', - lc_top_left_row TYPE zexcel_cell_row VALUE '3'. - - DATA: - lv_row_int TYPE zexcel_cell_row, - lv_first_row TYPE zexcel_cell_row, - lv_last_row TYPE zexcel_cell_row, - lv_column_int TYPE zexcel_cell_column, - lv_column_alpha TYPE zexcel_cell_column_alpha, - lt_field_catalog TYPE zexcel_t_fieldcatalog, - lv_id TYPE i, - lv_rows TYPE i, - lv_formula TYPE string, - ls_settings TYPE zexcel_s_table_settings, - lo_table TYPE REF TO zcl_excel_table, - lt_column_name_buffer TYPE SORTED TABLE OF string WITH UNIQUE KEY table_line, - lv_value TYPE string, - lv_syindex TYPE char3, - lv_errormessage TYPE string, "ins issue #237 - - lv_columns TYPE i, - lt_columns TYPE zexcel_t_fieldcatalog, - lv_maxcol TYPE i, - lv_maxrow TYPE i, - lo_iterator TYPE REF TO cl_object_collection_iterator, - lo_curtable TYPE REF TO zcl_excel_table. - - FIELD-SYMBOLS: - <ls_field_catalog> TYPE zexcel_s_fieldcatalog, - <ls_field_catalog_custom> TYPE zexcel_s_fieldcatalog, - <fs_table_line> TYPE ANY, - <fs_fldval> TYPE ANY. - - ls_settings = is_table_settings. - - IF ls_settings-top_left_column IS INITIAL. - ls_settings-top_left_column = lc_top_left_column. - ENDIF. - - IF ls_settings-table_style IS INITIAL. - ls_settings-table_style = zcl_excel_table=>builtinstyle_medium2. - ENDIF. - - IF ls_settings-top_left_row IS INITIAL. - ls_settings-top_left_row = lc_top_left_row. - ENDIF. - - IF it_field_catalog IS NOT SUPPLIED. - lt_field_catalog = zcl_excel_common=>get_fieldcatalog( ip_table = ip_table ). - ELSE. - lt_field_catalog = it_field_catalog. - ENDIF. - - SORT lt_field_catalog BY position. - -*--------------------------------------------------------------------* -* issue #237 Check if overlapping areas exist Start -*--------------------------------------------------------------------* - "Get the number of columns for the current table - lt_columns = lt_field_catalog. - DELETE lt_columns WHERE dynpfld NE abap_true. - DESCRIBE TABLE lt_columns LINES lv_columns. - - "Calculate the top left row of the current table - lv_column_int = zcl_excel_common=>convert_column2int( ls_settings-top_left_column ). - lv_row_int = ls_settings-top_left_row. - - "Get number of row for the current table - DESCRIBE TABLE ip_table LINES lv_rows. - - "Calculate the bottom right row for the current table - lv_maxcol = lv_column_int + lv_columns - 1. - lv_maxrow = lv_row_int + lv_rows - 1. - ls_settings-bottom_right_column = zcl_excel_common=>convert_column2alpha( lv_maxcol ). - ls_settings-bottom_right_row = lv_maxrow. - - lv_column_int = zcl_excel_common=>convert_column2int( ls_settings-top_left_column ). - - lo_iterator = me->tables->if_object_collection~get_iterator( ). - WHILE lo_iterator->if_object_collection_iterator~has_next( ) EQ abap_true. - - lo_curtable ?= lo_iterator->if_object_collection_iterator~get_next( ). - IF ( ( ls_settings-top_left_row GE lo_curtable->settings-top_left_row AND ls_settings-top_left_row LE lo_curtable->settings-bottom_right_row ) - OR - ( ls_settings-bottom_right_row GE lo_curtable->settings-top_left_row AND ls_settings-bottom_right_row LE lo_curtable->settings-bottom_right_row ) - ) - AND - ( ( lv_column_int GE zcl_excel_common=>convert_column2int( lo_curtable->settings-top_left_column ) AND lv_column_int LE zcl_excel_common=>convert_column2int( lo_curtable->settings-bottom_right_column ) ) - OR - ( lv_maxcol GE zcl_excel_common=>convert_column2int( lo_curtable->settings-top_left_column ) AND lv_maxcol LE zcl_excel_common=>convert_column2int( lo_curtable->settings-bottom_right_column ) ) - ). - lv_errormessage = 'Table overlaps with previously bound table and will not be added to worksheet.'(400). - RAISE EXCEPTION TYPE zcx_excel - EXPORTING - error = lv_errormessage. - ENDIF. - - ENDWHILE. -*--------------------------------------------------------------------* -* issue #237 Check if overlapping areas exist End -*--------------------------------------------------------------------* - - CREATE OBJECT lo_table. - lo_table->settings = ls_settings. - lo_table->set_data( ir_data = ip_table ). - lv_id = me->excel->get_next_table_id( ). - lo_table->set_id( iv_id = lv_id ). -* lo_table->fieldcat = lt_field_catalog[]. - - me->tables->add( lo_table ). - -* It is better to loop column by column (only visible column) - LOOP AT lt_field_catalog ASSIGNING <ls_field_catalog> WHERE dynpfld EQ abap_true. - - lv_column_alpha = zcl_excel_common=>convert_column2alpha( lv_column_int ). - - " Due restrinction of new table object we cannot have two column with the same name - " Check if a column with the same name exists, if exists add a counter - " If no medium description is provided we try to use small or long -* lv_value = <ls_field_catalog>-scrtext_m. - IF <ls_field_catalog>-scrtext_m IS NOT INITIAL. - lv_value = <ls_field_catalog>-scrtext_m. - <ls_field_catalog>-scrtext_l = lv_value. - ELSEIF <ls_field_catalog>-scrtext_s IS NOT INITIAL. - lv_value = <ls_field_catalog>-scrtext_s. - <ls_field_catalog>-scrtext_l = lv_value. - ELSEIF <ls_field_catalog>-scrtext_l IS NOT INITIAL. - lv_value = <ls_field_catalog>-scrtext_l. - ELSE. - lv_value = 'Column'. " default value as Excel does - <ls_field_catalog>-scrtext_l = lv_value. - ENDIF. - WHILE 1 = 1. - - READ TABLE lt_column_name_buffer TRANSPORTING NO FIELDS WITH KEY table_line = lv_value BINARY SEARCH. - IF sy-subrc <> 0. - <ls_field_catalog>-scrtext_l = lv_value. - INSERT lv_value INTO TABLE lt_column_name_buffer. - EXIT. - ELSE. - lv_syindex = sy-index. - CONCATENATE <ls_field_catalog>-scrtext_l lv_syindex INTO lv_value. - ENDIF. - - ENDWHILE. - " First of all write column header - IF <ls_field_catalog>-style_header IS NOT INITIAL. - me->set_cell( ip_column = lv_column_alpha - ip_row = lv_row_int - ip_value = lv_value - ip_style = <ls_field_catalog>-style_header ). - ELSE. - me->set_cell( ip_column = lv_column_alpha - ip_row = lv_row_int - ip_value = lv_value ). - ENDIF. - - ADD 1 TO lv_row_int. - LOOP AT ip_table ASSIGNING <fs_table_line>. - - ASSIGN COMPONENT <ls_field_catalog>-fieldname OF STRUCTURE <fs_table_line> TO <fs_fldval>. - " issue #290 Add formula support in table - IF <ls_field_catalog>-formula EQ abap_true. - IF <ls_field_catalog>-style IS NOT INITIAL. - me->set_cell( ip_column = lv_column_alpha - ip_row = lv_row_int - ip_formula = <fs_fldval> - ip_style = <ls_field_catalog>-style ). - ELSE. - me->set_cell( ip_column = lv_column_alpha - ip_row = lv_row_int - ip_formula = <fs_fldval> ). - ENDIF. - ELSE. - IF <ls_field_catalog>-style IS NOT INITIAL. - me->set_cell( ip_column = lv_column_alpha - ip_row = lv_row_int - ip_value = <fs_fldval> - ip_style = <ls_field_catalog>-style ). - ELSE. - me->set_cell( ip_column = lv_column_alpha - ip_row = lv_row_int - ip_value = <fs_fldval> ). - ENDIF. - ENDIF. - ADD 1 TO lv_row_int. - - ENDLOOP. - IF sy-subrc <> 0. "create empty row if table has no data - me->set_cell( ip_column = lv_column_alpha - ip_row = lv_row_int - ip_value = space ). - ADD 1 TO lv_row_int. - ENDIF. - -*--------------------------------------------------------------------* - " totals -*--------------------------------------------------------------------* - IF <ls_field_catalog>-totals_function IS NOT INITIAL. - lv_formula = lo_table->get_totals_formula( ip_column = <ls_field_catalog>-scrtext_l ip_function = <ls_field_catalog>-totals_function ). - IF <ls_field_catalog>-style_total IS NOT INITIAL. - me->set_cell( ip_column = lv_column_alpha - ip_row = lv_row_int - ip_formula = lv_formula - ip_style = <ls_field_catalog>-style_total ). - ELSE. - me->set_cell( ip_column = lv_column_alpha - ip_row = lv_row_int - ip_formula = lv_formula ). - ENDIF. - ENDIF. - - lv_row_int = ls_settings-top_left_row. - ADD 1 TO lv_column_int. - -*--------------------------------------------------------------------* - " conditional formatting -*--------------------------------------------------------------------* - IF <ls_field_catalog>-cond_style IS NOT INITIAL. - lv_first_row = ls_settings-top_left_row + 1. " +1 to exclude header - lv_last_row = ls_settings-top_left_row + lv_rows. - <ls_field_catalog>-cond_style->set_range( ip_start_column = lv_column_alpha - ip_start_row = lv_first_row - ip_stop_column = lv_column_alpha - ip_stop_row = lv_last_row ). - ENDIF. - - ENDLOOP. - -*--------------------------------------------------------------------* - " Set field catalog -*--------------------------------------------------------------------* - lo_table->fieldcat = lt_field_catalog[]. - - es_table_settings = ls_settings. - es_table_settings-bottom_right_column = lv_column_alpha. - " >> Issue #291 - IF ip_table IS INITIAL. - es_table_settings-bottom_right_row = ls_settings-top_left_row + 2. "Last rows - ELSE. - es_table_settings-bottom_right_row = ls_settings-top_left_row + lv_rows + 1. "Last rows - ENDIF. - " << Issue #291 - -ENDMETHOD. - - - - - - - method CALCULATE_CELL_WIDTH. - DATA: cell_value TYPE zexcel_cell_value, - guid TYPE zexcel_cell_style, - stylemapping TYPE zexcel_s_stylemapping. - - me->get_cell( EXPORTING ip_column = ip_column " Cell Column - ip_row = ip_row " Cell Row - IMPORTING ep_value = cell_value - ep_guid = guid )." Cell Value ). - - - ep_width = STRLEN( cell_value ). - TRY. - stylemapping = me->excel->get_style_to_guid( guid ). - CATCH zcx_excel. - EXIT. " Do nothing if no style was found - ENDTRY. - - IF stylemapping-complete_stylex-font-size = 'X'. - ep_width = ep_width * stylemapping-complete_style-font-size / 11. - ENDIF. - -endmethod. - - - - method CALCULATE_COLUMN_WIDTHS. - TYPES: - BEGIN OF t_auto_size, - col_index TYPE int4, - width TYPE float, - END OF t_auto_size. - TYPES: tt_auto_size TYPE TABLE OF t_auto_size. - - DATA: column_dimensions TYPE zexcel_t_worksheet_columndime. - DATA: column_dimension TYPE REF TO zcl_excel_worksheet_columndime. - - DATA: auto_size TYPE flag. - DATA: auto_sizes TYPE tt_auto_size. -* DATA: col_alpha TYPE zexcel_cell_column_alpha." issue #155 - less restrictive typing for ip_column - DATA: cell_value TYPE zexcel_cell_value. - DATA: cell_style TYPE REF TO zcl_excel_style. - DATA: count TYPE int4. - DATA: highest_row TYPE int4. - DATA: width TYPE i. - - FIELD-SYMBOLS: <column_dimension> LIKE LINE OF column_dimensions. - FIELD-SYMBOLS: <auto_size> LIKE LINE OF auto_sizes. - - column_dimensions[] = me->get_column_dimensions( ). - LOOP AT column_dimensions ASSIGNING <column_dimension>. - auto_size = <column_dimension>-column_dimension->get_auto_size( ). - IF auto_size = abap_true. - APPEND INITIAL LINE TO auto_sizes ASSIGNING <auto_size>. - <auto_size>-col_index = <column_dimension>-column_dimension->get_column_index( ). - <auto_size>-width = -1. - ENDIF. - ENDLOOP. - - " There is only something to do if there are some auto-size columns - IF NOT auto_sizes IS INITIAL. - highest_row = me->get_highest_row( ). - LOOP AT auto_sizes ASSIGNING <auto_size>. -* col_alpha = zcl_excel_common=>convert_column2alpha( <auto_size>-col_index )." issue #155 - less restrictive typing for ip_column - count = 1. - WHILE count <= highest_row. -* Start of change # issue 139 - Dateretention of cellstyles -* IF cell_style IS BOUND. -* CREATE OBJECT cell_style. -* ENDIF. -* me->get_cell( -* EXPORTING -* ip_column = col_alpha " Cell Column -* ip_row = count " Cell Row -* IMPORTING -* ep_value = cell_value " Cell Value -* ep_style = cell_style " Request Cell Style as well -* ). -* " For an easy start we just take the number of characters as the width -* width = strlen( cell_value ). -* " Addition to solve issue #120, contribution by Stefan Schm#ƒÂ#cker -* " Calculate width using Font Size and Font Type -* IF cell_style IS BOUND -* AND cell_style->font IS BOUND. -* width = cell_style->font->calculate_text_width( cell_value ). -* ENDIF. -* width = calculate_cell_width( ip_column = col_alpha " issue #155 - less restrictive typing for ip_column - width = calculate_cell_width( ip_column = <auto_size>-col_index " issue #155 - less restrictive typing for ip_column - ip_row = count ). -* End of change # issue 139 - Dateretention of cellstyles - IF width > <auto_size>-width. - <auto_size>-width = width. - ENDIF. - count = count + 1. - ENDWHILE. -* column_dimension = me->get_column_dimension( col_alpha ). " issue #155 - less restrictive typing for ip_column - column_dimension = me->get_column_dimension( <auto_size>-col_index ). " issue #155 - less restrictive typing for ip_column - column_dimension->set_width( <auto_size>-width ). - ENDLOOP. - ENDIF. - -endmethod. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - method CHANGE_CELL_STYLE. - " issue # 139 - 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, - l_guid TYPE zexcel_cell_style. "issue # 177 - -* 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 = l_guid )." Cell Value ). "issue # 177 - - - stylemapping = me->excel->get_style_to_guid( l_guid ). "issue # 177 - complete_style = stylemapping-complete_style. - complete_stylex = stylemapping-complete_stylex. - CATCH zcx_excel. -* Error --> use submitted style - ENDTRY. - -* 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->excel->get_static_cellstyle_guid( ip_cstyle_complete = complete_style - ip_cstylex_complete = complete_stylex ). - me->set_cell_style( ip_column = ip_column - ip_row = ip_row - ip_style = ep_guid ). - -endmethod. - - - - - - method CONSTRUCTOR. - DATA: lv_title TYPE zexcel_sheet_title. - - me->excel = ip_excel. - - CALL FUNCTION 'GUID_CREATE' - IMPORTING - ev_guid_16 = me->guid. - - IF ip_title IS NOT INITIAL. - lv_title = ip_title. - ELSE. -* 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 ). - - CREATE OBJECT sheet_setup. - CREATE OBJECT conditional_styles. - CREATE OBJECT data_validations. - CREATE OBJECT tables. - CREATE OBJECT ranges. " issue #163 - CREATE OBJECT drawings - EXPORTING - ip_type = zcl_excel_drawing=>type_image. - CREATE OBJECT charts - EXPORTING - ip_type = zcl_excel_drawing=>type_chart. - me->zif_excel_sheet_protection~initialize( ). - me->zif_excel_sheet_properties~initialize( ). - CREATE OBJECT hyperlinks. - -* initialize active cell coordinates - active_cell-cell_row = 1. - active_cell-cell_column = 1. - -* inizialize dimension range - lower_cell-cell_row = 1. - lower_cell-cell_column = 1. - upper_cell-cell_row = 1. - upper_cell-cell_column = 1. - -endmethod. - - - method DELETE_MERGE. - - DELETE sheet_content_merge INDEX 1. - DELETE sheet_content_merge INDEX 1. - -endmethod. - - - - - - method FREEZE_PANES. - data: lv_xsplit type i, - lv_ysplit type i. - - IF ip_num_columns IS NOT SUPPLIED AND ip_num_rows IS NOT SUPPLIED. - RAISE EXCEPTION TYPE zcx_excel - EXPORTING - error = 'Pleas provide number of rows and/or columns to freeze'. - ENDIF. - - IF ip_num_columns IS SUPPLIED AND ip_num_columns <= 0. - RAISE EXCEPTION TYPE zcx_excel - EXPORTING - error = 'Number of columns to freeze should be positive'. - ENDIF. - - IF ip_num_rows IS SUPPLIED AND ip_num_rows <= 0. - RAISE EXCEPTION TYPE zcx_excel - EXPORTING - error = 'Number of rows to freeze should be positive'. - ENDIF. - - 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( ) = abap_true. - 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. - CONCATENATE 'Sheet'(001) title INTO ep_title. - 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. - - - - - method GET_ACTIVE_CELL. - - DATA: lv_active_column TYPE zexcel_cell_column_alpha, - lv_active_row TYPE string. - - lv_active_column = zcl_excel_common=>convert_column2alpha( active_cell-cell_column ). - lv_active_row = active_cell-cell_row. - SHIFT lv_active_row RIGHT DELETING TRAILING space. - SHIFT lv_active_row LEFT DELETING LEADING space. - CONCATENATE lv_active_column lv_active_row INTO ep_active_cell. - -endmethod. - - - - - - - - - - method GET_CELL. - - DATA: lv_column TYPE zexcel_cell_column, - ls_sheet_content TYPE zexcel_s_cell_data. - - FIELD-SYMBOLS: <fs_sheet_content> TYPE zexcel_s_cell_data. - - lv_column = zcl_excel_common=>convert_column2int( ip_column ). - - READ TABLE sheet_content INTO ls_sheet_content WITH TABLE KEY cell_row = ip_row - cell_column = lv_column. - - ep_rc = sy-subrc. - ep_value = ls_sheet_content-cell_value. - ep_guid = ls_sheet_content-cell_style. " issue 139 - added this to be used for columnwidth calculation - - " Addition to solve issue #120, contribution by Stefan Schm#ƒÂ#cker - DATA: style_iterator TYPE REF TO cl_object_collection_iterator, - style TYPE REF TO zcl_excel_style. - IF ep_style IS REQUESTED. - style_iterator = me->excel->get_styles_iterator( ). - WHILE style_iterator->has_next( ) = 'X'. - style ?= style_iterator->get_next( ). - IF style->get_guid( ) = ls_sheet_content-cell_style. - ep_style = style. - EXIT. - ENDIF. - ENDWHILE. - ENDIF. -endmethod. - - - - - - 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 - - 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> - WITH KEY column = lv_column_alpha. " issue #155 - less restrictive typing for ip_column - - 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_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. - ELSE. - r_column_dimension = <fs_column_dimension>-column_dimension. - ENDIF. - -endmethod. - - - - method GET_COLUMN_DIMENSIONS. - r_column_dimension[] = me->column_dimensions[]. -endmethod. - - - - method GET_COND_STYLES_ITERATOR. - - eo_iterator = me->conditional_styles->get_iterator( ). -endmethod. - - - - method GET_DATA_VALIDATIONS_ITERATOR. - - eo_iterator = me->data_validations->get_iterator( ). -endmethod. - - - - method GET_DATA_VALIDATIONS_SIZE. - ep_size = me->data_validations->size( ). -endmethod. - - - - method GET_DEFAULT_COLUMN_DIMENSION. - IF me->default_column_dimension IS NOT BOUND. - CREATE OBJECT me->default_column_dimension - EXPORTING - ip_index = 'A' " ???? - ip_worksheet = me - ip_excel = me->excel. - ENDIF. - - r_column_dimension = me->default_column_dimension. -endmethod. - - - - method GET_DEFAULT_EXCEL_DATE_FORMAT. - CONSTANTS: c_lang_e TYPE lang VALUE 'E'. - - IF default_excel_date_format IS NOT INITIAL. - ep_default_excel_date_format = default_excel_date_format. - RETURN. - ENDIF. - - "try to get defaults - TRY. - cl_abap_datfm=>get_date_format_des( EXPORTING im_langu = c_lang_e - IMPORTING ex_dateformat = default_excel_date_format ). - CATCH cx_abap_datfm_format_unknown. - - ENDTRY. - - " and fallback to fixed format - IF default_excel_date_format IS INITIAL. - default_excel_date_format = zcl_excel_style_number_format=>c_format_date_ddmmyyyydot. - ENDIF. - - ep_default_excel_date_format = default_excel_date_format. -endmethod. - - - - method GET_DEFAULT_EXCEL_TIME_FORMAT. - DATA: l_timefm TYPE xutimefm. - - IF default_excel_time_format IS NOT INITIAL. - ep_default_excel_time_format = default_excel_time_format. - RETURN. - ENDIF. - -* Let's get default - l_timefm = cl_abap_timefm=>get_environment_timefm( ). - CASE l_timefm. - WHEN 0. -*0 24 Hour Format (Example: 12:05:10) - default_excel_time_format = zcl_excel_style_number_format=>c_format_date_time6. - WHEN 1. -*1 12 Hour Format (Example: 12:05:10 PM) - default_excel_time_format = zcl_excel_style_number_format=>c_format_date_time2. - WHEN 2. -*2 12 Hour Format (Example: 12:05:10 pm) for now all the same. no chnage upper lower - default_excel_time_format = zcl_excel_style_number_format=>c_format_date_time2. - WHEN 3. -*3 Hours from 0 to 11 (Example: 00:05:10 PM) for now all the same. no chnage upper lower - default_excel_time_format = zcl_excel_style_number_format=>c_format_date_time2. - WHEN 4. -*4 Hours from 0 to 11 (Example: 00:05:10 pm) for now all the same. no chnage upper lower - default_excel_time_format = zcl_excel_style_number_format=>c_format_date_time2. - WHEN OTHERS. - " and fallback to fixed format - default_excel_time_format = zcl_excel_style_number_format=>c_format_date_time6. - ENDCASE. - - ep_default_excel_time_format = default_excel_time_format. -endmethod. - - - - method GET_DEFAULT_ROW_DIMENSION. - IF me->default_row_dimension IS NOT BOUND. - CREATE OBJECT me->default_row_dimension. - ENDIF. - - r_row_dimension = me->default_row_dimension. -endmethod. - - - - - method GET_DIMENSION_RANGE. - - me->update_dimension_range( ). - IF upper_cell EQ lower_cell. "only one cell - " Worksheet not filled -* IF upper_cell-cell_coords = '0'. - IF upper_cell-cell_coords IS INITIAL. - ep_dimension_range = 'A1'. - ELSE. - ep_dimension_range = upper_cell-cell_coords. - ENDIF. - ELSE. - CONCATENATE upper_cell-cell_coords ':' lower_cell-cell_coords INTO ep_dimension_range. - ENDIF. - -endmethod. - - - - - method GET_DRAWINGS. - - DATA: lo_drawing TYPE REF TO zcl_excel_drawing, - lo_iterator TYPE REF TO cl_object_collection_iterator. - - CASE ip_type. - WHEN zcl_excel_drawing=>type_image. - r_drawings = drawings. - WHEN zcl_excel_drawing=>type_chart. - r_drawings = charts. - WHEN space. - CREATE OBJECT r_drawings - EXPORTING - ip_type = ''. - - lo_iterator = drawings->get_iterator( ). - WHILE lo_iterator->has_next( ) = abap_true. - lo_drawing ?= lo_iterator->get_next( ). - r_drawings->include( lo_drawing ). - ENDWHILE. - lo_iterator = charts->get_iterator( ). - WHILE lo_iterator->has_next( ) = abap_true. - lo_drawing ?= lo_iterator->get_next( ). - r_drawings->include( lo_drawing ). - ENDWHILE. - WHEN OTHERS. - ENDCASE. -endmethod. - - - - - method GET_DRAWINGS_ITERATOR. - CASE ip_type. - WHEN zcl_excel_drawing=>type_image. - eo_iterator = drawings->get_iterator( ). - WHEN zcl_excel_drawing=>type_chart. - eo_iterator = charts->get_iterator( ). - ENDCASE. -endmethod. - - - - - method GET_FREEZE_CELL. - ep_row = me->freeze_pane_cell_row. - ep_column = me->freeze_pane_cell_column. -endmethod. - - - - method GET_GUID. - - ep_guid = me->guid. - -endmethod. - - - - - method GET_HIGHEST_COLUMN. - me->update_dimension_range( ). - r_highest_column = me->lower_cell-cell_column. -endmethod. - - - - - method GET_HIGHEST_ROW. - me->update_dimension_range( ). - r_highest_row = me->lower_cell-cell_row. -endmethod. - - - - method GET_HYPERLINKS_ITERATOR. - eo_iterator = hyperlinks->get_iterator( ). -endmethod. - - - - method GET_HYPERLINKS_SIZE. - ep_size = hyperlinks->size( ). -endmethod. - - - - - method GET_MERGE. - - DATA: lv_column_start TYPE string, - lv_column_end TYPE string, - lv_row TYPE string, - lv_index TYPE sy-tabix, - ls_sheet_content TYPE zexcel_s_cell_data, - range_from TYPE string, - range_to TYPE string, - lv_merge_range TYPE string, - lv_count TYPE string. - - FIELD-SYMBOLS: <fs_sheet_content> TYPE zexcel_s_cell_data. - - DESCRIBE TABLE sheet_content_merge LINES lv_count. - - WHILE lv_count GT lv_index. -* LOOP AT sheet_content_merge ASSIGNING <fs_sheet_content>. - lv_index = lv_index + 1. - READ TABLE sheet_content_merge ASSIGNING <fs_sheet_content> INDEX lv_index. - lv_column_start = zcl_excel_common=>convert_column2alpha( <fs_sheet_content>-cell_column ). - lv_row = <fs_sheet_content>-cell_row. - SHIFT lv_column_start RIGHT DELETING TRAILING space. - SHIFT lv_column_start LEFT DELETING LEADING space. - SHIFT lv_row RIGHT DELETING TRAILING space. - SHIFT lv_row LEFT DELETING LEADING space. - CONCATENATE lv_column_start lv_row - INTO range_from. - - lv_index = lv_index + 1. - READ TABLE sheet_content_merge ASSIGNING <fs_sheet_content> INDEX lv_index. - lv_column_end = zcl_excel_common=>convert_column2alpha( <fs_sheet_content>-cell_column ). - lv_row = <fs_sheet_content>-cell_row. - SHIFT lv_column_end RIGHT DELETING TRAILING space. - SHIFT lv_column_end LEFT DELETING LEADING space. - SHIFT lv_row RIGHT DELETING TRAILING space. - SHIFT lv_row LEFT DELETING LEADING space. - CONCATENATE lv_column_end lv_row - INTO range_to. - - CONCATENATE range_from range_to INTO lv_merge_range - SEPARATED BY ':'. - APPEND lv_merge_range TO merge_range. - ENDWHILE. -* ENDLOOP. - -* READ TABLE sheet_content_merge ASSIGNING <fs_sheet_content> INDEX 1. -* IF sy-subrc EQ 0 AND <fs_sheet_content> IS ASSIGNED. -* lv_column_start = zcl_excel_common=>convert_column2alpha( <fs_sheet_content>-cell_column ). -* lv_row = <fs_sheet_content>-cell_row. -* SHIFT lv_column_start RIGHT DELETING TRAILING space. -* SHIFT lv_column_start LEFT DELETING LEADING space. -* SHIFT lv_row RIGHT DELETING TRAILING space. -* SHIFT lv_row LEFT DELETING LEADING space. -* CONCATENATE lv_column_start lv_row -* INTO range_from. -* ENDIF. -* READ TABLE sheet_content_merge ASSIGNING <fs_sheet_content> INDEX 2. -* IF sy-subrc EQ 0 AND <fs_sheet_content> IS ASSIGNED. -* lv_column_end = zcl_excel_common=>convert_column2alpha( <fs_sheet_content>-cell_column ). -* SHIFT lv_column_end RIGHT DELETING TRAILING space. -* SHIFT lv_column_end LEFT DELETING LEADING space. -* CONCATENATE lv_column_end lv_row -* INTO range_to. -* ENDIF. - -* IF range_from NE space AND range_to NE space. -* CONCATENATE range_from range_to INTO ep_merge_range -* SEPARATED BY ':'. -* ENDIF. - -endmethod. - - - - method GET_RANGES_ITERATOR. - - eo_iterator = me->ranges->get_iterator( ). - -endmethod. - - - - - method GET_ROW_DIMENSION. - FIELD-SYMBOLS: <fs_row_dimension> LIKE LINE OF row_dimensions. - - READ TABLE me->row_dimensions ASSIGNING <fs_row_dimension> - WITH KEY row = ip_row. - - IF NOT <fs_row_dimension> IS ASSIGNED. - CREATE OBJECT r_row_dimension - EXPORTING - ip_index = ip_row. - APPEND INITIAL LINE TO me->row_dimensions ASSIGNING <fs_row_dimension>. - <fs_row_dimension>-row = ip_row. - <fs_row_dimension>-row_dimension = r_row_dimension. - ELSE. - r_row_dimension = <fs_row_dimension>-row_dimension. - ENDIF. - -endmethod. - - - - method GET_ROW_DIMENSIONS. - r_row_dimension[] = me->row_dimensions[]. -endmethod. - - - - method GET_TABCOLOR. - ev_tabcolor = me->tabcolor. -endmethod. - - - - method GET_TABLES_ITERATOR. - eo_iterator = tables->if_object_collection~get_iterator( ). -endmethod. - - - - method GET_TABLES_SIZE. - ep_size = tables->if_object_collection~size( ). -endmethod. - - - - - method GET_TITLE. - DATA lv_value TYPE string. - IF ip_escaped EQ abap_true. - lv_value = me->title. - ep_title = zcl_excel_common=>escape_string( lv_value ). - ELSE. - ep_title = me->title. - ENDIF. -endmethod. - - - - - - method GET_VALUE_TYPE. - DATA: lo_addit TYPE REF TO cl_abap_elemdescr, - ls_dfies TYPE dfies, - l_function TYPE funcname, - l_value(50) TYPE c. - - ep_value = ip_value. - ep_value_type = cl_abap_typedescr=>typekind_string. " Thats our default if something goes wrong. - - TRY. - lo_addit ?= cl_abap_typedescr=>describe_by_data( ip_value ). - CATCH cx_sy_move_cast_error. - CLEAR lo_addit. - ENDTRY. - IF lo_addit IS BOUND. - lo_addit->get_ddic_field( RECEIVING p_flddescr = ls_dfies - EXCEPTIONS not_found = 1 - no_ddic_type = 2 - OTHERS = 3 ) . - IF sy-subrc = 0. - ep_value_type = ls_dfies-inttype. - - IF ls_dfies-convexit IS NOT INITIAL. -* We need to convert with output conversion function - CONCATENATE 'CONVERSION_EXIT_' ls_dfies-convexit '_OUTPUT' INTO l_function. - SELECT SINGLE funcname INTO l_function - FROM tfdir - WHERE funcname = l_function. - IF sy-subrc = 0. - CALL FUNCTION l_function - EXPORTING - input = ip_value - IMPORTING -* LONG_TEXT = - output = l_value -* SHORT_TEXT = - EXCEPTIONS - OTHERS = 1. - IF sy-subrc <> 0. -* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO -* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. - ELSE. - ep_value = l_value. - ENDIF. - ENDIF. - ENDIF. - ELSE. - ep_value_type = lo_addit->get_data_type_kind( ip_value ). - ENDIF. - ENDIF. - -endmethod. - - - method PRINT_TITLE_SET_RANGE. -*--------------------------------------------------------------------* -* issue#235 - repeat rows/columns -* - Stefan Schmöcker, 2012-12-02 -*--------------------------------------------------------------------* - - - DATA: lo_range_iterator TYPE REF TO cl_object_collection_iterator, - lo_range TYPE REF TO zcl_excel_range, - lv_repeat_range_sheetname TYPE string, - lv_repeat_range_col TYPE string, - lv_row_char_from TYPE char10, - lv_row_char_to TYPE char10, - lv_repeat_range_row TYPE string, - lv_repeat_range TYPE string. - - -*--------------------------------------------------------------------* -* Get range that represents printarea -* if non-existant, create it -*--------------------------------------------------------------------* - lo_range_iterator = me->get_ranges_iterator( ). - WHILE lo_range_iterator->has_next( ) = abap_true. - - lo_range ?= lo_range_iterator->get_next( ). - IF lo_range->name = zif_excel_sheet_printsettings=>gcv_print_title_name. - EXIT. " Found it - ENDIF. - CLEAR lo_range. - - ENDWHILE. - - - IF me->print_title_col_from IS INITIAL AND - me->print_title_row_from IS INITIAL. -*--------------------------------------------------------------------* -* No print titles are present, -*--------------------------------------------------------------------* - IF lo_range IS BOUND. - me->ranges->remove( lo_range ). - ENDIF. - ELSE. -*--------------------------------------------------------------------* -* Print titles are present, -*--------------------------------------------------------------------* - IF lo_range IS NOT BOUND. - lo_range = me->add_new_range( ). - lo_range->name = zif_excel_sheet_printsettings=>gcv_print_title_name. - ENDIF. - - lv_repeat_range_sheetname = me->get_title( ). - lv_repeat_range_sheetname = zcl_excel_common=>escape_string( lv_repeat_range_sheetname ). - -*--------------------------------------------------------------------* -* Repeat-columns -*--------------------------------------------------------------------* - IF me->print_title_col_from IS NOT INITIAL. - CONCATENATE lv_repeat_range_sheetname - '!$' me->print_title_col_from - ':$' me->print_title_col_to - INTO lv_repeat_range_col. - ENDIF. - -*--------------------------------------------------------------------* -* Repeat-rows -*--------------------------------------------------------------------* - IF me->print_title_row_from IS NOT INITIAL. - lv_row_char_from = me->print_title_row_from. - lv_row_char_to = me->print_title_row_to. - CONCATENATE '!$' lv_row_char_from - ':$' lv_row_char_to - INTO lv_repeat_range_row. - CONDENSE lv_repeat_range_row NO-GAPS. - CONCATENATE lv_repeat_range_sheetname - lv_repeat_range_row - INTO lv_repeat_range_row. - ENDIF. - -*--------------------------------------------------------------------* -* Concatenate repeat-rows and columns -*--------------------------------------------------------------------* - IF lv_repeat_range_col IS INITIAL. - lv_repeat_range = lv_repeat_range_row. - ELSEIF lv_repeat_range_row IS INITIAL. - lv_repeat_range = lv_repeat_range_col. - ELSE. - CONCATENATE lv_repeat_range_col lv_repeat_range_row - INTO lv_repeat_range SEPARATED BY ','. - ENDIF. - - - lo_range->set_range_value( lv_repeat_range ). - ENDIF. - - - -endmethod. - - - - - - - - - - - - method SET_CELL. - - DATA: lv_column TYPE zexcel_cell_column, - ls_sheet_content TYPE zexcel_s_cell_data, - lv_row_alpha TYPE string, - lv_col_alpha TYPE zexcel_cell_column_alpha, - lv_value TYPE zexcel_cell_value, - lv_data_type TYPE zexcel_cell_data_type, - lv_value_type TYPE abap_typekind, - lo_style TYPE REF TO zcl_excel_style, - lv_style_guid TYPE zexcel_cell_style, - lo_addit TYPE REF TO cl_abap_elemdescr, - lo_value TYPE REF TO data, - lo_value_new TYPE REF TO data. - - FIELD-SYMBOLS: <fs_sheet_content> TYPE zexcel_s_cell_data, - <fs_numeric> TYPE numeric, - <fs_date> TYPE d, - <fs_time> TYPE t, - <fs_value> TYPE simple. - - IF ip_value IS NOT SUPPLIED AND ip_formula IS NOT SUPPLIED. - RAISE EXCEPTION TYPE zcx_excel - EXPORTING - error = 'Please provide the value or formula'. - ENDIF. - -* Begin of change issue #152 - don't touch exisiting style if only value is passed -* lv_style_guid = ip_style. - lv_column = zcl_excel_common=>convert_column2int( ip_column ). - READ TABLE sheet_content ASSIGNING <fs_sheet_content> WITH TABLE KEY cell_row = ip_row " Changed to access via table key , Stefan Schmöcker, 2013-08-03 - cell_column = lv_column. - IF sy-subrc = 0. - IF ip_style IS INITIAL. - " If no style is provided as method-parameter and cell is found use cell's current style - lv_style_guid = <fs_sheet_content>-cell_style. - ELSE. - " Style provided as method-parameter --> use this - lv_style_guid = ip_style. - ENDIF. - ELSE. - " No cell found --> use supplied style even if empty - lv_style_guid = ip_style. - ENDIF. -* End of change issue #152 - don't touch exisiting style if only value is passed - - IF ip_value IS SUPPLIED. - "if data type is passed just write the value. Otherwise map abap type to excel and perform conversion - "IP_DATA_TYPE is passed by excel reader so source types are preserved -*First we get reference into local var. - CREATE DATA lo_value LIKE ip_value. - ASSIGN lo_value->* TO <fs_value>. - <fs_value> = ip_value. - IF ip_data_type IS SUPPLIED. - IF ip_abap_type IS NOT SUPPLIED. - get_value_type( EXPORTING ip_value = ip_value - IMPORTING ep_value = <fs_value> ) . - ENDIF. - lv_value = <fs_value>. - lv_data_type = ip_data_type. - ELSE. - IF ip_abap_type IS SUPPLIED. - lv_value_type = ip_abap_type. - ELSE. - get_value_type( EXPORTING ip_value = ip_value - IMPORTING ep_value = <fs_value> - ep_value_type = lv_value_type ). - ENDIF. - CASE lv_value_type. - WHEN cl_abap_typedescr=>typekind_int OR cl_abap_typedescr=>typekind_int1 OR cl_abap_typedescr=>typekind_int2. - lo_addit = cl_abap_elemdescr=>get_i( ). - CREATE DATA lo_value_new TYPE HANDLE lo_addit. - ASSIGN lo_value_new->* TO <fs_numeric>. - IF sy-subrc = 0. - <fs_numeric> = <fs_value>. - lv_value = zcl_excel_common=>number_to_excel_string( ip_value = <fs_numeric> ). - ENDIF. - - WHEN cl_abap_typedescr=>typekind_float OR cl_abap_typedescr=>typekind_packed. - lo_addit = cl_abap_elemdescr=>get_f( ). - CREATE DATA lo_value_new TYPE HANDLE lo_addit. - ASSIGN lo_value_new->* TO <fs_numeric>. - IF sy-subrc = 0. - <fs_numeric> = <fs_value>. - lv_value = zcl_excel_common=>number_to_excel_string( ip_value = <fs_numeric> ). - ENDIF. - - WHEN cl_abap_typedescr=>typekind_char OR cl_abap_typedescr=>typekind_string OR cl_abap_typedescr=>typekind_num OR - cl_abap_typedescr=>typekind_hex. - lv_value = <fs_value>. - lv_data_type = 's'. - - WHEN cl_abap_typedescr=>typekind_date. - lo_addit = cl_abap_elemdescr=>get_d( ). - CREATE DATA lo_value_new TYPE HANDLE lo_addit. - ASSIGN lo_value_new->* TO <fs_date>. - IF sy-subrc = 0. - <fs_date> = <fs_value>. - lv_value = zcl_excel_common=>date_to_excel_string( ip_value = <fs_date> ) . - ENDIF. -* Begin of change issue #152 - don't touch exisiting style if only value is passed -* Moved to end of routine - apply date-format even if other styleinformation is passed -* IF ip_style IS NOT SUPPLIED. "get default date format in case parameter is initial -* lo_style = excel->add_new_style( ). -* lo_style->number_format->format_code = get_default_excel_date_format( ). -* lv_style_guid = lo_style->get_guid( ). -* ENDIF. -* End of change issue #152 - don't touch exisiting style if only value is passed - - WHEN cl_abap_typedescr=>typekind_time. - lo_addit = cl_abap_elemdescr=>get_t( ). - CREATE DATA lo_value_new TYPE HANDLE lo_addit. - ASSIGN lo_value_new->* TO <fs_time>. - IF sy-subrc = 0. - <fs_time> = <fs_value>. - lv_value = zcl_excel_common=>time_to_excel_string( ip_value = <fs_time> ). - ENDIF. -* Begin of change issue #152 - don't touch exisiting style if only value is passed -* Moved to end of routine - apply time-format even if other styleinformation is passed -* IF ip_style IS NOT SUPPLIED. "get default time format for user in case parameter is initial -* lo_style = excel->add_new_style( ). -* lo_style->number_format->format_code = zcl_excel_style_number_format=>c_format_date_time6. -* lv_style_guid = lo_style->get_guid( ). -* ENDIF. -* End of change issue #152 - don't touch exisiting style if only value is passed - - WHEN OTHERS. - RAISE EXCEPTION TYPE zcx_excel - EXPORTING - error = 'Invalid data type of input value'. - ENDCASE. - ENDIF. - - ENDIF. - - IF ip_hyperlink IS BOUND. - ip_hyperlink->set_cell_reference( ip_column = ip_column - ip_row = ip_row ). - me->hyperlinks->add( ip_hyperlink ). - ENDIF. - -* Begin of change issue #152 - don't touch exisiting style if only value is passed -* Read table moved up, so that current style may be evaluated -* lv_column = zcl_excel_common=>convert_column2int( ip_column ). - -* READ TABLE sheet_content ASSIGNING <fs_sheet_content> WITH KEY cell_row = ip_row -* cell_column = lv_column. -* -* IF sy-subrc EQ 0. - IF <fs_sheet_content> IS ASSIGNED. -* End of change issue #152 - don't touch exisiting style if only value is passed - <fs_sheet_content>-cell_value = lv_value. - <fs_sheet_content>-cell_formula = ip_formula. - <fs_sheet_content>-cell_style = lv_style_guid. - <fs_sheet_content>-data_type = lv_data_type. - ELSE. - ls_sheet_content-cell_row = ip_row. - ls_sheet_content-cell_column = lv_column. - ls_sheet_content-cell_value = lv_value. - ls_sheet_content-cell_formula = ip_formula. - ls_sheet_content-cell_style = lv_style_guid. - ls_sheet_content-data_type = lv_data_type. - lv_row_alpha = ip_row. -* SHIFT lv_row_alpha RIGHT DELETING TRAILING space."del #152 - replaced with condense - should be faster -* SHIFT lv_row_alpha LEFT DELETING LEADING space. "del #152 - replaced with condense - should be faster - CONDENSE lv_row_alpha NO-GAPS. "ins #152 - replaced 2 shifts - should be faster - lv_col_alpha = zcl_excel_common=>convert_column2alpha( ip_column ). " issue #155 - less restrictive typing for ip_column - CONCATENATE lv_col_alpha lv_row_alpha INTO ls_sheet_content-cell_coords. " issue #155 - less restrictive typing for ip_column - INSERT ls_sheet_content INTO TABLE sheet_content ASSIGNING <fs_sheet_content>. "ins #152 - Now <fs_sheet_content> always holds the data -* APPEND ls_sheet_content TO sheet_content. -* SORT sheet_content BY cell_row cell_column. - " me->update_dimension_range( ). - - ENDIF. - -* Begin of change issue #152 - don't touch exisiting style if only value is passed -* For Date- or Timefields change the formatcode if nothing is set yet -* Enhancement option: Check if existing formatcode is a date/ or timeformat -* If not, use default - DATA: lo_format_code_datetime TYPE zexcel_number_format. - DATA: stylemapping TYPE zexcel_s_stylemapping. - CASE lv_value_type. - WHEN cl_abap_typedescr=>typekind_date. - TRY. - stylemapping = me->excel->get_style_to_guid( <fs_sheet_content>-cell_style ). - CATCH zcx_excel . - ENDTRY. - IF stylemapping-complete_stylex-number_format-format_code IS INITIAL OR - stylemapping-complete_style-number_format-format_code IS INITIAL. - lo_format_code_datetime = zcl_excel_style_number_format=>c_format_date_std. - ELSE. - lo_format_code_datetime = stylemapping-complete_style-number_format-format_code. - ENDIF. - me->change_cell_style( ip_column = ip_column - ip_row = ip_row - ip_number_format_format_code = lo_format_code_datetime ). - - WHEN cl_abap_typedescr=>typekind_time. - TRY. - stylemapping = me->excel->get_style_to_guid( <fs_sheet_content>-cell_style ). - CATCH zcx_excel . - ENDTRY. - IF stylemapping-complete_stylex-number_format-format_code IS INITIAL OR - stylemapping-complete_style-number_format-format_code IS INITIAL. - lo_format_code_datetime = zcl_excel_style_number_format=>c_format_date_time6. - ELSE. - lo_format_code_datetime = stylemapping-complete_style-number_format-format_code. - ENDIF. - me->change_cell_style( ip_column = ip_column - ip_row = ip_row - ip_number_format_format_code = lo_format_code_datetime ). - - ENDCASE. -* End of change issue #152 - don't touch exisiting style if only value is passed - -* Fix issue #162 - lv_value = ip_value. - IF lv_value CS cl_abap_char_utilities=>cr_lf. - me->change_cell_style( ip_column = ip_column - ip_row = ip_row - ip_alignment_wraptext = abap_true ). - ENDIF. -* End of Fix issue #162 - -endmethod. - - - - - - - METHOD set_cell_formula. - DATA: - lv_column TYPE zexcel_cell_column, - ls_sheet_content LIKE LINE OF me->sheet_content. - - FIELD-SYMBOLS: - <sheet_content> LIKE LINE OF me->sheet_content. - -*--------------------------------------------------------------------* -* Get cell to set formula into -*--------------------------------------------------------------------* - lv_column = zcl_excel_common=>convert_column2int( ip_column ). - READ TABLE me->sheet_content ASSIGNING <sheet_content> WITH TABLE KEY cell_row = ip_row - cell_column = lv_column. - IF sy-subrc <> 0. " Create new entry in sheet_content if necessary - CHECK ip_formula IS INITIAL. " no need to create new entry in sheet_content when no formula is passed - ls_sheet_content-cell_row = ip_row. - ls_sheet_content-cell_column = lv_column. - INSERT ls_sheet_content INTO TABLE me->sheet_content ASSIGNING <sheet_content>. - ENDIF. - -*--------------------------------------------------------------------* -* Fieldsymbol now holds the relevant cell -*--------------------------------------------------------------------* - <sheet_content>-cell_formula = ip_formula. - - -ENDMETHOD. - - - - - - - method SET_CELL_STYLE. - - DATA: lv_column TYPE zexcel_cell_column, - ls_sheet_content TYPE zexcel_s_cell_data, - lv_row_alpha TYPE string, - lo_style TYPE REF TO zcl_excel_style, - lv_style_guid TYPE zexcel_cell_style. - - FIELD-SYMBOLS: <fs_sheet_content> TYPE zexcel_s_cell_data. - - lv_style_guid = ip_style. - - lv_column = zcl_excel_common=>convert_column2int( ip_column ). - - READ TABLE sheet_content ASSIGNING <fs_sheet_content> WITH KEY cell_row = ip_row - cell_column = lv_column. - - IF sy-subrc EQ 0. - <fs_sheet_content>-cell_style = lv_style_guid. - ELSE. - set_cell( ip_column = ip_column ip_row = ip_row ip_value = '' ip_style = ip_style ). - ENDIF. - -endmethod. - - - - - - - method SET_COLUMN_WIDTH. - DATA: column_dimension TYPE REF TO zcl_excel_worksheet_columndime. - DATA: width TYPE float. - - column_dimension = me->get_column_dimension( ip_column ). - -* if a fix size is supplied use this - IF ip_width_fix IS SUPPLIED. - TRY. - width = ip_width_fix. - IF width <= 0. - RAISE EXCEPTION TYPE zcx_excel - EXPORTING - error = 'Please supply a positive number as column-width'. - ENDIF. - column_dimension->set_width( width ). - EXIT. - CATCH cx_sy_conversion_no_number. -* Strange stuff passed --> raise error - RAISE EXCEPTION TYPE zcx_excel - EXPORTING - error = 'Unable to interpret supplied input as number'. - ENDTRY. - ENDIF. - -* If we get down to here, we have to use whatever is found in autosize. - column_dimension->set_auto_size( ip_width_autosize ). - - -endmethod. - - - - - method SET_DEFAULT_EXCEL_DATE_FORMAT. - - IF ip_default_excel_date_format IS INITIAL. - RAISE EXCEPTION TYPE zcx_excel - EXPORTING - error = 'Default date format cannot be blank'. - ENDIF. - - default_excel_date_format = ip_default_excel_date_format. -endmethod. - - - - - - - - method SET_MERGE. - - DATA: lv_column_start TYPE zexcel_cell_column, - lv_column_end TYPE zexcel_cell_column, - ls_sheet_content TYPE zexcel_s_cell_data, - lv_row_alpha TYPE string. - - FIELD-SYMBOLS: <fs_sheet_content> TYPE zexcel_s_cell_data. - - lv_column_start = zcl_excel_common=>convert_column2int( ip_column_start ). - lv_column_end = zcl_excel_common=>convert_column2int( ip_column_end ). - - ls_sheet_content-cell_row = ip_row. - ls_sheet_content-cell_column = lv_column_start. - lv_row_alpha = ip_row. - SHIFT lv_row_alpha RIGHT DELETING TRAILING space. - SHIFT lv_row_alpha LEFT DELETING LEADING space. - CONCATENATE ip_column_start lv_row_alpha INTO ls_sheet_content-cell_coords. - INSERT ls_sheet_content INTO TABLE sheet_content_merge. - - ls_sheet_content-cell_column = lv_column_end. - IF ip_row_to IS SUPPLIED. - ls_sheet_content-cell_row = ip_row_to. - lv_row_alpha = ip_row_to. - ELSE. - lv_row_alpha = ip_row. - ls_sheet_content-cell_row = ip_row. - ENDIF. - - SHIFT lv_row_alpha RIGHT DELETING TRAILING space. - SHIFT lv_row_alpha LEFT DELETING LEADING space. - CONCATENATE ip_column_end lv_row_alpha INTO ls_sheet_content-cell_coords. - INSERT ls_sheet_content INTO TABLE sheet_content_merge. - -endmethod. - - - - method SET_PRINT_GRIDLINES. - me->print_gridlines = i_print_gridlines. -endmethod. - - - - - - method SET_ROW_HEIGHT. - DATA: row_dimension TYPE REF TO zcl_excel_worksheet_rowdimensi. - DATA: height TYPE float. - - row_dimension = me->get_row_dimension( ip_row ). - -* if a fix size is supplied use this - TRY. - height = ip_height_fix. - IF height <= 0. - RAISE EXCEPTION TYPE zcx_excel - EXPORTING - error = 'Please supply a positive number as row-height'. - ENDIF. - row_dimension->set_row_height( height ). - EXIT. - CATCH cx_sy_conversion_no_number. -* Strange stuff passed --> raise error - RAISE EXCEPTION TYPE zcx_excel - EXPORTING - error = 'Unable to interpret supplied input as number'. - ENDTRY. - - - -endmethod. - - - - method SET_SHOW_GRIDLINES. - me->show_gridlines = i_show_gridlines. -endmethod. - - - - method SET_SHOW_ROWCOLHEADERS. - me->show_rowcolheaders = i_show_rowcolheaders. -endmethod. - - - - method SET_TABCOLOR. - me->tabcolor = iv_tabcolor. -endmethod. - - - - - - - - - - - - method SET_TABLE. - - DATA: lo_tabdescr TYPE REF TO cl_abap_structdescr, - lr_data TYPE REF TO data, - ls_newline TYPE REF TO data, - ls_header TYPE x030l, - lt_dfies TYPE ddfields, - lv_row_header TYPE zexcel_cell_row VALUE '2', - lv_col_header TYPE zexcel_cell_column_alpha VALUE 'B', - lv_row_int TYPE zexcel_cell_row, - lv_column_int TYPE zexcel_cell_column, - lv_column_alpha TYPE zexcel_cell_column_alpha, - lv_cell_value TYPE zexcel_cell_value. - - - FIELD-SYMBOLS: <fs_table_line> TYPE ANY, - <fs_fldval> TYPE ANY, - <fs_dfies> TYPE dfies, - <fs_cell_value> TYPE zexcel_cell_value. - - lv_column_int = zcl_excel_common=>convert_column2int( ip_top_left_column ). - lv_row_int = ip_top_left_row. - - CREATE DATA lr_data LIKE LINE OF ip_table. - - lo_tabdescr ?= cl_abap_structdescr=>describe_by_data_ref( lr_data ). - - ls_header = lo_tabdescr->get_ddic_header( ). - - lt_dfies = lo_tabdescr->get_ddic_field_list( ). - -* It is better to loop column by column - LOOP AT lt_dfies ASSIGNING <fs_dfies>. - lv_column_alpha = zcl_excel_common=>convert_column2alpha( lv_column_int ). - - IF ip_no_header = abap_false. - " First of all write column header - lv_cell_value = <fs_dfies>-scrtext_m. - me->set_cell( ip_column = lv_column_alpha - ip_row = lv_row_int - ip_value = lv_cell_value - ip_style = ip_hdr_style ). - IF ip_transpose = abap_true. - ADD 1 TO lv_column_int. - ELSE. - ADD 1 TO lv_row_int. - ENDIF. - ENDIF. - - LOOP AT ip_table ASSIGNING <fs_table_line>. - lv_column_alpha = zcl_excel_common=>convert_column2alpha( lv_column_int ). - ASSIGN COMPONENT <fs_dfies>-fieldname OF STRUCTURE <fs_table_line> TO <fs_fldval>. - MOVE <fs_fldval> TO lv_cell_value. - me->set_cell( ip_column = lv_column_alpha - ip_row = lv_row_int - ip_value = <fs_fldval> "lv_cell_value - ip_style = ip_body_style ). - IF ip_transpose = abap_true. - ADD 1 TO lv_column_int. - ELSE. - ADD 1 TO lv_row_int. - ENDIF. - ENDLOOP. - IF ip_transpose = abap_true. - lv_column_int = zcl_excel_common=>convert_column2int( ip_top_left_column ). - ADD 1 TO lv_row_int. - ELSE. - lv_row_int = ip_top_left_row. - ADD 1 TO lv_column_int. - ENDIF. - ENDLOOP. - -endmethod. - - - - - method SET_TITLE. -*--------------------------------------------------------------------* -* ToDos: -* 2do§1 The current coding for replacing a named ranges name -* after renaming a sheet should be checked if it is -* really working if sheetname should be escaped -*--------------------------------------------------------------------* - -*--------------------------------------------------------------------* -* issue #230 - Pimp my Code -* - Stefan Schmöcker, (wip ) 2012-12-08 -* - ... -* changes: aligning code -* message made to support multilinguality -*--------------------------------------------------------------------* -* issue#243 - ' is not allowed as first character in sheet title -* - Stefan Schmöcker, 2012-12-02 -* changes: added additional check for ' as first character -*--------------------------------------------------------------------* - DATA: lo_worksheets_iterator TYPE REF TO cl_object_collection_iterator, - lo_worksheet TYPE REF TO zcl_excel_worksheet, - errormessage TYPE string, - lv_rangesheetname_old TYPE string, - lv_rangesheetname_new TYPE string, - lo_ranges_iterator TYPE REF TO cl_object_collection_iterator, - lo_range TYPE REF TO zcl_excel_range, - lv_range_value TYPE zexcel_range_value, - lv_errormessage TYPE string. " Can't pass '...'(abc) to exception-class - - -*--------------------------------------------------------------------* -* Check whether title consists only of allowed characters -* Illegal characters are: / \ [ ] * ? : --> http://msdn.microsoft.com/en-us/library/ff837411.aspx -* Illegal characters not in documentation: ' as first character -*--------------------------------------------------------------------* - IF ip_title CA '/\[]*?:'. - lv_errormessage = 'Found illegal character in sheetname. List of forbidden characters: /\[]*?:'(402). - RAISE EXCEPTION TYPE zcx_excel - EXPORTING - error = lv_errormessage. - ENDIF. - - IF ip_title IS NOT INITIAL AND ip_title(1) = `'`. - lv_errormessage = 'Sheetname may not start with &'(403). " & used instead of ' to allow fallbacklanguage - REPLACE '&' IN lv_errormessage WITH `'`. - RAISE EXCEPTION TYPE zcx_excel - EXPORTING - error = lv_errormessage. - ENDIF. - - -*--------------------------------------------------------------------* -* Check whether title is unique in workbook -*--------------------------------------------------------------------* - 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. - -*--------------------------------------------------------------------* -* Remember old sheetname and rename sheet to desired name -*--------------------------------------------------------------------* - CONCATENATE me->title '!' INTO lv_rangesheetname_old. - me->title = ip_title. - -*--------------------------------------------------------------------* -* After changing this worksheet's title we have to adjust -* all ranges that are referring to this worksheet. -*--------------------------------------------------------------------* -* 2do§1 - Check if the following quickfix is solid -* I fear it isn't - but this implementation is better then -* nothing at all since it handles a supposed majority of cases -*--------------------------------------------------------------------* - CONCATENATE me->title '!' INTO lv_rangesheetname_new. - - lo_ranges_iterator = me->excel->get_ranges_iterator( ). - WHILE lo_ranges_iterator->has_next( ) = 'X'. - - lo_range ?= lo_ranges_iterator->get_next( ). - lv_range_value = lo_range->get_value( ). - REPLACE ALL OCCURRENCES OF lv_rangesheetname_old IN lv_range_value WITH lv_rangesheetname_new. - IF sy-subrc = 0. - lo_range->set_range_value( lv_range_value ). - ENDIF. - - ENDWHILE. - - -endmethod. - - - - method UPDATE_DIMENSION_RANGE. - - DATA: ls_sheet_content TYPE zexcel_s_cell_data, - lt_sheet_content TYPE zexcel_t_cell_data_unsorted, - lv_row_alpha TYPE string, - lv_column_alpha TYPE zexcel_cell_column_alpha. - - CHECK sheet_content IS NOT INITIAL. - -* update dimension range - lt_sheet_content = sheet_content. - "upper left corner - SORT lt_sheet_content BY cell_row. - READ TABLE lt_sheet_content INDEX 1 INTO ls_sheet_content. - upper_cell-cell_row = ls_sheet_content-cell_row. - SORT lt_sheet_content BY cell_column. - READ TABLE lt_sheet_content INDEX 1 INTO ls_sheet_content. - upper_cell-cell_column = ls_sheet_content-cell_column. - - lv_row_alpha = upper_cell-cell_row. - lv_column_alpha = zcl_excel_common=>convert_column2alpha( upper_cell-cell_column ). - SHIFT lv_row_alpha RIGHT DELETING TRAILING space. - SHIFT lv_row_alpha LEFT DELETING LEADING space. - CONCATENATE lv_column_alpha lv_row_alpha INTO upper_cell-cell_coords. - - "bottom right corner - SORT lt_sheet_content BY cell_row DESCENDING. - READ TABLE lt_sheet_content INDEX 1 INTO ls_sheet_content. - lower_cell-cell_row = ls_sheet_content-cell_row. - SORT lt_sheet_content BY cell_column DESCENDING. - READ TABLE lt_sheet_content INDEX 1 INTO ls_sheet_content. - lower_cell-cell_column = ls_sheet_content-cell_column. - - lv_row_alpha = lower_cell-cell_row. - lv_column_alpha = zcl_excel_common=>convert_column2alpha( lower_cell-cell_column ). - SHIFT lv_row_alpha RIGHT DELETING TRAILING space. - SHIFT lv_row_alpha LEFT DELETING LEADING space. - CONCATENATE lv_column_alpha lv_row_alpha INTO lower_cell-cell_coords. - -endmethod. - - - - *"* 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 ADD. - - worksheets->add( ip_worksheet ). - -endmethod. - - - method CLEAR. - - worksheets->clear( ). - -endmethod. - - - method CONSTRUCTOR. - - CREATE OBJECT worksheets. - -endmethod. - - - - - method GET. - - DATA lv_index TYPE i. - lv_index = ip_index. - eo_worksheet ?= worksheets->if_object_collection~get( lv_index ). - -endmethod. - - - - method GET_ITERATOR. - - eo_iterator ?= worksheets->if_object_collection~get_iterator( ). - -endmethod. - - - - method IS_EMPTY. - - is_empty = worksheets->if_object_collection~is_empty( ). - -endmethod. - - - - method REMOVE. - - worksheets->remove( ip_worksheet ). - -endmethod. - - - - method SIZE. - - ep_size = worksheets->if_object_collection~size( ). - -endmethod. - - - - *"* 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 - - ABAP - - - - - - - - - - - - - - - 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. - - - - 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. - 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 width as number'. - ENDTRY. -endmethod. - - - - - method SET_XF_INDEX. - me->XF_INDEX = ip_XF_INDEX. - r_worksheet_columndime = me. -endmethod. - - - - *"* 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 - - ABAP - - - - - - - - - method CONSTRUCTOR. - " Initialise values - me->row_index = ip_index. - me->row_height = -1. - me->visible = abap_true. - me->outline_level = 0. - me->collapsed = abap_false. - - " set row dimension as unformatted by default - me->xf_index = 0. -endmethod. - - - - method GET_COLLAPSED. - r_collapsed = me->collapsed. -endmethod. - - - - method GET_OUTLINE_LEVEL. - r_outline_level = me->outline_level. -endmethod. - - - - method GET_ROW_HEIGHT. - r_row_height = me->row_height. -endmethod. - - - - method GET_ROW_INDEX. - r_row_index = me->row_index. -endmethod. - - - - method GET_VISIBLE. - r_visible = me->visible. -endmethod. - - - - method GET_XF_INDEX. - r_xf_index = me->xf_index. -endmethod. - - - - method SET_COLLAPSED. - me->collapsed = ip_collapsed. -endmethod. - - - - - method SET_OUTLINE_LEVEL. - IF ip_outline_level < 0 - OR ip_outline_level > 7. - - RAISE EXCEPTION TYPE zcx_excel - EXPORTING - error = 'Outline level must range between 0 and 7.'. - - ENDIF. - me->outline_level = ip_outline_level. -endmethod. - - - - - method SET_ROW_HEIGHT. - TRY. - me->row_height = ip_row_height. - CATCH cx_sy_conversion_no_number. - RAISE EXCEPTION TYPE zcx_excel - EXPORTING - error = 'Unable to interpret ip_row_height as number'. - ENDTRY. -endmethod. - - - - method SET_ROW_INDEX. - me->row_index = ip_index. -endmethod. - - - - method SET_VISIBLE. - me->visible = ip_visible. -endmethod. - - - - method SET_XF_INDEX. - me->XF_INDEX = ip_XF_INDEX. -endmethod. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -25464,10 +24676,16 @@ endmethod. - + - + + + + + + + @@ -25530,13 +24748,7 @@ endmethod. - - - - - - - + @@ -25545,7 +24757,7 @@ endmethod. - + @@ -25608,6 +24820,12 @@ endmethod. + + + + + + @@ -25617,7 +24835,7 @@ endmethod. - + @@ -25674,21 +24892,6 @@ endmethod. - - - - - - - - - - - - - - - @@ -25772,14 +24975,15 @@ endmethod. - + - - - + + + + @@ -27400,7 +26604,7 @@ START-OF-SELECTION. lo_style_rotated = lo_excel->add_new_style( ). lo_style_rotated->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_center. lo_style_rotated->alignment->vertical = zcl_excel_style_alignment=>c_vertical_center. - lo_style_rotated->alignment->textrotation = 165. " -75° == 90° + 75° + lo_style_rotated->alignment->textrotation = 165. " -75° == 90° + 75° lv_style_rotated_guid = lo_style_rotated->get_guid( ). @@ -27434,7 +26638,7 @@ START-OF-SELECTION. " Rotated lo_worksheet->set_cell( ip_row = 10 ip_column = 'D' - ip_value = 'This is a centered text rotated by -75°' + ip_value = 'This is a centered text rotated by -75°' ip_style = lv_style_rotated_guid ). " forced line break @@ -29638,272 +28842,6 @@ START-OF-SELECTION. *** Create output lcl_output=>output( lo_excel ). - - - - - - - *&---------------------------------------------------------------------* -*& Report ZABAP2XLSX_DEMO_SHOW -*&---------------------------------------------------------------------* -REPORT zabap2xlsx_demo_like_se83. - - -*----------------------------------------------------------------------* -* CLASS lcl_perform DEFINITION -*----------------------------------------------------------------------* -CLASS lcl_perform DEFINITION CREATE PRIVATE. - PUBLIC SECTION. - CLASS-METHODS: setup_objects, - collect_reports, - - handle_nav FOR EVENT double_click OF cl_gui_alv_grid - IMPORTING e_row. - - PRIVATE SECTION. - TYPES: BEGIN OF ty_reports, - progname TYPE reposrc-progname, - sort TYPE reposrc-progname, - filename TYPE string, - END OF ty_reports. - - CLASS-DATA: - lo_grid TYPE REF TO cl_gui_alv_grid, - lo_text TYPE REF TO cl_gui_textedit, - cl_document TYPE REF TO i_oi_document_proxy, - - t_reports TYPE STANDARD TABLE OF ty_reports WITH NON-UNIQUE DEFAULT KEY. - CLASS-DATA:error TYPE REF TO i_oi_error, - t_errors TYPE STANDARD TABLE OF REF TO i_oi_error WITH NON-UNIQUE DEFAULT KEY, - cl_control TYPE REF TO i_oi_container_control. "Office Dokument - -ENDCLASS. "lcl_perform DEFINITION - - -START-OF-SELECTION. - lcl_perform=>collect_reports( ). - lcl_perform=>setup_objects( ). - -END-OF-SELECTION. - - WRITE '.'. " Force output - - -*----------------------------------------------------------------------* -* CLASS lcl_perform IMPLEMENTATION -*----------------------------------------------------------------------* -CLASS lcl_perform IMPLEMENTATION. - METHOD setup_objects. - DATA: lo_split TYPE REF TO cl_gui_splitter_container, - lo_container TYPE REF TO cl_gui_container. - - DATA: it_fieldcat TYPE lvc_t_fcat, - is_layout TYPE lvc_s_layo, - is_variant TYPE disvariant. - FIELD-SYMBOLS: <fc> LIKE LINE OF it_fieldcat. - - - CREATE OBJECT lo_split - EXPORTING - parent = cl_gui_container=>screen0 - rows = 1 - columns = 3 - no_autodef_progid_dynnr = 'X'. - lo_split->set_column_width( EXPORTING id = 1 - width = 20 ). - lo_split->set_column_width( EXPORTING id = 2 - width = 40 ). - -* Left: List of reports - lo_container = lo_split->get_container( row = 1 - column = 1 ). - - CREATE OBJECT lo_grid - EXPORTING - i_parent = lo_container. - SET HANDLER lcl_perform=>handle_nav FOR lo_grid. - - is_variant-report = sy-repid. - is_variant-handle = '0001'. - - is_layout-cwidth_opt = 'X'. - - APPEND INITIAL LINE TO it_fieldcat ASSIGNING <fc>. - <fc>-fieldname = 'PROGNAME'. - <fc>-tabname = 'REPOSRC'. - - APPEND INITIAL LINE TO it_fieldcat ASSIGNING <fc>. - <fc>-fieldname = 'SORT'. - <fc>-ref_field = 'PROGNAME'. - <fc>-ref_table = 'REPOSRC'. - - - lo_grid->set_table_for_first_display( EXPORTING - is_variant = is_variant - i_save = 'A' - is_layout = is_layout - CHANGING - it_outtab = t_reports - it_fieldcatalog = it_fieldcat - EXCEPTIONS - invalid_parameter_combination = 1 - program_error = 2 - too_many_lines = 3 - OTHERS = 4 ). - -* Middle: Text with coding - lo_container = lo_split->get_container( row = 1 - column = 2 ). - CREATE OBJECT lo_text - EXPORTING - parent = lo_container. - lo_text->set_readonly_mode( cl_gui_textedit=>true ). - lo_text->set_font_fixed( ). - - - -* right: DemoOutput - lo_container = lo_split->get_container( row = 1 - column = 3 ). - - c_oi_container_control_creator=>get_container_control( IMPORTING control = cl_control - error = error ). - APPEND error TO t_errors. - - cl_control->init_control( EXPORTING inplace_enabled = 'X' - no_flush = 'X' - r3_application_name = 'Demo Document Container' - parent = lo_container - IMPORTING error = error - EXCEPTIONS OTHERS = 2 ). - APPEND error TO t_errors. - - cl_control->get_document_proxy( EXPORTING document_type = 'Excel.Sheet' " EXCEL - no_flush = ' ' - IMPORTING document_proxy = cl_document - error = error ). - APPEND error TO t_errors. -* Errorhandling should be inserted here - - - ENDMETHOD. "setup_objects - - "collect_reports - METHOD collect_reports. - FIELD-SYMBOLS:<report> LIKE LINE OF t_reports. - DATA: t_source TYPE STANDARD TABLE OF text255 WITH NON-UNIQUE DEFAULT KEY. - -* Get all demoreports - SELECT progname - INTO CORRESPONDING FIELDS OF TABLE t_reports - FROM reposrc - WHERE progname LIKE 'ZDEMO_EXCEL%' - AND progname <> sy-repid - AND subc = '1'. - - LOOP AT t_reports ASSIGNING <report>. - -* Check if already switched to new outputoptions - READ REPORT <report>-progname INTO t_source. - IF sy-subrc = 0. - FIND 'INCLUDE zdemo_excel_outputopt_incl.' IN TABLE t_source IGNORING CASE. - ENDIF. - IF sy-subrc <> 0. - DELETE t_reports. - CONTINUE. - ENDIF. - - -* Build half-numeric sort - <report>-sort = <report>-progname. - REPLACE REGEX '(ZDEMO_EXCEL)(\d\d)\s*$' IN <report>-sort WITH '$1\0$2'. " REPLACE REGEX '(ZDEMO_EXCEL)([^][^])*$' IN <report>-sort WITH '$1$2'.REPLACE REGEX '(ZDEMO_EXCEL)([^][^])*$' IN <report>-sort WITH '$1$2'.REPLACE - - REPLACE REGEX '(ZDEMO_EXCEL)(\d)\s*$' IN <report>-sort WITH '$1\0\0$2'. - ENDLOOP. - SORT t_reports BY sort progname. - - ENDMETHOD. "collect_reports - - METHOD handle_nav. - CONSTANTS: filename TYPE text80 VALUE 'ZABAP2XLSX_DEMO_SHOW.xlsx'. - DATA: wa_report LIKE LINE OF t_reports, - t_source TYPE STANDARD TABLE OF text255, - t_rawdata TYPE solix_tab, - wa_rawdata LIKE LINE OF t_rawdata, - bytecount TYPE i, - length TYPE i, - add_selopt TYPE flag. - - - READ TABLE t_reports INTO wa_report INDEX e_row-index. - CHECK sy-subrc = 0. - -* Set new text into middle frame - READ REPORT wa_report-progname INTO t_source. - lo_text->set_text_as_r3table( EXPORTING table = t_source ). - - -* Unload old xls-file - cl_document->close_document( ). - -* Get the demo -* If additional parameters found on selection screen, start via selection screen , otherwise start w/o - CLEAR add_selopt. - FIND 'PARAMETERS' IN TABLE t_source. - IF sy-subrc = 0. - add_selopt = 'X'. - ELSE. - FIND 'SELECT-OPTIONS' IN TABLE t_source. - IF sy-subrc = 0. - add_selopt = 'X'. - ENDIF. - ENDIF. - IF add_selopt IS INITIAL. - SUBMIT (wa_report-progname) AND RETURN - WITH p_backfn = filename - WITH rb_back = 'X' - WITH rb_down = ' ' - WITH rb_send = ' ' - WITH rb_show = ' '. - ELSE. - SUBMIT (wa_report-progname) VIA SELECTION-SCREEN AND RETURN - WITH p_backfn = filename - WITH rb_back = 'X' - WITH rb_down = ' ' - WITH rb_send = ' ' - WITH rb_show = ' '. - ENDIF. - - OPEN DATASET filename FOR INPUT IN BINARY MODE. - IF sy-subrc = 0. - DO. - CLEAR wa_rawdata. - READ DATASET filename INTO wa_rawdata LENGTH length. - IF sy-subrc <> 0. - APPEND wa_rawdata TO t_rawdata. - ADD length TO bytecount. - EXIT. - ENDIF. - APPEND wa_rawdata TO t_rawdata. - ADD length TO bytecount. - ENDDO. - CLOSE DATASET filename. - ENDIF. - - cl_control->get_document_proxy( EXPORTING document_type = 'Excel.Sheet' " EXCEL - no_flush = ' ' - IMPORTING document_proxy = cl_document - error = error ). - - cl_document->open_document_from_table( EXPORTING document_size = bytecount - document_table = t_rawdata - open_inplace = 'X' ). - - ENDMETHOD. "handle_nav - -ENDCLASS. "lcl_perform IMPLEMENTATION - @@ -30144,7 +29082,7 @@ CLASS lcl_output IMPLEMENTATION. ENDAT. TRANSFER <rawdata> TO p_backfn. - SUBTRACT 255 FROM bytes_remain. " Solix hat Länge 255 + SUBTRACT 255 FROM bytes_remain. " Solix hat Länge 255 ENDLOOP. @@ -32102,6 +31040,272 @@ START-OF-SELECTION. *** Create output lcl_output=>output( lo_excel ). + + + + + + + *&---------------------------------------------------------------------* +*& Report ZABAP2XLSX_DEMO_SHOW +*&---------------------------------------------------------------------* +REPORT zabap2xlsx_demo_like_se83. + + +*----------------------------------------------------------------------* +* CLASS lcl_perform DEFINITION +*----------------------------------------------------------------------* +CLASS lcl_perform DEFINITION CREATE PRIVATE. + PUBLIC SECTION. + CLASS-METHODS: setup_objects, + collect_reports, + + handle_nav FOR EVENT double_click OF cl_gui_alv_grid + IMPORTING e_row. + + PRIVATE SECTION. + TYPES: BEGIN OF ty_reports, + progname TYPE reposrc-progname, + sort TYPE reposrc-progname, + filename TYPE string, + END OF ty_reports. + + CLASS-DATA: + lo_grid TYPE REF TO cl_gui_alv_grid, + lo_text TYPE REF TO cl_gui_textedit, + cl_document TYPE REF TO i_oi_document_proxy, + + t_reports TYPE STANDARD TABLE OF ty_reports WITH NON-UNIQUE DEFAULT KEY. + CLASS-DATA:error TYPE REF TO i_oi_error, + t_errors TYPE STANDARD TABLE OF REF TO i_oi_error WITH NON-UNIQUE DEFAULT KEY, + cl_control TYPE REF TO i_oi_container_control. "Office Dokument + +ENDCLASS. "lcl_perform DEFINITION + + +START-OF-SELECTION. + lcl_perform=>collect_reports( ). + lcl_perform=>setup_objects( ). + +END-OF-SELECTION. + + WRITE '.'. " Force output + + +*----------------------------------------------------------------------* +* CLASS lcl_perform IMPLEMENTATION +*----------------------------------------------------------------------* +CLASS lcl_perform IMPLEMENTATION. + METHOD setup_objects. + DATA: lo_split TYPE REF TO cl_gui_splitter_container, + lo_container TYPE REF TO cl_gui_container. + + DATA: it_fieldcat TYPE lvc_t_fcat, + is_layout TYPE lvc_s_layo, + is_variant TYPE disvariant. + FIELD-SYMBOLS: <fc> LIKE LINE OF it_fieldcat. + + + CREATE OBJECT lo_split + EXPORTING + parent = cl_gui_container=>screen0 + rows = 1 + columns = 3 + no_autodef_progid_dynnr = 'X'. + lo_split->set_column_width( EXPORTING id = 1 + width = 20 ). + lo_split->set_column_width( EXPORTING id = 2 + width = 40 ). + +* Left: List of reports + lo_container = lo_split->get_container( row = 1 + column = 1 ). + + CREATE OBJECT lo_grid + EXPORTING + i_parent = lo_container. + SET HANDLER lcl_perform=>handle_nav FOR lo_grid. + + is_variant-report = sy-repid. + is_variant-handle = '0001'. + + is_layout-cwidth_opt = 'X'. + + APPEND INITIAL LINE TO it_fieldcat ASSIGNING <fc>. + <fc>-fieldname = 'PROGNAME'. + <fc>-tabname = 'REPOSRC'. + + APPEND INITIAL LINE TO it_fieldcat ASSIGNING <fc>. + <fc>-fieldname = 'SORT'. + <fc>-ref_field = 'PROGNAME'. + <fc>-ref_table = 'REPOSRC'. + + + lo_grid->set_table_for_first_display( EXPORTING + is_variant = is_variant + i_save = 'A' + is_layout = is_layout + CHANGING + it_outtab = t_reports + it_fieldcatalog = it_fieldcat + EXCEPTIONS + invalid_parameter_combination = 1 + program_error = 2 + too_many_lines = 3 + OTHERS = 4 ). + +* Middle: Text with coding + lo_container = lo_split->get_container( row = 1 + column = 2 ). + CREATE OBJECT lo_text + EXPORTING + parent = lo_container. + lo_text->set_readonly_mode( cl_gui_textedit=>true ). + lo_text->set_font_fixed( ). + + + +* right: DemoOutput + lo_container = lo_split->get_container( row = 1 + column = 3 ). + + c_oi_container_control_creator=>get_container_control( IMPORTING control = cl_control + error = error ). + APPEND error TO t_errors. + + cl_control->init_control( EXPORTING inplace_enabled = 'X' + no_flush = 'X' + r3_application_name = 'Demo Document Container' + parent = lo_container + IMPORTING error = error + EXCEPTIONS OTHERS = 2 ). + APPEND error TO t_errors. + + cl_control->get_document_proxy( EXPORTING document_type = 'Excel.Sheet' " EXCEL + no_flush = ' ' + IMPORTING document_proxy = cl_document + error = error ). + APPEND error TO t_errors. +* Errorhandling should be inserted here + + + ENDMETHOD. "setup_objects + + "collect_reports + METHOD collect_reports. + FIELD-SYMBOLS:<report> LIKE LINE OF t_reports. + DATA: t_source TYPE STANDARD TABLE OF text255 WITH NON-UNIQUE DEFAULT KEY. + +* Get all demoreports + SELECT progname + INTO CORRESPONDING FIELDS OF TABLE t_reports + FROM reposrc + WHERE progname LIKE 'ZDEMO_EXCEL%' + AND progname <> sy-repid + AND subc = '1'. + + LOOP AT t_reports ASSIGNING <report>. + +* Check if already switched to new outputoptions + READ REPORT <report>-progname INTO t_source. + IF sy-subrc = 0. + FIND 'INCLUDE zdemo_excel_outputopt_incl.' IN TABLE t_source IGNORING CASE. + ENDIF. + IF sy-subrc <> 0. + DELETE t_reports. + CONTINUE. + ENDIF. + + +* Build half-numeric sort + <report>-sort = <report>-progname. + REPLACE REGEX '(ZDEMO_EXCEL)(\d\d)\s*$' IN <report>-sort WITH '$1\0$2'. " REPLACE REGEX '(ZDEMO_EXCEL)([^][^])*$' IN <report>-sort WITH '$1$2'.REPLACE REGEX '(ZDEMO_EXCEL)([^][^])*$' IN <report>-sort WITH '$1$2'.REPLACE + + REPLACE REGEX '(ZDEMO_EXCEL)(\d)\s*$' IN <report>-sort WITH '$1\0\0$2'. + ENDLOOP. + SORT t_reports BY sort progname. + + ENDMETHOD. "collect_reports + + METHOD handle_nav. + CONSTANTS: filename TYPE text80 VALUE 'ZABAP2XLSX_DEMO_SHOW.xlsx'. + DATA: wa_report LIKE LINE OF t_reports, + t_source TYPE STANDARD TABLE OF text255, + t_rawdata TYPE solix_tab, + wa_rawdata LIKE LINE OF t_rawdata, + bytecount TYPE i, + length TYPE i, + add_selopt TYPE flag. + + + READ TABLE t_reports INTO wa_report INDEX e_row-index. + CHECK sy-subrc = 0. + +* Set new text into middle frame + READ REPORT wa_report-progname INTO t_source. + lo_text->set_text_as_r3table( EXPORTING table = t_source ). + + +* Unload old xls-file + cl_document->close_document( ). + +* Get the demo +* If additional parameters found on selection screen, start via selection screen , otherwise start w/o + CLEAR add_selopt. + FIND 'PARAMETERS' IN TABLE t_source. + IF sy-subrc = 0. + add_selopt = 'X'. + ELSE. + FIND 'SELECT-OPTIONS' IN TABLE t_source. + IF sy-subrc = 0. + add_selopt = 'X'. + ENDIF. + ENDIF. + IF add_selopt IS INITIAL. + SUBMIT (wa_report-progname) AND RETURN + WITH p_backfn = filename + WITH rb_back = 'X' + WITH rb_down = ' ' + WITH rb_send = ' ' + WITH rb_show = ' '. + ELSE. + SUBMIT (wa_report-progname) VIA SELECTION-SCREEN AND RETURN + WITH p_backfn = filename + WITH rb_back = 'X' + WITH rb_down = ' ' + WITH rb_send = ' ' + WITH rb_show = ' '. + ENDIF. + + OPEN DATASET filename FOR INPUT IN BINARY MODE. + IF sy-subrc = 0. + DO. + CLEAR wa_rawdata. + READ DATASET filename INTO wa_rawdata LENGTH length. + IF sy-subrc <> 0. + APPEND wa_rawdata TO t_rawdata. + ADD length TO bytecount. + EXIT. + ENDIF. + APPEND wa_rawdata TO t_rawdata. + ADD length TO bytecount. + ENDDO. + CLOSE DATASET filename. + ENDIF. + + cl_control->get_document_proxy( EXPORTING document_type = 'Excel.Sheet' " EXCEL + no_flush = ' ' + IMPORTING document_proxy = cl_document + error = error ). + + cl_document->open_document_from_table( EXPORTING document_size = bytecount + document_table = t_rawdata + open_inplace = 'X' ). + + ENDMETHOD. "handle_nav + +ENDCLASS. "lcl_perform IMPLEMENTATION + @@ -36580,56 +35784,849 @@ START-OF-SELECTION. *** Create output lcl_output=>output( lo_excel ). + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + @@ -36641,113 +36638,34 @@ START-OF-SELECTION. - + - - + + + + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - + + + + + + + + + + + + + @@ -36761,843 +36679,199 @@ START-OF-SELECTION. - - + + - - + + - + - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -37670,84 +36944,13 @@ START-OF-SELECTION. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - + - - - - - - - - - - - - - - - - - - - - - - @@ -37837,4 +37040,12 @@ START-OF-SELECTION. + + + + + + + + diff --git a/build/ABAP2XLSX_V_7_0.zip b/build/ABAP2XLSX_V_7_0.zip index 24789f8..d478a55 100644 Binary files a/build/ABAP2XLSX_V_7_0.zip and b/build/ABAP2XLSX_V_7_0.zip differ