diff --git a/build/ABAP2XLSX_V_7_0.nugg b/build/ABAP2XLSX_V_7_0.nugg index bd5bb89..220d7db 100644 --- a/build/ABAP2XLSX_V_7_0.nugg +++ b/build/ABAP2XLSX_V_7_0.nugg @@ -1,2 +1,37882 @@ - + + + + + + + + + + + + + + + + + + + + + *"* local class implementation for public class +*"* use this source file for the implementation part of +*"* local helper classes + TYPES: BEGIN OF t_relationship, + id TYPE string, + type TYPE string, + target TYPE string, + END OF t_relationship. + *"* 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 + + + + + + + + + IXML + + + + + + + + method ZIF_EXCEL_READER~CAN_READ_FILE. +*--------------------------------------------------------------------* +* issue #230 - Pimp my Code +* - 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. + + + method ZIF_EXCEL_READER~LOAD. +*--------------------------------------------------------------------* +* ToDos: +* 2do§1 Map Document Properties to ZCL_EXCEL +*--------------------------------------------------------------------* + +*--------------------------------------------------------------------* +* issue #230 - Pimp my Code +* - Stefan Schmöcker, (done) 2012-11-07 +* - ... +* changes: renaming variables to naming conventions +* removing unused variables +* aligning code +* adding comments to explain what we are trying to achieve +* commenting on problems/future enhancements/todos we already know of or should decide upon +* adding me-> where possible +*--------------------------------------------------------------------* +* issue#234 - error reading xlsx written by libre office +* - Stefan Schmöcker, 2012-11-07 +* changes: passing new optional input parameter to private attribute +*--------------------------------------------------------------------* + + CONSTANTS: lcv_core_properties TYPE string VALUE 'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties', + lcv_office_document TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument'. + + DATA: lo_rels TYPE REF TO if_ixml_document, + lo_node TYPE REF TO if_ixml_element, + ls_relationship TYPE t_relationship. + +*--------------------------------------------------------------------* +* §1 Create EXCEL-Object we want to return to caller + +* §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 +* +* The xlsx Zip-archive has generally the following folder structure: +* <root> | +* |--> _rels +* |--> doc_Props +* |--> xl | +* |--> _rels +* |--> theme +* |--> worksheets + +* §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"> +* <Relationship Target="docProps/app.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Id="rId3"/> +* <Relationship Target="docProps/core.xml" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Id="rId2"/> +* <Relationship Target="xl/workbook.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Id="rId1"/> +* </Relationships> +*--------------------------------------------------------------------* + + +*--------------------------------------------------------------------* +* §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 = i_use_alternate_zip. +*--------------------------------------------------------------------* + + +*--------------------------------------------------------------------* +* §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 +*--------------------------------------------------------------------* + lo_node ?= lo_rels->find_from_name( 'Relationship' ). "#EC NOTEXT + WHILE lo_node IS BOUND. + + me->fill_struct_from_attributes( EXPORTING + ip_element = lo_node + CHANGING + cp_structure = ls_relationship ). + CASE ls_relationship-type. + + WHEN lcv_core_properties. + " 2do§1 Map Document Properties to ZCL_EXCEL + + WHEN lcv_office_document. + me->load_workbook( iv_workbook_full_filename = ls_relationship-target + io_excel = r_excel ). + + WHEN OTHERS. + + ENDCASE. + lo_node ?= lo_node->get_next( ). + + ENDWHILE. + + + endmethod. + + + METHOD zif_excel_reader~load_file. +*--------------------------------------------------------------------* +* ToDos: +* 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 +*--------------------------------------------------------------------* + +*--------------------------------------------------------------------* +* issue #230 - Pimp my Code +* - Stefan Schmöcker, (done) 2012-11-05 +* - ... +* changes: renaming variables to naming conventions +* renaming variables to indicate what they are used for +* adding comments to explain what we are trying to achieve +* message made to support multilinguality +* aligning code +* commenting on problems/future enhancements/todos we already know of or should decide upon +* adding issue # that has initiated the change - date provided to allow cleaning of code after a certain period +* explicit declaration of type of table instead of implicit declaration +* added errorhandling for open dataset +*--------------------------------------------------------------------* +* issue#234 - error reading xlsx written by libre office +* - Stefan Schmöcker, 2012-11-07 +* changes: passing new optional input parameter to private attribute +*--------------------------------------------------------------------* + + DATA: lv_excel_data TYPE xstring. + +* issue#234 - error reading xlsx written by libre office + me->zif_excel_reader~gv_use_alternate_zip = i_use_alternate_zip. + + 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 + r_excel = me->zif_excel_reader~load( i_excel2007 = lv_excel_data + i_use_alternate_zip = i_use_alternate_zip ). +*--------------------------------------------------------------------* + + ENDMETHOD. + + + + + method FILL_STRUCT_FROM_ATTRIBUTES. +*--------------------------------------------------------------------* +* issue #230 - Pimp my Code +* - Stefan Schmöcker, (done) 2012-11-07 +* - ... +* changes: renaming variables to naming conventions +* aligning code +* adding comments to explain what we are trying to achieve +*--------------------------------------------------------------------* + + DATA: lv_name TYPE string, + lo_attributes TYPE REF TO if_ixml_named_node_map, + lo_attribute TYPE REF TO if_ixml_attribute, + lo_iterator TYPE REF TO if_ixml_node_iterator. + + FIELD-SYMBOLS: <component> TYPE ANY. + +*--------------------------------------------------------------------* +* The values of named attributes of a tag are being read and moved into corresponding +* fields of given structure +* Behaves like move-corresonding tag to structure + +* Example: +* <Relationship Target="docProps/app.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Id="rId3"/> +* Here the attributes are Target, Type and Id. Thus if the passed +* structure has fieldnames Id and Target these would be filled with +* "rId3" and "docProps/app.xml" respectively +*--------------------------------------------------------------------* + CLEAR cp_structure. + + lo_attributes = ip_element->get_attributes( ). + lo_iterator = lo_attributes->create_iterator( ). + lo_attribute ?= lo_iterator->get_next( ). + WHILE lo_attribute IS BOUND. + + lv_name = lo_attribute->get_name( ). + TRANSLATE lv_name TO UPPER CASE. + ASSIGN COMPONENT lv_name OF STRUCTURE cp_structure TO <component>. + IF sy-subrc = 0. + <component> = lo_attribute->get_value( ). + ENDIF. + lo_attribute ?= lo_iterator->get_next( ). + + ENDWHILE. + + + endmethod. + + + + + + method GET_FROM_ZIP_ARCHIVE. +*--------------------------------------------------------------------* +* issue #230 - Pimp my Code +* - Stefan Schmöcker, (done) 2012-11-07 +* - ... +* changes: aligning code +* adding comments to explain what we are trying to achieve +* changed message passed with exception +* message made to support multilinguality +*--------------------------------------------------------------------**--------------------------------------------------------------------* +* issue#234 - error reading xlsx written by libre office +* - Stefan Schmöcker, 2012-11-07 +* changes: copying coding and using ALTERNATE_ZIP in ELSE-Branch +*--------------------------------------------------------------------* + + DATA: lv_errormessage TYPE string. " Can't pass '...'(abc) to exception-class + + +*--------------------------------------------------------------------* +* An xlsx-file is basically a zip-archive +* From this zip-archive we need to extract one file in binary form +*--------------------------------------------------------------------* + IF me->zif_excel_reader~gv_use_alternate_zip IS INITIAL. "+#234 +*--------------------------------------------------------------------* +* Setup ABAP zip-class with binary exceldata if not done already +*--------------------------------------------------------------------* + IF me->zip IS NOT BOUND. + CREATE OBJECT me->zip. + zip->load( EXPORTING + zip = me->excel2007 + EXCEPTIONS + zip_parse_error = 1 + OTHERS = 2 ). + IF sy-subrc <> 0. + lv_errormessage = 'ZIP parse error'(002). + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = lv_errormessage. + ENDIF. + ENDIF. + +*--------------------------------------------------------------------* +* Extract requested filename from archive if possible +*--------------------------------------------------------------------* + zip->get( EXPORTING + name = i_filename + IMPORTING + content = r_content " Contents + EXCEPTIONS + zip_index_error = 1 + zip_decompression_error = 2 + OTHERS = 3 ). + IF sy-subrc <> 0. + lv_errormessage = 'File not found in zip-archive'(003). + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = lv_errormessage. + ENDIF. +*--------------------------------------------------------------------* +* issue#234 - begin of insertion +*--------------------------------------------------------------------* + ELSE. +*--------------------------------------------------------------------* +* Setup alternate ABAP zip-class with binary exceldata if not done already +* May become obsolete if SAP fixes standard CL_ABAP_ZIP +*--------------------------------------------------------------------* + IF me->alternate_zip IS NOT BOUND. + CREATE OBJECT me->alternate_zip TYPE (zif_excel_reader~gv_use_alternate_zip). + TRY. + CALL METHOD me->alternate_zip->('LOAD') + EXPORTING + zip = me->excel2007 + EXCEPTIONS + zip_parse_error = 1 + OTHERS = 2. + CATCH cx_sy_dyn_call_illegal_method. + lv_errormessage = 'Method LOAD missing in alternative zipclass'. "#EC NOTEXT This is a workaround until class CL_ABAP_ZIP is fixed + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = lv_errormessage. + ENDTRY. + + IF sy-subrc <> 0. + lv_errormessage = 'ZIP parse error'(002). + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = lv_errormessage. + ENDIF. + ENDIF. + +*--------------------------------------------------------------------* +* Extract requested filename from archive if possible +*--------------------------------------------------------------------* + TRY. + CALL METHOD me->alternate_zip->('GET') + EXPORTING + name = i_filename + IMPORTING + content = r_content " Contents + EXCEPTIONS + zip_index_error = 1 + zip_decompression_error = 2 + OTHERS = 3. + CATCH cx_sy_dyn_call_illegal_method. + lv_errormessage = 'Method GET missing in alternative zipclass'. "#EC NOTEXT This is a workaround until class CL_ABAP_ZIP is fixed + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = lv_errormessage. + ENDTRY. + IF sy-subrc <> 0. + lv_errormessage = 'File not found in zip-archive'(003). + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = lv_errormessage. + ENDIF. + ENDIF. +*--------------------------------------------------------------------* +* issue#234 - end of insertion +*--------------------------------------------------------------------* + + endmethod. + + + + + + + method GET_IXML_FROM_ZIP_ARCHIVE. +*--------------------------------------------------------------------* +* ToDos: +* 2do§1 Add comment what is being achieved here +*--------------------------------------------------------------------* + +*--------------------------------------------------------------------* +* issue #230 - Pimp my Code +* - Stefan Schmöcker, (done) 2012-11-07 +* - ... +* changes: renaming variables to naming conventions +* removing unnecessary type-pool +* aligning code +*--------------------------------------------------------------------* + + DATA: lv_content TYPE xstring, + + lo_ixml TYPE REF TO if_ixml, + lo_streamfactory TYPE REF TO if_ixml_stream_factory, + lo_istream TYPE REF TO if_ixml_istream, + lo_parser TYPE REF TO if_ixml_parser. + + +*--------------------------------------------------------------------* +* 2do§1 ???? Something happens here ??? +*--------------------------------------------------------------------* + lv_content = me->get_from_zip_archive( i_filename ). + lo_ixml = cl_ixml=>create( ). + lo_streamfactory = lo_ixml->create_stream_factory( ). + lo_istream = lo_streamfactory->create_istream_xstring( lv_content ). + r_ixml = lo_ixml->create_document( ). + lo_parser = lo_ixml->create_parser( stream_factory = lo_streamfactory + istream = lo_istream + document = r_ixml ). + + lo_parser->set_normalizing( is_normalizing ). + lo_parser->set_validating( mode = if_ixml_parser=>co_no_validation ). + lo_parser->parse( ). + + endmethod. + + + + + + method LOAD_DRAWING_ANCHOR. + + TYPES: BEGIN OF t_c_nv_pr, + name TYPE string, + id TYPE string, + END OF t_c_nv_pr. + + TYPES: BEGIN OF t_blip, + cstate TYPE string, + embed TYPE string, + END OF t_blip. + + TYPES: BEGIN OF t_chart, + id TYPE string, + END OF t_chart. + + TYPES: BEGIN OF t_ext, + cx TYPE string, + cy TYPE string, + END OF t_ext. + + CONSTANTS: lc_xml_attr_true TYPE string VALUE 'true', + lc_xml_attr_true_int TYPE string VALUE '1'. + CONSTANTS: lc_rel_chart TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart', + lc_rel_image TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image'. + + DATA: lo_drawing TYPE REF TO zcl_excel_drawing, + node TYPE REF TO if_ixml_element, + node2 TYPE REF TO if_ixml_element, + node3 TYPE REF TO if_ixml_element, + node4 TYPE REF TO if_ixml_element, + + ls_upper TYPE zexcel_drawing_location, + ls_lower TYPE zexcel_drawing_location, + ls_size TYPE zexcel_drawing_size, + ext TYPE t_ext, + lv_content TYPE xstring, + lv_relation_id TYPE string, + lv_title TYPE zexcel_sheet_title, + + cnvpr TYPE t_c_nv_pr, + blip TYPE t_blip, + chart TYPE t_chart, + drawing_type TYPE zexcel_drawing_type, + + rel_drawing TYPE t_rel_drawing. + + node ?= io_anchor_element->find_from_name( name = 'from' namespace = 'xdr' ). + CHECK node IS NOT INITIAL. + node2 ?= node->find_from_name( name = 'col' namespace = 'xdr' ). + ls_upper-col = node2->get_value( ). + node2 ?= node->find_from_name( name = 'row' namespace = 'xdr' ). + ls_upper-row = node2->get_value( ). + node2 ?= node->find_from_name( name = 'colOff' namespace = 'xdr' ). + ls_upper-col_offset = node2->get_value( ). + node2 ?= node->find_from_name( name = 'rowOff' namespace = 'xdr' ). + ls_upper-row_offset = node2->get_value( ). + + node ?= io_anchor_element->find_from_name( name = 'ext' namespace = 'xdr' ). + IF node IS INITIAL. + CLEAR ls_size. + ELSE. + me->fill_struct_from_attributes( EXPORTING ip_element = node CHANGING cp_structure = ext ). + ls_size-width = ext-cx. + ls_size-height = ext-cy. + ENDIF. + + node ?= io_anchor_element->find_from_name( name = 'to' namespace = 'xdr' ). + IF node IS INITIAL. + CLEAR ls_lower. + ELSE. + node2 ?= node->find_from_name( name = 'col' namespace = 'xdr' ). + ls_lower-col = node2->get_value( ). + node2 ?= node->find_from_name( name = 'row' namespace = 'xdr' ). + ls_lower-row = node2->get_value( ). + node2 ?= node->find_from_name( name = 'colOff' namespace = 'xdr' ). + ls_lower-col_offset = node2->get_value( ). + node2 ?= node->find_from_name( name = 'rowOff' namespace = 'xdr' ). + ls_lower-row_offset = node2->get_value( ). + ENDIF. + + node ?= io_anchor_element->find_from_name( name = 'pic' namespace = 'xdr' ). + IF node IS NOT INITIAL. + node2 ?= node->find_from_name( name = 'nvPicPr' namespace = 'xdr' ). + CHECK node2 IS NOT INITIAL. + node3 ?= node2->find_from_name( name = 'cNvPr' namespace = 'xdr' ). + CHECK node3 IS NOT INITIAL. + me->fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = cnvpr ). + lv_title = cnvpr-name. + + node2 ?= node->find_from_name( name = 'blipFill' namespace = 'xdr' ). + CHECK node2 IS NOT INITIAL. + node3 ?= node2->find_from_name( name = 'blip' namespace = 'a' ). + CHECK node3 IS NOT INITIAL. + me->fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = blip ). + lv_relation_id = blip-embed. + + drawing_type = zcl_excel_drawing=>type_image. + ENDIF. + + node ?= io_anchor_element->find_from_name( name = 'graphicFrame' namespace = 'xdr' ). + IF node IS NOT INITIAL. + node2 ?= node->find_from_name( name = 'nvGraphicFramePr' namespace = 'xdr' ). + CHECK node2 IS NOT INITIAL. + node3 ?= node2->find_from_name( name = 'cNvPr' namespace = 'xdr' ). + CHECK node3 IS NOT INITIAL. + me->fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = cnvpr ). + lv_title = cnvpr-name. + + node2 ?= node->find_from_name( name = 'graphic' namespace = 'a' ). + CHECK node2 IS NOT INITIAL. + node3 ?= node2->find_from_name( name = 'graphicData' namespace = 'a' ). + CHECK node3 IS NOT INITIAL. + node4 ?= node2->find_from_name( name = 'chart' namespace = 'c' ). + CHECK node4 IS NOT INITIAL. + me->fill_struct_from_attributes( EXPORTING ip_element = node4 CHANGING cp_structure = chart ). + lv_relation_id = chart-id. + + drawing_type = zcl_excel_drawing=>type_chart. + ENDIF. + + lo_drawing = io_worksheet->excel->add_new_drawing( + ip_type = drawing_type + ip_title = lv_title ). + io_worksheet->add_drawing( lo_drawing ). + + lo_drawing->set_position2( + EXPORTING + ip_from = ls_upper + ip_to = ls_lower ). + + READ TABLE it_related_drawings INTO rel_drawing + WITH KEY id = lv_relation_id. + + lo_drawing->set_media( + EXPORTING + ip_media = rel_drawing-content + ip_media_type = rel_drawing-file_ext + ip_width = ls_size-width + ip_height = ls_size-height ). + + if drawing_type = zcl_excel_drawing=>type_chart. + "-------------Added by Alessandro Iannacci - Should load chart attributes + lo_drawing->load_chart_attributes( rel_drawing-content_xml ). + endif. + + endmethod. + + + + + method LOAD_SHARED_STRINGS. +*--------------------------------------------------------------------* +* ToDos: +* 2do§1 Support partial formatting of strings in cells +*--------------------------------------------------------------------* + +*--------------------------------------------------------------------* +* issue #230 - Pimp my Code +* - Stefan Schmöcker, (done) 2012-11-11 +* - ... +* changes: renaming variables to naming conventions +* renaming variables to indicate what they are used for +* aligning code +* adding comments to explain what we are trying to achieve +* rewriting code for better readibility +*--------------------------------------------------------------------* + + + + DATA: + lo_shared_strings_xml TYPE REF TO if_ixml_document, + lo_node_si TYPE REF TO if_ixml_element, + lo_node_si_child TYPE REF TO if_ixml_element, + lo_node_r_child_t TYPE REF TO if_ixml_element, + lv_tag_name TYPE string, + lv_node_value TYPE string. + + FIELD-SYMBOLS: <lv_shared_string> LIKE LINE OF me->shared_strings. + +*--------------------------------------------------------------------* + +* §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 + +* Following is an example how this file could be set up; 2 strings in simple formatting, 3rd string rich textformatted + + +* <?xml version="1.0" encoding="UTF-8" standalone="true"?> +* <sst uniqueCount="6" count="6" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"> +* <si> +* <t>This is a teststring 1</t> +* </si> +* <si> +* <t>This is a teststring 2</t> +* </si> +* <si> +* <r> +* <t>T</t> +* </r> +* <r> +* <rPr> +* <sz val="11"/> +* <color rgb="FFFF0000"/> +* <rFont val="Calibri"/> +* <family val="2"/> +* <scheme val="minor"/> +* </rPr> +* <t xml:space="preserve">his is a </t> +* </r> +* <r> +* <rPr> +* <sz val="11"/> +* <color theme="1"/> +* <rFont val="Calibri"/> +* <family val="2"/> +* <scheme val="minor"/> +* </rPr> +* <t>teststring 3</t> +* </r> +* </si> +* </sst> +*--------------------------------------------------------------------* + + lo_shared_strings_xml = me->get_ixml_from_zip_archive( i_filename = ip_path + is_normalizing = space ). " NO!!! normalizing - otherwise leading blanks will be omitted and that is not really desired for the stringtable + lo_node_si ?= lo_shared_strings_xml->find_from_name( 'si' ). + WHILE lo_node_si IS BOUND. + + APPEND INITIAL LINE TO me->shared_strings ASSIGNING <lv_shared_string>. " Each <si>-entry in the xml-file must lead to an entry in our stringtable + lo_node_si_child ?= lo_node_si->get_first_child( ). + IF lo_node_si_child IS BOUND. + lv_tag_name = lo_node_si_child->get_name( ). + IF lv_tag_name = 't'. +*--------------------------------------------------------------------* +* §1.1 - "simple" strings +* Example: see above +*--------------------------------------------------------------------* + <lv_shared_string> = lo_node_si_child->get_value( ). + ELSE. +*--------------------------------------------------------------------* +* §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 +* Example: see above +*--------------------------------------------------------------------* + WHILE lo_node_si_child IS BOUND. " actually these children of <si> are <r>-tags + + lo_node_r_child_t ?= lo_node_si_child->find_from_name( 't' ). " extract the <t>...</t> part of each <r>-tag + IF lo_node_r_child_t IS BOUND. + lv_node_value = lo_node_r_child_t->get_value( ). + CONCATENATE <lv_shared_string> lv_node_value INTO <lv_shared_string> RESPECTING BLANKS. + ENDIF. + + lo_node_si_child ?= lo_node_si_child->get_next( ). + + ENDWHILE. + ENDIF. + ENDIF. + + lo_node_si ?= lo_node_si->get_next( ). + ENDWHILE. + + endmethod. + + + + + + method LOAD_STYLES. + +*--------------------------------------------------------------------* +* issue #230 - Pimp my Code +* - Stefan Schmöcker, (wip ) 2012-11-25 +* - ... +* changes: renaming variables and types to naming conventions +* aligning code +* adding comments to explain what we are trying to achieve +*--------------------------------------------------------------------* + TYPES: BEGIN OF lty_xf, + applyalignment TYPE string, + applyborder TYPE string, + applyfill TYPE string, + applyfont TYPE string, + applynumberformat TYPE string, + applyprotection TYPE string, + borderid TYPE string, + fillid TYPE string, + fontid TYPE string, + numfmtid TYPE string, + pivotbutton TYPE string, + quoteprefix TYPE string, + xfid TYPE string, + END OF lty_xf. + + TYPES: BEGIN OF lty_alignment, + horizontal TYPE string, + indent TYPE string, + justifylastline TYPE string, + readingorder TYPE string, + relativeindent TYPE string, + shrinktofit TYPE string, + textrotation TYPE string, + vertical TYPE string, + wraptext TYPE string, + END OF lty_alignment. + + TYPES: BEGIN OF lty_protection, + hidden TYPE string, + locked TYPE string, + END OF lty_protection. + + DATA: lo_styles_xml TYPE REF TO if_ixml_document, + lo_style TYPE REF TO zcl_excel_style, + + lt_num_formats TYPE t_num_formats, + lt_fills TYPE t_fills, + lt_borders TYPE t_borders, + lt_fonts TYPE t_fonts, + + ls_num_format TYPE t_num_format, + ls_fill TYPE REF TO zcl_excel_style_fill, + ls_cell_border TYPE REF TO zcl_excel_style_borders, + ls_font TYPE REF TO zcl_excel_style_font, + + lo_node_cellxfs TYPE REF TO if_ixml_element, + lo_node_cellxfs_xf TYPE REF TO if_ixml_element, + lo_node_cellxfs_xf_alignment TYPE REF TO if_ixml_element, + lo_node_cellxfs_xf_protection TYPE REF TO if_ixml_element, + + lo_nodes_xf TYPE REF TO if_ixml_node_collection, + lo_iterator_cellxfs TYPE REF TO if_ixml_node_iterator, + + ls_xf TYPE lty_xf, + ls_alignment TYPE lty_alignment, + ls_protection TYPE lty_protection, + lv_index TYPE i. + +*--------------------------------------------------------------------* +* 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 + +* Following is an example how this part of a file could be set up +* ... +* parts with various formatinformation - see §1,§2,§3,§4 +* ... +* <cellXfs count="26"> +* <xf numFmtId="0" borderId="0" fillId="0" fontId="0" xfId="0"/> +* <xf numFmtId="0" borderId="0" fillId="2" fontId="0" xfId="0" applyFill="1"/> +* <xf numFmtId="0" borderId="1" fillId="3" fontId="0" xfId="0" applyFill="1" applyBorder="1"/> +* <xf numFmtId="0" borderId="2" fillId="3" fontId="0" xfId="0" applyFill="1" applyBorder="1"/> +* <xf numFmtId="0" borderId="3" fillId="3" fontId="0" xfId="0" applyFill="1" applyBorder="1"/> +* <xf numFmtId="0" borderId="4" fillId="3" fontId="0" xfId="0" applyFill="1" applyBorder="1"/> +* <xf numFmtId="0" borderId="0" fillId="3" fontId="0" xfId="0" applyFill="1" applyBorder="1"/> +* ... +* </cellXfs> +*--------------------------------------------------------------------* + + lo_styles_xml = me->get_ixml_from_zip_archive( ip_path ). + +*--------------------------------------------------------------------* +* The styles are build up from +* §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 + +*--------------------------------------------------------------------* +* Now everything is prepared to build a "full" style +*--------------------------------------------------------------------* + lo_node_cellxfs = lo_styles_xml->find_from_name( name = 'cellXfs' ). + IF lo_node_cellxfs IS BOUND. + lo_nodes_xf = lo_node_cellxfs->get_elements_by_tag_name( name = 'xf' ). + lo_iterator_cellxfs = lo_nodes_xf->create_iterator( ). + lo_node_cellxfs_xf ?= lo_iterator_cellxfs->get_next( ). + WHILE lo_node_cellxfs_xf IS BOUND. + + lo_style = ip_excel->add_new_style( ). + fill_struct_from_attributes( EXPORTING + ip_element = lo_node_cellxfs_xf + CHANGING + cp_structure = ls_xf ). +*--------------------------------------------------------------------* +* §2 fill style +*--------------------------------------------------------------------* + IF ls_xf-applyfill = '1' AND ls_xf-fillid IS NOT INITIAL. + lv_index = ls_xf-fillid + 1. + READ TABLE lt_fills INTO ls_fill INDEX lv_index. + IF sy-subrc = 0. + lo_style->fill = ls_fill. + ENDIF. + ENDIF. + +*--------------------------------------------------------------------* +* §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. + IF sy-subrc = 0. + lo_style->number_format = ls_num_format-format. + ENDIF. + ENDIF. + +*--------------------------------------------------------------------* +* §3 border style +*--------------------------------------------------------------------* + IF ls_xf-applyborder = '1' AND ls_xf-borderid IS NOT INITIAL. + lv_index = ls_xf-borderid + 1. + READ TABLE lt_borders INTO ls_cell_border INDEX lv_index. + IF sy-subrc = 0. + lo_style->borders = ls_cell_border. + ENDIF. + ENDIF. + +*--------------------------------------------------------------------* +* §4 font +*--------------------------------------------------------------------* + IF ls_xf-applyfont = '1' AND ls_xf-fontid IS NOT INITIAL. + lv_index = ls_xf-fontid + 1. + READ TABLE lt_fonts INTO ls_font INDEX lv_index. + IF sy-subrc = 0. + lo_style->font = ls_font. + ENDIF. + ENDIF. + +*--------------------------------------------------------------------* +* §5 - Alignment +*--------------------------------------------------------------------* + lo_node_cellxfs_xf_alignment ?= lo_node_cellxfs_xf->find_from_name( 'alignment' ). + IF lo_node_cellxfs_xf_alignment IS BOUND. + fill_struct_from_attributes( EXPORTING + ip_element = lo_node_cellxfs_xf_alignment + CHANGING + cp_structure = ls_alignment ). + IF ls_alignment-horizontal IS NOT INITIAL. + lo_style->alignment->horizontal = ls_alignment-horizontal. + ENDIF. + + IF ls_alignment-vertical IS NOT INITIAL. + lo_style->alignment->vertical = ls_alignment-vertical. + ENDIF. + + IF ls_alignment-textrotation IS NOT INITIAL. + lo_style->alignment->textrotation = ls_alignment-textrotation. + ENDIF. + + IF ls_alignment-wraptext = '1' OR ls_alignment-wraptext = 'true'. + lo_style->alignment->wraptext = abap_true. + ENDIF. + + IF ls_alignment-shrinktofit = '1' OR ls_alignment-shrinktofit = 'true'. + lo_style->alignment->shrinktofit = abap_true. + ENDIF. + + IF ls_alignment-indent IS NOT INITIAL. + lo_style->alignment->indent = ls_alignment-indent. + ENDIF. + ENDIF. + +*--------------------------------------------------------------------* +* §6 - Protection +*--------------------------------------------------------------------* + lo_node_cellxfs_xf_protection ?= lo_node_cellxfs_xf->find_from_name( 'protection' ). + IF lo_node_cellxfs_xf_protection IS BOUND. + fill_struct_from_attributes( EXPORTING + ip_element = lo_node_cellxfs_xf_protection + CHANGING + cp_structure = ls_protection ). + IF ls_protection-locked = '1' OR ls_protection-locked = 'true'. + lo_style->protection->locked = zcl_excel_style_protection=>c_protection_locked. + ELSE. + lo_style->protection->locked = zcl_excel_style_protection=>c_protection_unlocked. + ENDIF. + + IF ls_protection-hidden = '1' OR ls_protection-hidden = 'true'. + lo_style->protection->hidden = zcl_excel_style_protection=>c_protection_hidden. + ELSE. + lo_style->protection->hidden = zcl_excel_style_protection=>c_protection_unhidden. + ENDIF. + + ENDIF. + + INSERT lo_style INTO TABLE me->styles. + + lo_node_cellxfs_xf ?= lo_iterator_cellxfs->get_next( ). + + ENDWHILE. + ENDIF. + + endmethod. + + + + + method LOAD_STYLE_BORDERS. + +*--------------------------------------------------------------------* +* issue #230 - Pimp my Code +* - Stefan Schmöcker, (done) 2012-11-25 +* - ... +* changes: renaming variables and types to naming conventions +* aligning code +* renaming variables to indicate what they are used for +* adding comments to explain what we are trying to achieve +*--------------------------------------------------------------------* + DATA: lo_node_border TYPE REF TO if_ixml_element, + lo_node_bordertype TYPE REF TO if_ixml_element, + lo_node_bordercolor TYPE REF TO if_ixml_element, + lo_cell_border TYPE REF TO zcl_excel_style_borders, + lo_border TYPE REF TO zcl_excel_style_border, + ls_color TYPE t_color. + +*--------------------------------------------------------------------* +* We need a table of used borderformats to build up our styles +* §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 + +* Following is an example how this part of a file could be set up +* <border diagonalDown="1"> +* <left style="mediumDashDotDot"> +* <color rgb="FFFF0000"/> +* </left> +* <right/> +* <top style="thick"> +* <color rgb="FFFF0000"/> +* </top> +* <bottom style="thick"> +* <color rgb="FFFF0000"/> +* </bottom> +* <diagonal style="thick"> +* <color rgb="FFFF0000"/> +* </diagonal> +* </border> +*--------------------------------------------------------------------* + lo_node_border ?= ip_xml->find_from_name( 'border' ). + WHILE lo_node_border IS BOUND. + + CREATE OBJECT lo_cell_border. + +*--------------------------------------------------------------------* +* Diagonal borderlines are formatted the equally. Determine what kind of diagonal borders are present if any +*--------------------------------------------------------------------* +* DiagonalNone = 0 +* DiagonalUp = 1 +* DiagonalDown = 2 +* DiagonalBoth = 3 +*--------------------------------------------------------------------* + IF lo_node_border->get_attribute( 'diagonalDown' ) IS NOT INITIAL. + add zcl_excel_style_borders=>c_diagonal_down to lo_cell_border->diagonal_mode. + ENDIF. + + IF lo_node_border->get_attribute( 'diagonalUp' ) IS NOT INITIAL. + add zcl_excel_style_borders=>c_diagonal_up to lo_cell_border->diagonal_mode. + ENDIF. + + 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 +*--------------------------------------------------------------------* +* Up, down, left, right, diagonal +*--------------------------------------------------------------------* + CREATE OBJECT lo_border. + + CASE lo_node_bordertype->get_name( ). + + WHEN 'left'. + lo_cell_border->left = lo_border. + + WHEN 'right'. + lo_cell_border->right = lo_border. + + WHEN 'top'. + lo_cell_border->top = lo_border. + + WHEN 'bottom'. + lo_cell_border->down = lo_border. + + WHEN 'diagonal'. + lo_cell_border->diagonal = lo_border. + + ENDCASE. + +*--------------------------------------------------------------------* +* §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' ). + IF lo_node_bordercolor IS BOUND. + fill_struct_from_attributes( EXPORTING + ip_element = lo_node_bordercolor + CHANGING + cp_structure = ls_color ). + + lo_border->border_color-rgb = ls_color-rgb. + IF ls_color-indexed IS NOT INITIAL. + lo_border->border_color-indexed = ls_color-indexed. + ENDIF. + + IF ls_color-theme IS NOT INITIAL. + lo_border->border_color-theme = ls_color-theme. + ENDIF. + lo_border->border_color-tint = ls_color-tint. + ENDIF. + + lo_node_bordertype ?= lo_node_bordertype->get_next( ). + + ENDWHILE. + + INSERT lo_cell_border INTO TABLE ep_borders. + + lo_node_border ?= lo_node_border->get_next( ). + + ENDWHILE. + + + endmethod. + + + + + method LOAD_STYLE_FILLS. +*--------------------------------------------------------------------* +* ToDos: +* 2do§1 Support gradientFill +*--------------------------------------------------------------------* + +*--------------------------------------------------------------------* +* issue #230 - Pimp my Code +* - Stefan Schmöcker, (done) 2012-11-25 +* - ... +* changes: renaming variables and types to naming conventions +* aligning code +* commenting on problems/future enhancements/todos we already know of or should decide upon +* adding comments to explain what we are trying to achieve +* renaming variables to indicate what they are used for +*--------------------------------------------------------------------* + DATA: lv_value TYPE string, + lo_node_fill TYPE REF TO if_ixml_element, + lo_node_fill_child TYPE REF TO if_ixml_element, + lo_node_bgcolor TYPE REF TO if_ixml_element, + lo_node_fgcolor TYPE REF TO if_ixml_element, + lo_fill TYPE REF TO zcl_excel_style_fill, + ls_color TYPE t_color. + +*--------------------------------------------------------------------* +* We need a table of used fillformats to build up our styles + +* Following is an example how this part of a file could be set up +* <fill> +* <patternFill patternType="gray125"/> +* </fill> +* <fill> +* <patternFill patternType="solid"> +* <fgColor rgb="FFFFFF00"/> +* <bgColor indexed="64"/> +* </patternFill> +* </fill> +*--------------------------------------------------------------------* + + lo_node_fill ?= ip_xml->find_from_name( 'fill' ). + WHILE lo_node_fill IS BOUND. + + CREATE OBJECT lo_fill. + lo_node_fill_child ?= lo_node_fill->get_first_child( ). + lv_value = lo_node_fill_child->get_name( ). + CASE lv_value. + +*--------------------------------------------------------------------* +* Patternfill +*--------------------------------------------------------------------* + WHEN 'patternFill'. + lo_fill->filltype = lo_node_fill_child->get_attribute( 'patternType' ). +*--------------------------------------------------------------------* +* Patternfill - background color +*--------------------------------------------------------------------* + lo_node_bgcolor = lo_node_fill_child->find_from_name( 'bgColor' ). + IF lo_node_bgcolor IS BOUND. + fill_struct_from_attributes( EXPORTING + ip_element = lo_node_bgcolor + CHANGING + cp_structure = ls_color ). + + lo_fill->bgcolor-rgb = ls_color-rgb. + IF ls_color-indexed IS NOT INITIAL. + lo_fill->bgcolor-indexed = ls_color-indexed. + ENDIF. + + IF ls_color-theme IS NOT INITIAL. + lo_fill->bgcolor-theme = ls_color-theme. + ENDIF. + lo_fill->bgcolor-tint = ls_color-tint. + ENDIF. + +*--------------------------------------------------------------------* +* Patternfill - foreground color +*--------------------------------------------------------------------* + lo_node_fgcolor = lo_node_fill->find_from_name( 'fgColor' ). + IF lo_node_fgcolor IS BOUND. + fill_struct_from_attributes( EXPORTING + ip_element = lo_node_fgcolor + CHANGING + cp_structure = ls_color ). + + lo_fill->fgcolor-rgb = ls_color-rgb. + IF ls_color-indexed IS NOT INITIAL. + lo_fill->fgcolor-indexed = ls_color-indexed. + ENDIF. + + IF ls_color-theme IS NOT INITIAL. + lo_fill->fgcolor-theme = ls_color-theme. + ENDIF. + lo_fill->fgcolor-tint = ls_color-tint. + ENDIF. + + +*--------------------------------------------------------------------* +* gradientFill +*--------------------------------------------------------------------* + WHEN 'gradientFill'. + " 2do§1 Support gradientFill + + WHEN OTHERS. + + ENDCASE. + + + INSERT lo_fill INTO TABLE ep_fills. + + lo_node_fill ?= lo_node_fill->get_next( ). + + ENDWHILE. + + + endmethod. + + + + + method LOAD_STYLE_FONTS. + +*--------------------------------------------------------------------* +* issue #230 - Pimp my Code +* - Stefan Schmöcker, (done) 2012-11-25 +* - ... +* changes: renaming variables and types to naming conventions +* aligning code +* removing unused variables +* adding comments to explain what we are trying to achieve +*--------------------------------------------------------------------* + DATA: lo_node_font TYPE REF TO if_ixml_element, + lo_node2 TYPE REF TO if_ixml_element, + lo_font TYPE REF TO zcl_excel_style_font, + ls_color TYPE t_color. + +*--------------------------------------------------------------------* +* We need a table of used fonts to build up our styles + +* Following is an example how this part of a file could be set up +* <font> +* <sz val="11"/> +* <color theme="1"/> +* <name val="Calibri"/> +* <family val="2"/> +* <scheme val="minor"/> +* </font> +*--------------------------------------------------------------------* + lo_node_font ?= ip_xml->find_from_name( 'font' ). + WHILE lo_node_font IS BOUND. + + CREATE OBJECT lo_font. +*--------------------------------------------------------------------* +* Bold +*--------------------------------------------------------------------* + IF lo_node_font->find_from_name( 'b' ) IS BOUND. + lo_font->bold = abap_true. + ENDIF. + +*--------------------------------------------------------------------* +* Italic +*--------------------------------------------------------------------* + IF lo_node_font->find_from_name( 'i' ) IS BOUND. + lo_font->italic = abap_true. + ENDIF. + +*--------------------------------------------------------------------* +* Underline +*--------------------------------------------------------------------* + lo_node2 = lo_node_font->find_from_name( 'u' ). + IF lo_node2 IS BOUND. + lo_font->underline = abap_true. + lo_font->underline_mode = lo_node2->get_attribute( 'val' ). + ENDIF. + +*--------------------------------------------------------------------* +* StrikeThrough +*--------------------------------------------------------------------* + IF lo_node_font->find_from_name( 'strike' ) IS BOUND. + lo_font->strikethrough = abap_true. + ENDIF. + +*--------------------------------------------------------------------* +* Fontsize +*--------------------------------------------------------------------* + lo_node2 = lo_node_font->find_from_name( 'sz' ). + IF lo_node2 IS BOUND. + lo_font->size = lo_node2->get_attribute( 'val' ). + ENDIF. + +*--------------------------------------------------------------------* +* Fontname +*--------------------------------------------------------------------* + lo_node2 = lo_node_font->find_from_name( 'name' ). + IF lo_node2 IS BOUND. + lo_font->name = lo_node2->get_attribute( 'val' ). + ENDIF. + +*--------------------------------------------------------------------* +* Fontfamily +*--------------------------------------------------------------------* + lo_node2 = lo_node_font->find_from_name( 'family' ). + IF lo_node2 IS BOUND. + lo_font->family = lo_node2->get_attribute( 'val' ). + ENDIF. + +*--------------------------------------------------------------------* +* Fontscheme +*--------------------------------------------------------------------* + lo_node2 = lo_node_font->find_from_name( 'scheme' ). + IF lo_node2 IS BOUND. + lo_font->scheme = lo_node2->get_attribute( 'val' ). + ENDIF. + +*--------------------------------------------------------------------* +* Fontcolor +*--------------------------------------------------------------------* + lo_node2 = lo_node_font->find_from_name( 'color' ). + IF lo_node2 IS BOUND. + fill_struct_from_attributes( EXPORTING + ip_element = lo_node2 + CHANGING + cp_structure = ls_color ). + lo_font->color-rgb = ls_color-rgb. + IF ls_color-indexed IS NOT INITIAL. + lo_font->color-indexed = ls_color-indexed. + ENDIF. + + IF ls_color-theme IS NOT INITIAL. + lo_font->color-theme = ls_color-theme. + ENDIF. + lo_font->color-tint = ls_color-tint. + ENDIF. + + INSERT lo_font INTO TABLE ep_fonts. + + lo_node_font ?= lo_node_font->get_next( ). + + ENDWHILE. + + + endmethod. + + + + + method LOAD_STYLE_NUM_FORMATS. +*--------------------------------------------------------------------* +* ToDos: +* 2do§1 Explain gaps in predefined formats +*--------------------------------------------------------------------* + +*--------------------------------------------------------------------* +* issue #230 - Pimp my Code +* - 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 +* aligning code +*--------------------------------------------------------------------* + DATA: lo_node_numfmt TYPE REF TO if_ixml_element, + ls_num_format TYPE t_num_format. + +*--------------------------------------------------------------------* +* 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 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"> +* <numFmt formatCode="#,###,###,###,##0.00" numFmtId="164"/> +* </numFmts> +*--------------------------------------------------------------------* + lo_node_numfmt ?= ip_xml->find_from_name( 'numFmt' ). + WHILE lo_node_numfmt IS BOUND. + + CLEAR ls_num_format. + + CREATE OBJECT ls_num_format-format. + ls_num_format-format->format_code = lo_node_numfmt->get_attribute( 'formatCode' ). + ls_num_format-id = lo_node_numfmt->get_attribute( 'numFmtId' ). + INSERT ls_num_format INTO TABLE ep_num_formats. + + lo_node_numfmt ?= lo_node_numfmt->get_next( ). + + ENDWHILE. + + DEFINE predefined_format. + ls_num_format-id = &1. + create object ls_num_format-format. + ls_num_format-format->format_code = &2. + insert ls_num_format into table ep_num_formats. + END-OF-DEFINITION. + +*--------------------------------------------------------------------* +* §1 Get internal predefined numberformats +*--------------------------------------------------------------------* + predefined_format '1' '0'. + predefined_format '2' '0.00'. + predefined_format '3' '#,##0'. + predefined_format '4' '#,##0.00'. + predefined_format '5' '$#,##0_);($#,##0)'. + predefined_format '6' '$#,##0_);[Red]($#,##0)'. + predefined_format '7' '$#,##0.00_);($#,##0.00)'. + predefined_format '8' '$#,##0.00_);[Red]($#,##0.00)'. + predefined_format '9' '0%'. + predefined_format '10' '0.00%'. + predefined_format '11' '0.00E+00'. + predefined_format '12' '# ?/?'. + predefined_format '13' '# ??/??'. + predefined_format '14' 'm/d/yyyy'. + predefined_format '15' 'd-mmm-yy'. + predefined_format '16' 'd-mmm'. + predefined_format '17' 'mmm-yy'. + predefined_format '18' 'h:mm AM/PM'. + predefined_format '19' 'h:mm:ss AM/PM'. + 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? + + + + + + + + + + + + + + predefined_format '37' '#,##0_);(#,##0)'. + 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? + + + + predefined_format '45' 'mm:ss'. + predefined_format '46' '[h]:mm:ss'. + predefined_format '47' 'mm:ss.0'. + predefined_format '48' '##0.0E+0'. + predefined_format '49' '@'. +* 2do§1 Is 49 really the last predefined format? + + + endmethod. + + + + + + method LOAD_WORKBOOK. +*--------------------------------------------------------------------* +* ToDos: +* 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 +* - ... +* changes: renaming variables to naming conventions +* aligning code +* removing unused variables +* adding me-> where possible +* renaming variables to indicate what they are used for +* adding comments to explain what we are trying to achieve +* renaming i/o parameters: previous input-parameter ip_path holds a (full) filename and not a path --> rename to iv_workbook_full_filename +* ip_excel renamed while being at it --> rename to io_excel +*--------------------------------------------------------------------* +* issue #232 - Read worksheetstate hidden/veryHidden +* - Stefan Schmöcker, 2012-11-11 +*--------------------------------------------------------------------* +* issue#235 - repeat rows/columns +* - 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 +* changes: initialize area to hold referenced formulaedata +* after all worksheets have been read resolve formuae +*--------------------------------------------------------------------* + + CONSTANTS: lcv_shared_strings TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings', + lcv_worksheet TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet', + lcv_styles TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles', + lcv_vba_project TYPE string VALUE 'http://schemas.microsoft.com/office/2006/relationships/vbaProject', "#EC NEEDED for future incorporation of XLSM-reader +*--------------------------------------------------------------------* +* #232: Read worksheetstate hidden/veryHidden - begin data declarations +*--------------------------------------------------------------------* + lcv_worksheet_state_hidden TYPE string VALUE 'hidden', + lcv_worksheet_state_veryhidden TYPE string VALUE 'veryHidden'. +*--------------------------------------------------------------------* +* #232: Read worksheetstate hidden/veryHidden - end data declarations +*--------------------------------------------------------------------* + + DATA: + lv_path TYPE string, + lv_filename TYPE chkfile, + lv_full_filename TYPE string, + + lo_rels_workbook TYPE REF TO if_ixml_document, + lt_worksheets TYPE STANDARD TABLE OF t_relationship WITH NON-UNIQUE DEFAULT KEY, + lo_workbook TYPE REF TO if_ixml_document, + lv_workbook_index TYPE i, + lv_worksheet_path TYPE string, + ls_sheet TYPE t_sheet, + + lo_node TYPE REF TO if_ixml_element, + ls_relationship TYPE t_relationship, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + lo_range TYPE REF TO zcl_excel_range, + lv_worksheet_title TYPE zexcel_sheet_title, + lv_tabix TYPE sytabix, " #235 - repeat rows/cols. Needed to link defined name to correct worksheet + + ls_range TYPE t_range, + lv_range_value TYPE zexcel_range_value, +*--------------------------------------------------------------------* +* #229: Set active worksheet - begin data declarations +*--------------------------------------------------------------------* + lv_active_sheet_string TYPE string, + lv_zexcel_active_worksheet TYPE zexcel_active_worksheet, +*--------------------------------------------------------------------* +* issue#235 - repeat rows/columns - added autofilter support while changing this section + lo_autofilter TYPE REF TO zcl_excel_autofilter, + ls_area TYPE zexcel_s_autofilter_area, + lv_col_start_alpha TYPE zexcel_cell_column_alpha, + lv_col_end_alpha TYPE zexcel_cell_column_alpha, + lv_row_start TYPE zexcel_cell_row, + lv_row_end TYPE zexcel_cell_row , + lv_regex TYPE string, + lv_range_value_1 TYPE zexcel_range_value, + lv_range_value_2 TYPE zexcel_range_value. +*--------------------------------------------------------------------* +* #229: Set active worksheet - end data declarations +*--------------------------------------------------------------------* + FIELD-SYMBOLS: <worksheet> TYPE t_relationship. + + +*--------------------------------------------------------------------* + +* §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 +* <workbookroot>/_rels/<workbookfilename>.rels and their positions +* be be given relative to the workbookroot + +* 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"> +* <Relationship Target="styles.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Id="rId6"/> +* <Relationship Target="theme/theme1.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Id="rId5"/> +* <Relationship Target="worksheets/sheet1.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Id="rId1"/> +* <Relationship Target="worksheets/sheet2.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Id="rId2"/> +* <Relationship Target="worksheets/sheet3.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Id="rId3"/> +* <Relationship Target="worksheets/sheet4.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Id="rId4"/> +* <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 +* 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 +* ... +* +* §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 + +* <?xml version="1.0" encoding="UTF-8" standalone="true"?> +* <workbook xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"> +* <fileVersion rupBuild="4506" lowestEdited="4" lastEdited="4" appName="xl"/> +* <workbookPr defaultThemeVersion="124226"/> +* <bookViews> +* <workbookView activeTab="1" windowHeight="8445" windowWidth="19035" yWindow="120" xWindow="120"/> +* </bookViews> +* <sheets> +* <sheet r:id="rId1" sheetId="1" name="Sheet1"/> +* <sheet r:id="rId2" sheetId="2" name="Sheet2"/> +* <sheet r:id="rId3" sheetId="3" name="Sheet3" state="hidden"/> +* <sheet r:id="rId4" sheetId="4" name="Sheet4"/> +* </sheets> +* <definedNames/> +* <calcPr calcId="125725"/> +* </workbook> +*--------------------------------------------------------------------* + + CLEAR me->mt_ref_formulae. " ins issue#284 + +*--------------------------------------------------------------------* +* §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' + EXPORTING + full_name = iv_workbook_full_filename + IMPORTING + stripped_name = lv_filename + file_path = lv_path. + + CONCATENATE lv_path '_rels/' lv_filename '.rels' + INTO lv_full_filename. + lo_rels_workbook = me->get_ixml_from_zip_archive( lv_full_filename ). + + lo_node ?= lo_rels_workbook->find_from_name( 'Relationship' ). "#EC NOTEXT + WHILE lo_node IS BOUND. + + me->fill_struct_from_attributes( EXPORTING ip_element = lo_node CHANGING cp_structure = ls_relationship ). + + CASE ls_relationship-type. + +*--------------------------------------------------------------------* +* §2.1 Shared strings - This holds all strings that are used in all worksheets +*--------------------------------------------------------------------* + WHEN lcv_shared_strings. + CONCATENATE lv_path ls_relationship-target + INTO lv_full_filename. + me->load_shared_strings( lv_full_filename ). + +*--------------------------------------------------------------------* +* §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 +*--------------------------------------------------------------------* + WHEN lcv_worksheet. + APPEND ls_relationship TO lt_worksheets. + +*--------------------------------------------------------------------* +* §2.2 Styles - This holds the styles that are used in all worksheets +*--------------------------------------------------------------------* + WHEN lcv_styles. + CONCATENATE lv_path ls_relationship-target + INTO lv_full_filename. + me->load_styles( ip_path = lv_full_filename + ip_excel = io_excel ). + + WHEN OTHERS. + + ENDCASE. + + lo_node ?= lo_node->get_next( ). + + ENDWHILE. + +*--------------------------------------------------------------------* +* §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 +*--------------------------------------------------------------------* + lo_node ?= lo_workbook->find_from_name( 'sheet' ). + lv_workbook_index = 1. + WHILE lo_node IS BOUND. + + me->fill_struct_from_attributes( EXPORTING + ip_element = lo_node + CHANGING + cp_structure = ls_sheet ). +*--------------------------------------------------------------------* +* Create new worksheet in workbook with correct name +*--------------------------------------------------------------------* + lv_worksheet_title = ls_sheet-name. + IF lv_workbook_index = 1. " First sheet has been added automatically by creating io_excel + lo_worksheet = io_excel->get_active_worksheet( ). + lo_worksheet->set_title( lv_worksheet_title ). + ELSE. + lo_worksheet = io_excel->add_new_worksheet( lv_worksheet_title ). + ENDIF. +*--------------------------------------------------------------------* +* #232 - Read worksheetstate hidden/veryHidden - begin of coding +* Set status hidden if necessary +*--------------------------------------------------------------------* + CASE ls_sheet-state. + + WHEN lcv_worksheet_state_hidden. + lo_worksheet->zif_excel_sheet_properties~hidden = zif_excel_sheet_properties=>c_hidden. + + WHEN lcv_worksheet_state_veryhidden. + lo_worksheet->zif_excel_sheet_properties~hidden = zif_excel_sheet_properties=>c_veryhidden. + + ENDCASE. +*--------------------------------------------------------------------* +* #232 - Read worksheetstate hidden/veryHidden - end of coding +*--------------------------------------------------------------------* +*--------------------------------------------------------------------* +* Load worksheetdata +*--------------------------------------------------------------------* + READ TABLE lt_worksheets ASSIGNING <worksheet> WITH KEY id = ls_sheet-id. + IF sy-subrc = 0. + <worksheet>-sheetid = ls_sheet-sheetid. "ins #235 - repeat rows/cols - needed to identify correct sheet + CONCATENATE lv_path <worksheet>-target + INTO lv_worksheet_path. + me->load_worksheet( ip_path = lv_worksheet_path + io_worksheet = lo_worksheet ). + <worksheet>-worksheet = lo_worksheet. + ENDIF. + + lo_node ?= lo_node->get_next( ). + ADD 1 TO lv_workbook_index. + + ENDWHILE. + SORT lt_worksheets BY sheetid. " needed for localSheetid -referencing + +*--------------------------------------------------------------------* +* #284: Set active worksheet - Resolve referenced formulae to +* explicit formulae those cells +*--------------------------------------------------------------------* + me->resolve_referenced_formulae( ). + " ins issue#284 +*--------------------------------------------------------------------* +* #229: Set active worksheet - begin coding +* §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' ). + IF lo_node IS BOUND. + lv_active_sheet_string = lo_node->get_attribute( 'activeTab' ). + TRY. + lv_zexcel_active_worksheet = lv_active_sheet_string + 1. " EXCEL numbers the sheets from 0 onwards --> index into worksheettable is increased by one + CATCH cx_sy_conversion_error. "#EC NO_HANDLER - error here --> just use the default 1st sheet + ENDTRY. + ENDIF. + io_excel->set_active_sheet_index( lv_zexcel_active_worksheet ). +*--------------------------------------------------------------------* +* #229: Set active worksheet - end coding +*--------------------------------------------------------------------* + + +*--------------------------------------------------------------------* +* §3.3 Defined names +* So far I have encountered these +* - named ranges - sheetlocal +* - named ranges - workbookglobal +* - autofilters - sheetlocal ( special range ) +* - repeat rows/cols - sheetlocal ( special range ) +* +*--------------------------------------------------------------------* + lo_node ?= lo_workbook->find_from_name( 'definedName' ). + WHILE lo_node IS BOUND. + + CLEAR lo_range. "ins issue #235 - repeat rows/cols + me->fill_struct_from_attributes( EXPORTING + ip_element = lo_node + CHANGING + cp_structure = ls_range ). + lv_range_value = lo_node->get_value( ). + + IF ls_range-localsheetid IS NOT INITIAL. " issue #163+ +* READ TABLE lt_worksheets ASSIGNING <worksheet> WITH KEY id = ls_range-localsheetid. "del issue #235 - repeat rows/cols " issue #163+ +* lo_range = <worksheet>-worksheet->add_new_range( ). "del issue #235 - repeat rows/cols " issue #163+ +*--------------------------------------------------------------------* +* issue#235 - repeat rows/columns - begin +*--------------------------------------------------------------------* + lv_tabix = ls_range-localsheetid + 1. + READ TABLE lt_worksheets ASSIGNING <worksheet> INDEX lv_tabix. + IF sy-subrc = 0. + CASE ls_range-name. + +*--------------------------------------------------------------------* +* insert autofilters +*--------------------------------------------------------------------* + WHEN zcl_excel_autofilters=>c_autofilter. + lo_autofilter = io_excel->add_new_autofilter( io_sheet = <worksheet>-worksheet ) . + zcl_excel_common=>convert_range2column_a_row( EXPORTING i_range = lv_range_value + IMPORTING e_column_start = lv_col_start_alpha + e_column_end = lv_col_end_alpha + e_row_start = ls_area-row_start ). + ls_area-col_start = zcl_excel_common=>convert_column2int( lv_col_start_alpha ). + ls_area-col_end = zcl_excel_common=>convert_column2int( lv_col_end_alpha ). + lo_autofilter->set_filter_area( is_area = ls_area ). + +*--------------------------------------------------------------------* +* repeat print rows/columns +*--------------------------------------------------------------------* + WHEN zif_excel_sheet_printsettings=>gcv_print_title_name. + lo_range = <worksheet>-worksheet->add_new_range( ). +*--------------------------------------------------------------------* +* This might be a temporary solution. Maybe ranges get be reworked +* to support areas consisting of multiple rectangles +* But for now just split the range into row and columnpart +*--------------------------------------------------------------------* + CLEAR:lv_range_value_1, + lv_range_value_2. + IF lv_range_value IS INITIAL. +* Empty --> nothing to do + ELSE. + IF lv_range_value(1) = `'`. " Escaped + lv_regex = `^('[^']*')+![^,]*,`. + ELSE. + lv_regex = `^[^!]*![^,]*,`. + ENDIF. +* Split into two ranges if necessary + FIND REGEX lv_regex IN lv_range_value MATCH LENGTH sy-fdpos. + IF sy-subrc = 0 AND sy-fdpos > 0. + lv_range_value_2 = lv_range_value+sy-fdpos. + SUBTRACT 1 FROM sy-fdpos. + lv_range_value_1 = lv_range_value(sy-fdpos). + ELSE. + lv_range_value_1 = lv_range_value. + ENDIF. + ENDIF. +* 1st range + zcl_excel_common=>convert_range2column_a_row( EXPORTING i_range = lv_range_value_1 + IMPORTING e_column_start = lv_col_start_alpha + e_column_end = lv_col_end_alpha + e_row_start = lv_row_start + e_row_end = lv_row_end ). + IF lv_col_start_alpha IS NOT INITIAL. + <worksheet>-worksheet->zif_excel_sheet_printsettings~set_print_repeat_columns( iv_columns_from = lv_col_start_alpha + iv_columns_to = lv_col_end_alpha ). + ENDIF. + IF lv_row_start IS NOT INITIAL. + <worksheet>-worksheet->zif_excel_sheet_printsettings~set_print_repeat_rows( iv_rows_from = lv_row_start + iv_rows_to = lv_row_end ). + ENDIF. + +* 2nd range + zcl_excel_common=>convert_range2column_a_row( EXPORTING i_range = lv_range_value_2 + IMPORTING e_column_start = lv_col_start_alpha + e_column_end = lv_col_end_alpha + e_row_start = lv_row_start + e_row_end = lv_row_end ). + IF lv_col_start_alpha IS NOT INITIAL. + <worksheet>-worksheet->zif_excel_sheet_printsettings~set_print_repeat_columns( iv_columns_from = lv_col_start_alpha + iv_columns_to = lv_col_end_alpha ). + ENDIF. + IF lv_row_start IS NOT INITIAL. + <worksheet>-worksheet->zif_excel_sheet_printsettings~set_print_repeat_rows( iv_rows_from = lv_row_start + iv_rows_to = lv_row_end ). + ENDIF. + + WHEN OTHERS. + + ENDCASE. + ENDIF. +*--------------------------------------------------------------------* +* issue#235 - repeat rows/columns - end +*--------------------------------------------------------------------* + ELSE. " issue #163+ + lo_range = io_excel->add_new_range( ). " issue #163+ + ENDIF. " issue #163+ +* lo_range = ip_excel->add_new_range( ). " issue #163- + IF lo_range IS BOUND. "ins issue #235 - repeat rows/cols + lo_range->name = ls_range-name. + lo_range->set_range_value( lv_range_value ). + ENDIF. "ins issue #235 - repeat rows/cols + lo_node ?= lo_node->get_next( ). + + ENDWHILE. + + endmethod. + + + + + + method LOAD_WORKSHEET. +*--------------------------------------------------------------------* +* ToDos: +* 2do§1 Header/footer +* +* Please don't just delete these ToDos if they are not +* needed but leave a comment that states this +*--------------------------------------------------------------------* + +*--------------------------------------------------------------------* +* issue #230 - Pimp my Code +* - Stefan Schmöcker, +* - ... +* changes: renaming variables to naming conventions +* aligning code (started) +* add a list of open ToDos here +* adding comments to explain what we are trying to achieve (started) +*--------------------------------------------------------------------* + TYPES: BEGIN OF lty_cell, + r TYPE string, + t TYPE string, + s TYPE string, + END OF lty_cell. + + TYPES: BEGIN OF lty_column, + min TYPE string, + max TYPE string, + width TYPE float, + customwidth TYPE string, + style TYPE string, + bestfit TYPE string, + collapsed TYPE string, + hidden TYPE string, + outlinelevel TYPE string, + END OF lty_column. + + TYPES: BEGIN OF lty_sheetview, + showgridlines TYPE zexcel_show_gridlines, + tabselected TYPE string, + zoomscalenormal TYPE string, + workbookviewid TYPE string, + showrowcolheaders TYPE string, + END OF lty_sheetview. + + TYPES: BEGIN OF lty_mergecell, + ref TYPE string, + END OF lty_mergecell. + + TYPES: BEGIN OF lty_row, + r TYPE string, + customheight TYPE string, + ht TYPE float, + spans TYPE string, + thickbot TYPE string, + customformat TYPE string, + thicktop TYPE string, + collapsed TYPE string, + hidden TYPE string, + outlinelevel TYPE string, + END OF lty_row. + + TYPES: BEGIN OF lty_page_setup, + id TYPE string, + orientation TYPE string, + scale TYPE string, + END OF lty_page_setup. + + TYPES: BEGIN OF lty_page_margins, + footer TYPE string, + header TYPE string, + bottom TYPE string, + top TYPE string, + right TYPE string, + left TYPE string, + END OF lty_page_margins. + + TYPES: BEGIN OF lty_sheetformatpr, + customheight TYPE string, + defaultrowheight TYPE string, + customwidth TYPE string, + defaultcolwidth TYPE string, + END OF lty_sheetformatpr. + + TYPES: BEGIN OF lty_headerfooter, + alignwithmargins TYPE string, + differentoddeven TYPE string, + END OF lty_headerfooter. + + TYPES: BEGIN OF lty_tabcolor, + rgb TYPE string, + theme TYPE string, + END OF lty_tabcolor. + + TYPES: BEGIN OF lty_datavalidation, + type TYPE zexcel_data_val_type, + allowblank TYPE flag, + showinputmessage TYPE flag, + showerrormessage TYPE flag, + showdropdown TYPE flag, + operator TYPE zexcel_data_val_operator, + formula1 TYPE zexcel_validation_formula1, + formula2 TYPE zexcel_validation_formula1, + sqref TYPE string, + cell_column TYPE zexcel_cell_column_alpha, + cell_column_to TYPE zexcel_cell_column_alpha, + cell_row TYPE zexcel_cell_row, + cell_row_to TYPE zexcel_cell_row, + error TYPE string, + errortitle TYPE string, + prompt TYPE string, + prompttitle TYPE string, + errorstyle TYPE zexcel_data_val_error_style, + END OF lty_datavalidation. + + + + CONSTANTS: lc_xml_attr_true TYPE string VALUE 'true', + lc_xml_attr_true_int TYPE string VALUE '1', + lc_rel_drawing TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing', + lc_rel_printer TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/printerSettings'. + + DATA: lo_ixml_worksheet TYPE REF TO if_ixml_document, + lo_ixml_cells TYPE REF TO if_ixml_node_collection, + lo_ixml_iterator TYPE REF TO if_ixml_node_iterator, + lo_ixml_iterator2 TYPE REF TO if_ixml_node_iterator, + lo_ixml_row_elem TYPE REF TO if_ixml_element, + lo_ixml_cell_elem TYPE REF TO if_ixml_element, + ls_cell TYPE lty_cell, + lv_index TYPE i, + lo_ixml_value_elem TYPE REF TO if_ixml_element, + lo_ixml_formula_elem TYPE REF TO if_ixml_element, + lv_cell_value TYPE zexcel_cell_value, + lv_cell_formula TYPE zexcel_cell_formula, + lv_cell_column TYPE zexcel_cell_column_alpha, + lv_cell_row TYPE zexcel_cell_row, + lo_excel_style TYPE REF TO zcl_excel_style, + lv_style_guid TYPE zexcel_cell_style, + + lo_ixml_imension_elem TYPE REF TO if_ixml_element, "#+234 + lv_dimension_range TYPE string, "#+234 + + lo_ixml_sheetview_elem TYPE REF TO if_ixml_element, + ls_sheetview TYPE lty_sheetview, + lo_ixml_pane_elem TYPE REF TO if_ixml_element, + ls_excel_pane TYPE zexcel_pane, + lv_pane_cell_row TYPE zexcel_cell_row, + lv_pane_cell_col_a TYPE zexcel_cell_column_alpha, + lv_pane_cell_col TYPE zexcel_cell_column, + + lo_ixml_mergecells TYPE REF TO if_ixml_node_collection, + lo_ixml_mergecell_elem TYPE REF TO if_ixml_element, + ls_mergecell TYPE lty_mergecell, + lv_merge_column_start TYPE zexcel_cell_column_alpha, + lv_merge_column_end TYPE zexcel_cell_column_alpha, + lv_merge_row_start TYPE zexcel_cell_row, + lv_merge_row_end TYPE zexcel_cell_row, + + lo_ixml_sheetformatpr_elem TYPE REF TO if_ixml_element, + ls_sheetformatpr TYPE lty_sheetformatpr, + lv_height TYPE float, + + lo_ixml_headerfooter_elem TYPE REF TO if_ixml_element, + ls_headerfooter TYPE lty_headerfooter, + ls_odd_header TYPE zexcel_s_worksheet_head_foot, + ls_odd_footer TYPE zexcel_s_worksheet_head_foot, + ls_even_header TYPE zexcel_s_worksheet_head_foot, + ls_even_footer TYPE zexcel_s_worksheet_head_foot, + lo_ixml_hf_value_elem TYPE REF TO if_ixml_element, + + lo_ixml_pagemargins_elem TYPE REF TO if_ixml_element, + ls_pagemargins TYPE lty_page_margins, + lo_ixml_pagesetup_elem TYPE REF TO if_ixml_element, + ls_pagesetup TYPE lty_page_setup, + + lo_ixml_columns TYPE REF TO if_ixml_node_collection, + lo_ixml_column_elem TYPE REF TO if_ixml_element, + ls_column TYPE lty_column, + lv_column_alpha TYPE zexcel_cell_column_alpha, + lo_column_dimension TYPE REF TO zcl_excel_worksheet_columndime, + lv_outline_level TYPE int4, + + lo_ixml_tabcolor TYPE REF TO if_ixml_element, + ls_tabcolor TYPE lty_tabcolor, + ls_excel_s_tabcolor TYPE zexcel_s_tabcolor, + + lo_ixml_rows TYPE REF TO if_ixml_node_collection, + ls_row TYPE lty_row, + lv_max_col TYPE i, "for use with SPANS element +* lv_min_col TYPE i, "for use with SPANS element " not in use currently + lv_max_col_s TYPE char10, "for use with SPANS element + lv_min_col_s TYPE char10, "for use with SPANS element + lo_row_dimension TYPE REF TO zcl_excel_worksheet_rowdimensi, +*--- End of current code aligning --------------------------------------------------------------- + + lv_path TYPE string, + lo_ixml_node TYPE REF TO if_ixml_element, + ls_relationship TYPE t_relationship, + lo_ixml_rels_worksheet TYPE REF TO if_ixml_document, + lv_rels_worksheet_path TYPE string, + lv_stripped_name TYPE chkfile, + lv_dirname TYPE string, + + lo_ixml_datavalidations TYPE REF TO if_ixml_node_collection, + lo_ixml_datavalidation_elem TYPE REF TO if_ixml_element, + ls_datavalidation TYPE lty_datavalidation, + lo_data_validation TYPE REF TO zcl_excel_data_validation, + lv_datavalidation_range TYPE string, + lt_datavalidation_range TYPE TABLE OF string. + +*--------------------------------------------------------------------* +* §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 +* +* The xlsx Zip-archive has generally the following folder structure: +* <root> | +* |--> _rels +* |--> doc_Props +* |--> xl | +* |--> _rels +* |--> theme +* |--> worksheets +*--------------------------------------------------------------------* + + " Read Workbook Relationships + CALL FUNCTION 'TRINT_SPLIT_FILE_AND_PATH' + EXPORTING + full_name = ip_path + IMPORTING + stripped_name = lv_stripped_name + file_path = lv_dirname. + CONCATENATE lv_dirname '_rels/' lv_stripped_name '.rels' + INTO lv_rels_worksheet_path. + TRY. " +#222 _rels/xxx.rels might not be present. If not found there can be no drawings --> just ignore this section + lo_ixml_rels_worksheet = me->get_ixml_from_zip_archive( lv_rels_worksheet_path ). + lo_ixml_node ?= lo_ixml_rels_worksheet->find_from_name( 'Relationship' ). + CATCH zcx_excel. "#EC NO_HANDLER +#222 + " +#222 No errorhandling necessary - node will be unbound if error occurs + ENDTRY. " +#222 + WHILE lo_ixml_node IS BOUND. + fill_struct_from_attributes( EXPORTING + ip_element = lo_ixml_node + CHANGING + cp_structure = ls_relationship ). + CONCATENATE lv_dirname ls_relationship-target INTO lv_path. + lv_path = resolve_path( lv_path ). + + CASE ls_relationship-type. + WHEN lc_rel_drawing. + " Read Drawings + me->load_worksheet_drawing( ip_path = lv_path + io_worksheet = io_worksheet ). + + WHEN lc_rel_printer. + " Read Printer settings + + WHEN OTHERS. + ENDCASE. + + lo_ixml_node ?= lo_ixml_node->get_next( ). + ENDWHILE. + + + lo_ixml_worksheet = me->get_ixml_from_zip_archive( ip_path ). + + + lo_ixml_tabcolor ?= lo_ixml_worksheet->find_from_name( 'tabColor' ). + IF lo_ixml_tabcolor IS BOUND. + fill_struct_from_attributes( EXPORTING + ip_element = lo_ixml_tabcolor + CHANGING + cp_structure = ls_tabcolor ). +* Theme not supported yet + IF ls_tabcolor-rgb IS NOT INITIAL. + ls_excel_s_tabcolor-rgb = ls_tabcolor-rgb. + io_worksheet->set_tabcolor( ls_excel_s_tabcolor ). + ENDIF. + ENDIF. + + lo_ixml_rows = lo_ixml_worksheet->get_elements_by_tag_name( name = 'row' ). + lo_ixml_iterator = lo_ixml_rows->create_iterator( ). + lo_ixml_row_elem ?= lo_ixml_iterator->get_next( ). + WHILE lo_ixml_row_elem IS BOUND. + + fill_struct_from_attributes( EXPORTING + ip_element = lo_ixml_row_elem + CHANGING + cp_structure = ls_row ). + SPLIT ls_row-spans AT ':' INTO lv_min_col_s lv_max_col_s. + lv_index = lv_max_col_s. + IF lv_index > lv_max_col. + lv_max_col = lv_index. + ENDIF. + lv_cell_row = ls_row-r. + IF ls_row-customheight = '1' + OR ls_row-collapsed = lc_xml_attr_true + OR ls_row-collapsed = lc_xml_attr_true_int + OR ls_row-hidden = lc_xml_attr_true + OR ls_row-hidden = lc_xml_attr_true_int + OR ls_row-outlinelevel > '0'. + lo_row_dimension = io_worksheet->get_row_dimension( lv_cell_row ). + IF ls_row-customheight = '1'. + lo_row_dimension->set_row_height( ls_row-ht ). + ENDIF. + + IF ls_row-collapsed = lc_xml_attr_true + OR ls_row-collapsed = lc_xml_attr_true_int. + lo_row_dimension->set_collapsed( abap_true ). + ENDIF. + + IF ls_row-hidden = lc_xml_attr_true + OR ls_row-hidden = lc_xml_attr_true_int. + lo_row_dimension->set_visible( abap_false ). + ENDIF. + + IF ls_row-outlinelevel > ''. +* outline_level = condense( row-outlineLevel ). "For basis 7.02 and higher + CONDENSE ls_row-outlinelevel. + lv_outline_level = ls_row-outlinelevel. + IF lv_outline_level > 0. + lo_row_dimension->set_outline_level( lv_outline_level ). + ENDIF. + ENDIF. + ENDIF. + + lo_ixml_cells = lo_ixml_row_elem->get_elements_by_tag_name( name = 'c' ). + lo_ixml_iterator2 = lo_ixml_cells->create_iterator( ). + lo_ixml_cell_elem ?= lo_ixml_iterator2->get_next( ). + WHILE lo_ixml_cell_elem IS BOUND. + CLEAR: lv_cell_value, + lv_cell_formula, + lv_style_guid. + + fill_struct_from_attributes( EXPORTING ip_element = lo_ixml_cell_elem CHANGING cp_structure = ls_cell ). + + lo_ixml_value_elem = lo_ixml_cell_elem->find_from_name( name = 'v' ). + + CASE ls_cell-t. + WHEN 's'. " String values are stored as index in shared string table + lv_index = lo_ixml_value_elem->get_value( ) + 1. + READ TABLE shared_strings INTO lv_cell_value INDEX lv_index. + WHEN 'inlineStr'. " inlineStr values are kept in special node + lo_ixml_value_elem = lo_ixml_cell_elem->find_from_name( name = 'is' ). + IF lo_ixml_value_elem IS BOUND. + lv_cell_value = lo_ixml_value_elem->get_value( ). + ENDIF. + WHEN OTHERS. "other types are stored directly + IF lo_ixml_value_elem IS BOUND. + lv_cell_value = lo_ixml_value_elem->get_value( ). + ENDIF. + ENDCASE. + + CLEAR lv_style_guid. + "read style based on index + IF ls_cell-s IS NOT INITIAL. + lv_index = ls_cell-s + 1. + READ TABLE styles INTO lo_excel_style INDEX lv_index. + IF sy-subrc = 0. + lv_style_guid = lo_excel_style->get_guid( ). + ENDIF. + ENDIF. + + lo_ixml_formula_elem = lo_ixml_cell_elem->find_from_name( name = 'f' ). + IF lo_ixml_formula_elem IS BOUND. + lv_cell_formula = lo_ixml_formula_elem->get_value( ). +*--------------------------------------------------------------------* +* Begin of insertion issue#284 - Copied formulae not +*--------------------------------------------------------------------* + DATA: BEGIN OF ls_formula_attributes, + ref TYPE string, + si TYPE i, + t TYPE string, + END OF ls_formula_attributes, + ls_ref_formula TYPE ty_ref_formulae. + + fill_struct_from_attributes( EXPORTING ip_element = lo_ixml_formula_elem CHANGING cp_structure = ls_formula_attributes ). + IF ls_formula_attributes-t = 'shared'. + zcl_excel_common=>convert_columnrow2column_a_row( EXPORTING + i_columnrow = ls_cell-r + IMPORTING + e_column = lv_cell_column + e_row = lv_cell_row ). + + TRY. + CLEAR ls_ref_formula. + ls_ref_formula-sheet = io_worksheet. + ls_ref_formula-row = lv_cell_row. + ls_ref_formula-column = zcl_excel_common=>convert_column2int( lv_cell_column ). + ls_ref_formula-si = ls_formula_attributes-si. + ls_ref_formula-ref = ls_formula_attributes-ref. + ls_ref_formula-formula = lv_cell_formula. + INSERT ls_ref_formula INTO TABLE me->mt_ref_formulae. + CATCH cx_root. + BREAK-POINT. + ENDTRY. + ENDIF. +*--------------------------------------------------------------------* +* End of insertion issue#284 - Copied formulae not +*--------------------------------------------------------------------* + ENDIF. + + IF lv_cell_value IS NOT INITIAL + OR lv_cell_formula IS NOT INITIAL + OR lv_style_guid IS NOT INITIAL. + zcl_excel_common=>convert_columnrow2column_a_row( EXPORTING + i_columnrow = ls_cell-r + IMPORTING + e_column = lv_cell_column + e_row = lv_cell_row ). + io_worksheet->set_cell( ip_column = lv_cell_column " cell_elem Column + ip_row = lv_cell_row " cell_elem row_elem + ip_value = lv_cell_value " cell_elem Value + ip_formula = lv_cell_formula + ip_data_type = ls_cell-t + ip_style = lv_style_guid ). + ENDIF. + lo_ixml_cell_elem ?= lo_ixml_iterator2->get_next( ). + ENDWHILE. + lo_ixml_row_elem ?= lo_ixml_iterator->get_next( ). + ENDWHILE. + +*--------------------------------------------------------------------* +*#234 - column width not read correctly - begin of coding +* reason - libre office doesn't use SPAN in row - definitions +*--------------------------------------------------------------------* + IF lv_max_col = 0. + lo_ixml_imension_elem = lo_ixml_worksheet->find_from_name( name = 'dimension' ). + IF lo_ixml_imension_elem IS BOUND. + lv_dimension_range = lo_ixml_imension_elem->get_attribute( 'ref' ). + IF lv_dimension_range CS ':'. + REPLACE REGEX '\D+\d+:(\D+)\d+' IN lv_dimension_range WITH '$1'. " Get max column + ELSE. + REPLACE REGEX '(\D+)\d+' IN lv_dimension_range WITH '$1'. " Get max column + ENDIF. + lv_max_col = zcl_excel_common=>convert_column2int( lv_dimension_range ). + ENDIF. + ENDIF. +*--------------------------------------------------------------------* +*#234 - column width not read correctly - end of coding +*--------------------------------------------------------------------* + + "Get the customized column width + lo_ixml_columns = lo_ixml_worksheet->get_elements_by_tag_name( name = 'col' ). + lo_ixml_iterator = lo_ixml_columns->create_iterator( ). + lo_ixml_column_elem ?= lo_ixml_iterator->get_next( ). + WHILE lo_ixml_column_elem IS BOUND. + fill_struct_from_attributes( EXPORTING + ip_element = lo_ixml_column_elem + CHANGING + cp_structure = ls_column ). + lo_ixml_column_elem ?= lo_ixml_iterator->get_next( ). + IF ls_column-customwidth = lc_xml_attr_true + OR ls_column-customwidth = lc_xml_attr_true_int + OR ls_column-bestfit = lc_xml_attr_true + OR ls_column-bestfit = lc_xml_attr_true_int + OR ls_column-collapsed = lc_xml_attr_true + OR ls_column-collapsed = lc_xml_attr_true_int + OR ls_column-hidden = lc_xml_attr_true + OR ls_column-hidden = lc_xml_attr_true_int + OR ls_column-outlinelevel > '' + OR ls_column-style > ''. + lv_index = ls_column-min. + WHILE lv_index <= ls_column-max AND lv_index <= lv_max_col. + + lv_column_alpha = zcl_excel_common=>convert_column2alpha( lv_index ). + lo_column_dimension = io_worksheet->get_column_dimension( lv_column_alpha ). + + IF ls_column-customwidth = lc_xml_attr_true + OR ls_column-customwidth = lc_xml_attr_true_int + OR ls_column-width IS NOT INITIAL. "+#234 + lo_column_dimension->set_width( ls_column-width ). + ENDIF. + + IF ls_column-bestfit = lc_xml_attr_true + OR ls_column-bestfit = lc_xml_attr_true_int. + lo_column_dimension->set_auto_size( abap_true ). + ENDIF. + + IF ls_column-collapsed = lc_xml_attr_true + OR ls_column-collapsed = lc_xml_attr_true_int. + lo_column_dimension->set_collapsed( abap_true ). + ENDIF. + + IF ls_column-hidden = lc_xml_attr_true + OR ls_column-hidden = lc_xml_attr_true_int. + lo_column_dimension->set_visible( abap_false ). + ENDIF. + + IF ls_column-outlinelevel > ''. +* outline_level = condense( column-outlineLevel ). + CONDENSE ls_column-outlinelevel. + lv_outline_level = ls_column-outlinelevel. + IF lv_outline_level > 0. + lo_column_dimension->set_outline_level( lv_outline_level ). + ENDIF. + ENDIF. + + IF ls_column-style > ''. + sy-index = ls_column-style + 1. + READ TABLE styles INTO lo_excel_style INDEX sy-index. + DATA: dummy_zexcel_cell_style TYPE zexcel_cell_style. + dummy_zexcel_cell_style = lo_excel_style->get_guid( ). + lo_column_dimension->set_column_style_by_guid( dummy_zexcel_cell_style ). + ENDIF. + + ADD 1 TO lv_index. + ENDWHILE. + ENDIF. +* Fix 207 Read attributes HIDDEN, OUTLINELEVEL, COLLAPSED in ZCL_EXCEL_READER_2007 +* IF column-hidden = lc_xml_attr_true OR +* column-hidden = lc_xml_attr_true_int. +* index = column-min. +* WHILE index <= column-max. +* column_alpha = zcl_excel_common=>convert_column2alpha( index ). +* column_dimension = io_worksheet->get_column_dimension( column_alpha ). +* column_dimension->set_visible( abap_false ). +* ADD 1 TO index. +* ENDWHILE. +* ENDIF. + ENDWHILE. + + "Now we need to get information from the sheetView node + lo_ixml_sheetview_elem = lo_ixml_worksheet->find_from_name( name = 'sheetView' ). + fill_struct_from_attributes( EXPORTING ip_element = lo_ixml_sheetview_elem CHANGING cp_structure = ls_sheetview ). + IF ls_sheetview-showgridlines IS INITIAL OR + ls_sheetview-showgridlines = lc_xml_attr_true OR + ls_sheetview-showgridlines = lc_xml_attr_true_int. + "If the attribute is not specified or set to true, we will show grid lines + ls_sheetview-showgridlines = abap_true. + ELSE. + ls_sheetview-showgridlines = abap_false. + ENDIF. + io_worksheet->set_show_gridlines( ls_sheetview-showgridlines ). + + + "Add merge cell information + lo_ixml_mergecells = lo_ixml_worksheet->get_elements_by_tag_name( name = 'mergeCell' ). + lo_ixml_iterator = lo_ixml_mergecells->create_iterator( ). + lo_ixml_mergecell_elem ?= lo_ixml_iterator->get_next( ). + WHILE lo_ixml_mergecell_elem IS BOUND. + fill_struct_from_attributes( EXPORTING + ip_element = lo_ixml_mergecell_elem + CHANGING + cp_structure = ls_mergecell ). + zcl_excel_common=>convert_range2column_a_row( EXPORTING + i_range = ls_mergecell-ref + IMPORTING + e_column_start = lv_merge_column_start + e_column_end = lv_merge_column_end + e_row_start = lv_merge_row_start + e_row_end = lv_merge_row_end ). + lo_ixml_mergecell_elem ?= lo_ixml_iterator->get_next( ). + io_worksheet->set_merge( EXPORTING + ip_column_start = lv_merge_column_start + ip_column_end = lv_merge_column_end + ip_row = lv_merge_row_start + ip_row_to = lv_merge_row_end ). + ENDWHILE. + + " read sheet format properties + lo_ixml_sheetformatpr_elem = lo_ixml_worksheet->find_from_name( 'sheetFormatPr' ). + IF lo_ixml_sheetformatpr_elem IS NOT INITIAL. + fill_struct_from_attributes( EXPORTING ip_element = lo_ixml_sheetformatpr_elem CHANGING cp_structure = ls_sheetformatpr ). + IF ls_sheetformatpr-customheight = '1'. + lv_height = ls_sheetformatpr-defaultrowheight. + lo_row_dimension = io_worksheet->get_default_row_dimension( ). + lo_row_dimension->set_row_height( lv_height ). + ENDIF. + + " TODO... column + ENDIF. + + " Read in page margins + lo_ixml_pagemargins_elem = lo_ixml_worksheet->find_from_name( 'pageMargins' ). + IF lo_ixml_pagemargins_elem IS NOT INITIAL. + fill_struct_from_attributes( EXPORTING + ip_element = lo_ixml_pagemargins_elem + CHANGING + cp_structure = ls_pagemargins ). + io_worksheet->sheet_setup->margin_bottom = ls_pagemargins-bottom. + io_worksheet->sheet_setup->margin_footer = ls_pagemargins-footer. + io_worksheet->sheet_setup->margin_header = ls_pagemargins-header. + io_worksheet->sheet_setup->margin_left = ls_pagemargins-left. + io_worksheet->sheet_setup->margin_right = ls_pagemargins-right. + io_worksheet->sheet_setup->margin_top = ls_pagemargins-top. + ENDIF. + + " Read in page setup + lo_ixml_pagesetup_elem = lo_ixml_worksheet->find_from_name( 'pageSetup' ). + IF lo_ixml_pagesetup_elem IS NOT INITIAL. + fill_struct_from_attributes( EXPORTING + ip_element = lo_ixml_pagesetup_elem + CHANGING + cp_structure = ls_pagesetup ). + io_worksheet->sheet_setup->orientation = ls_pagesetup-orientation. + io_worksheet->sheet_setup->scale = ls_pagesetup-scale. + ENDIF. + + " Read header footer + lo_ixml_headerfooter_elem = lo_ixml_worksheet->find_from_name( 'headerFooter' ). + IF lo_ixml_headerfooter_elem IS NOT INITIAL. + fill_struct_from_attributes( EXPORTING ip_element = lo_ixml_headerfooter_elem CHANGING cp_structure = ls_headerfooter ). + io_worksheet->sheet_setup->diff_oddeven_headerfooter = ls_headerfooter-differentoddeven. + + lo_ixml_hf_value_elem = lo_ixml_headerfooter_elem->find_from_name( 'oddFooter' ). + IF lo_ixml_hf_value_elem IS NOT INITIAL. + ls_odd_footer-left_value = lo_ixml_hf_value_elem->get_value( ). + ENDIF. + +* 2do§1 Header/footer + " TODO.. get the rest. + + io_worksheet->sheet_setup->set_header_footer( ip_odd_header = ls_odd_header + ip_odd_footer = ls_odd_footer + ip_even_header = ls_even_header + ip_even_footer = ls_even_footer ). + + ENDIF. + + " Start fix 194 Read attributes HIDDEN, OUTLINELEVEL, COLLAPSED in ZCL_EXCEL_READER_2007 + " Read pane + lo_ixml_pane_elem = lo_ixml_sheetview_elem->find_from_name( name = 'pane' ). + IF lo_ixml_pane_elem IS BOUND. + fill_struct_from_attributes( EXPORTING ip_element = lo_ixml_pane_elem CHANGING cp_structure = ls_excel_pane ). + " Issue #194 + " Replace REGEX with method from the common class + zcl_excel_common=>convert_columnrow2column_a_row( EXPORTING + i_columnrow = ls_excel_pane-topleftcell + IMPORTING + e_column = lv_pane_cell_col_a " Cell Column + e_row = lv_pane_cell_row ). " Natural number + lv_pane_cell_col = zcl_excel_common=>convert_column2int( lv_pane_cell_col_a ). + SUBTRACT 1 FROM: lv_pane_cell_col, + lv_pane_cell_row. + IF lv_pane_cell_col > 0 + AND lv_pane_cell_row > 0. + io_worksheet->freeze_panes( ip_num_rows = lv_pane_cell_row + ip_num_columns = lv_pane_cell_col ). + ELSEIF lv_pane_cell_row > 0. + io_worksheet->freeze_panes( ip_num_rows = lv_pane_cell_row ). + ELSE. + io_worksheet->freeze_panes( ip_num_columns = lv_pane_cell_col ). + ENDIF. + ENDIF. + " End fix 194 Read attributes HIDDEN, OUTLINELEVEL, COLLAPSED in ZCL_EXCEL_READER_2007 + + " Start fix 276 Read data validations + lo_ixml_datavalidations = lo_ixml_worksheet->get_elements_by_tag_name( name = 'dataValidation' ). + lo_ixml_iterator = lo_ixml_datavalidations->create_iterator( ). + lo_ixml_datavalidation_elem ?= lo_ixml_iterator->get_next( ). + WHILE lo_ixml_datavalidation_elem IS BOUND. + fill_struct_from_attributes( EXPORTING + ip_element = lo_ixml_datavalidation_elem + CHANGING + cp_structure = ls_datavalidation ). + clear lo_ixml_formula_elem. + lo_ixml_formula_elem = lo_ixml_datavalidation_elem->find_from_name( name = 'formula1' ). + if lo_ixml_formula_elem is bound. + ls_datavalidation-formula1 = lo_ixml_formula_elem->get_value( ). + endif. + clear lo_ixml_formula_elem. + lo_ixml_formula_elem = lo_ixml_datavalidation_elem->find_from_name( name = 'formula2' ). + if lo_ixml_formula_elem is bound. + ls_datavalidation-formula2 = lo_ixml_formula_elem->get_value( ). + endif. + SPLIT ls_datavalidation-sqref AT space INTO TABLE lt_datavalidation_range. + LOOP AT lt_datavalidation_range INTO lv_datavalidation_range. + zcl_excel_common=>convert_range2column_a_row( EXPORTING + i_range = lv_datavalidation_range + IMPORTING + e_column_start = ls_datavalidation-cell_column + e_column_end = ls_datavalidation-cell_column_to + e_row_start = ls_datavalidation-cell_row + e_row_end = ls_datavalidation-cell_row_to ). + lo_data_validation = io_worksheet->add_new_data_validation( ). + lo_data_validation->type = ls_datavalidation-type. + lo_data_validation->allowblank = ls_datavalidation-allowblank. + lo_data_validation->showinputmessage = ls_datavalidation-showinputmessage. + lo_data_validation->showerrormessage = ls_datavalidation-showerrormessage. + lo_data_validation->showdropdown = ls_datavalidation-showdropdown. + lo_data_validation->operator = ls_datavalidation-operator. + lo_data_validation->formula1 = ls_datavalidation-formula1. + lo_data_validation->formula2 = ls_datavalidation-formula2. + lo_data_validation->prompttitle = ls_datavalidation-prompttitle. + lo_data_validation->prompt = ls_datavalidation-prompt. + lo_data_validation->errortitle = ls_datavalidation-errortitle. + lo_data_validation->error = ls_datavalidation-error. + lo_data_validation->errorstyle = ls_datavalidation-errorstyle. + lo_data_validation->cell_row = ls_datavalidation-cell_row. + lo_data_validation->cell_row_to = ls_datavalidation-cell_row_to. + lo_data_validation->cell_column = ls_datavalidation-cell_column. + lo_data_validation->cell_column_to = ls_datavalidation-cell_column_to. + endloop. + lo_ixml_datavalidation_elem ?= lo_ixml_iterator->get_next( ). + ENDWHILE. + " End fix 276 Read data validations + + endmethod. + + + + + + method LOAD_WORKSHEET_DRAWING. + + TYPES: BEGIN OF t_c_nv_pr, + name TYPE string, + id TYPE string, + END OF t_c_nv_pr. + + TYPES: BEGIN OF t_blip, + cstate TYPE string, + embed TYPE string, + END OF t_blip. + + TYPES: BEGIN OF t_chart, + id TYPE string, + END OF t_chart. + + CONSTANTS: lc_xml_attr_true TYPE string VALUE 'true', + lc_xml_attr_true_int TYPE string VALUE '1'. + CONSTANTS: lc_rel_chart TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart', + lc_rel_image TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image'. + + DATA: drawing TYPE REF TO if_ixml_document, + anchors TYPE REF TO if_ixml_node_collection, + node TYPE REF TO if_ixml_element, + coll_length TYPE i, + iterator TYPE REF TO if_ixml_node_iterator, + anchor_elem TYPE REF TO if_ixml_element, + + relationship TYPE t_relationship, + rel_drawings TYPE t_rel_drawings, + rel_drawing TYPE t_rel_drawing, + rels_drawing TYPE REF TO if_ixml_document, + rels_drawing_path TYPE string, + stripped_name TYPE chkfile, + dirname TYPE string, + + path TYPE string, + path2 TYPE text255, + file_ext2 TYPE char10. + + " Read Workbook Relationships + CALL FUNCTION 'TRINT_SPLIT_FILE_AND_PATH' + EXPORTING + full_name = ip_path + IMPORTING + stripped_name = stripped_name + file_path = dirname. + CONCATENATE dirname '_rels/' stripped_name '.rels' + INTO rels_drawing_path. + rels_drawing_path = resolve_path( rels_drawing_path ). + rels_drawing = me->get_ixml_from_zip_archive( rels_drawing_path ). + node ?= rels_drawing->find_from_name( 'Relationship' ). + WHILE node IS BOUND. + fill_struct_from_attributes( EXPORTING ip_element = node CHANGING cp_structure = relationship ). + + rel_drawing-id = relationship-id. + + CONCATENATE dirname relationship-target INTO path. + path = resolve_path( path ). + rel_drawing-content = me->get_from_zip_archive( path ). "------------> This is for template usage + + path2 = path. + zcl_excel_common=>split_file( EXPORTING ip_file = path2 + IMPORTING ep_extension = file_ext2 ). + rel_drawing-file_ext = file_ext2. + + "-------------Added by Alessandro Iannacci - Should load graph xml + CASE relationship-type. + WHEN lc_rel_chart. + "Read chart xml + rel_drawing-content_xml = me->get_ixml_from_zip_archive( path ). + WHEN OTHERS. + ENDCASE. + "---------------------------- + + + APPEND rel_drawing TO rel_drawings. + + node ?= node->get_next( ). + ENDWHILE. + + drawing = me->get_ixml_from_zip_archive( ip_path ). + +* one-cell anchor ************** + anchors = drawing->get_elements_by_tag_name( name = 'oneCellAnchor' namespace = 'xdr' ). + coll_length = anchors->get_length( ). + iterator = anchors->create_iterator( ). + DO coll_length TIMES. + anchor_elem ?= iterator->get_next( ). + + CALL METHOD me->load_drawing_anchor + EXPORTING + io_anchor_element = anchor_elem + io_worksheet = io_worksheet + it_related_drawings = rel_drawings. + + ENDDO. + +* two-cell anchor ****************** + anchors = drawing->get_elements_by_tag_name( name = 'twoCellAnchor' namespace = 'xdr' ). + coll_length = anchors->get_length( ). + iterator = anchors->create_iterator( ). + DO coll_length TIMES. + anchor_elem ?= iterator->get_next( ). + + CALL METHOD me->load_drawing_anchor + EXPORTING + io_anchor_element = anchor_elem + io_worksheet = io_worksheet + it_related_drawings = rel_drawings. + + ENDDO. + + 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. + + + + + method RESOLVE_PATH. +*--------------------------------------------------------------------* +* ToDos: +* 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 +* +* Please don't just delete these ToDos if they are not +* needed but leave a comment that states this +*--------------------------------------------------------------------* + +*--------------------------------------------------------------------* +* issue #230 - Pimp my Code +* - 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 +* The output should be a resolved path without relative references +* Example: Input xl/worksheets/../drawings/drawing1.xml +* Output xl/drawings/drawing1.xml +*--------------------------------------------------------------------* + + rp_result = ip_path. +*--------------------------------------------------------------------* +* §1 Remove relative pathnames +*--------------------------------------------------------------------* +* Regular expression [^/]*/\.\./ +* [^/]* --> any number of characters other than / +* followed by /\.\./ --> the sequence /../ +* ==> worksheets/../ will be found in the example +*--------------------------------------------------------------------* + REPLACE REGEX '[^/]*/\.\./' IN rp_result WITH ``. + + + endmethod. + + + method RESOLVE_REFERENCED_FORMULAE. + TYPES: BEGIN OF ty_referenced_cells, + sheet TYPE REF TO zcl_excel_worksheet, + si TYPE i, + row_from TYPE i, + row_to TYPE i, + col_from TYPE i, + col_to TYPE i, + formula TYPE string, + ref_cell TYPE char10, + END OF ty_referenced_cells. + + DATA: ls_ref_formula LIKE LINE OF me->mt_ref_formulae, + lts_referenced_cells TYPE SORTED TABLE OF ty_referenced_cells WITH NON-UNIQUE KEY sheet si row_from row_to col_from col_to, + ls_referenced_cell LIKE LINE OF lts_referenced_cells, + lv_col_from TYPE zexcel_cell_column_alpha, + lv_col_to TYPE zexcel_cell_column_alpha, + lv_resulting_formula TYPE string, + lv_current_cell TYPE char10. + + + me->mt_ref_formulae = me->mt_ref_formulae. + +*--------------------------------------------------------------------* +* Get referenced Cells, Build ranges for easy lookup +*--------------------------------------------------------------------* + LOOP AT me->mt_ref_formulae INTO ls_ref_formula WHERE ref <> space. + + CLEAR ls_referenced_cell. + ls_referenced_cell-sheet = ls_ref_formula-sheet. + ls_referenced_cell-si = ls_ref_formula-si. + ls_referenced_cell-formula = ls_ref_formula-formula. + + TRY. + zcl_excel_common=>convert_range2column_a_row( EXPORTING i_range = ls_ref_formula-ref + IMPORTING e_column_start = lv_col_from + e_column_end = lv_col_to + e_row_start = ls_referenced_cell-row_from + e_row_end = ls_referenced_cell-row_to ). + ls_referenced_cell-col_from = zcl_excel_common=>convert_column2int( lv_col_from ). + ls_referenced_cell-col_to = zcl_excel_common=>convert_column2int( lv_col_to ). + + + CLEAR ls_referenced_cell-ref_cell. + TRY. + ls_referenced_cell-ref_cell(3) = zcl_excel_common=>convert_column2alpha( ls_ref_formula-column ). + ls_referenced_cell-ref_cell+3 = ls_ref_formula-row. + CONDENSE ls_referenced_cell-ref_cell NO-GAPS. + CATCH zcx_excel. + ENDTRY. + + INSERT ls_referenced_cell INTO TABLE lts_referenced_cells. + CATCH zcx_excel. + ENDTRY. + + ENDLOOP. + +* break x0009004. +*--------------------------------------------------------------------* +* For each referencing cell determine the referenced cell +* and resolve the formula +*--------------------------------------------------------------------* + LOOP AT me->mt_ref_formulae INTO ls_ref_formula WHERE ref = space. + + + CLEAR lv_current_cell. + TRY. + lv_current_cell(3) = zcl_excel_common=>convert_column2alpha( ls_ref_formula-column ). + lv_current_cell+3 = ls_ref_formula-row. + CONDENSE lv_current_cell NO-GAPS. + CATCH zcx_excel. + ENDTRY. + + LOOP AT lts_referenced_cells INTO ls_referenced_cell WHERE sheet = ls_ref_formula-sheet + AND si = ls_ref_formula-si + AND row_from <= ls_ref_formula-row + AND row_to >= ls_ref_formula-row + AND col_from <= ls_ref_formula-column + AND col_to >= ls_ref_formula-column. + + TRY. + + lv_resulting_formula = zcl_excel_common=>determine_resulting_formula( iv_reference_cell = ls_referenced_cell-ref_cell + iv_reference_formula = ls_referenced_cell-formula + iv_current_cell = lv_current_cell ). + + ls_referenced_cell-sheet->set_cell_formula( ip_column = ls_ref_formula-column + ip_row = ls_ref_formula-row + ip_formula = lv_resulting_formula ). + CATCH zcx_excel. + ENDTRY. + EXIT. + + ENDLOOP. + + ENDLOOP. + 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. + + + + *"* 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. + + + + *"* 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. + 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. + + + + *"* 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. + + + + + *"* 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_WRITER~WRITE_FILE. + me->excel = io_excel. + + ep_file = me->create( ). + endmethod. + + + + 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( ). + + "-------------Added by Alessandro Iannacci - Only if template exist + IF lv_content IS NOT INITIAL AND me->excel->use_template EQ abap_true. + lv_value = lo_drawing->get_media_name( ). + CONCATENATE 'xl/charts/' lv_value INTO lv_value. + lo_zip->add( name = lv_value + content = lv_content ). + ELSE. "ADD CUSTOM CHART!!!! + lv_content = me->create_xl_charts( lo_drawing ). + lv_value = lo_drawing->get_media_name( ). + CONCATENATE 'xl/charts/' lv_value INTO lv_value. + lo_zip->add( name = lv_value + content = lv_content ). + ENDIF. + "------------------------------------------------- + ENDWHILE. + +********************************************************************** +* STEP 12: Create the final zip + ep_excel = lo_zip->save( ). + + endmethod. + + + + method CREATE_CONTENT_TYPES. + + +** Constant node name + DATA: lc_xml_node_types TYPE string VALUE 'Types', + lc_xml_node_override TYPE string VALUE 'Override', + 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', + " Node namespace + lc_xml_node_types_ns TYPE string VALUE 'http://schemas.openxmlformats.org/package/2006/content-types', + " Node extension + lc_xml_node_rels_ext TYPE string VALUE 'rels', + lc_xml_node_xml_ext TYPE string VALUE 'xml', + " Node partnumber + lc_xml_node_theme_pn TYPE string VALUE '/xl/theme/theme1.xml', + lc_xml_node_styles_pn TYPE string VALUE '/xl/styles.xml', + lc_xml_node_workb_pn TYPE string VALUE '/xl/workbook.xml', + lc_xml_node_props_pn TYPE string VALUE '/docProps/app.xml', + lc_xml_node_worksheet_pn TYPE string VALUE '/xl/worksheets/sheet#.xml', + lc_xml_node_strings_pn TYPE string VALUE '/xl/sharedStrings.xml', + lc_xml_node_core_pn TYPE string VALUE '/docProps/core.xml', + lc_xml_node_chart_pn TYPE string VALUE '/xl/charts/chart#.xml', + " Node contentType + lc_xml_node_theme_ct TYPE string VALUE 'application/vnd.openxmlformats-officedocument.theme+xml', + lc_xml_node_styles_ct TYPE string VALUE 'application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml', + lc_xml_node_workb_ct TYPE string VALUE 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml', + lc_xml_node_rels_ct TYPE string VALUE 'application/vnd.openxmlformats-package.relationships+xml', + lc_xml_node_xml_ct TYPE string VALUE 'application/xml', + lc_xml_node_props_ct TYPE string VALUE 'application/vnd.openxmlformats-officedocument.extended-properties+xml', + lc_xml_node_worksheet_ct TYPE string VALUE 'application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml', + lc_xml_node_strings_ct TYPE string VALUE 'application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml', + lc_xml_node_core_ct TYPE string VALUE 'application/vnd.openxmlformats-package.core-properties+xml', + lc_xml_node_table_ct TYPE string VALUE 'application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml', + lc_xml_node_drawings_ct TYPE string VALUE 'application/vnd.openxmlformats-officedocument.drawing+xml', + lc_xml_node_chart_ct TYPE string VALUE 'application/vnd.openxmlformats-officedocument.drawingml.chart+xml'. + + 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 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_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. + + DATA: lv_worksheets_num TYPE i, + lv_worksheets_numc TYPE numc3, + lv_xml_node_worksheet_pn TYPE string, + lv_xml_size TYPE i, + lv_value TYPE string, + lv_drawing_index TYPE i VALUE 1, + lv_index_str TYPE string. + +********************************************************************** +* STEP 1: Create [Content_Types].xml into the root of the ZIP + 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 ). + +********************************************************************** +* STEP 3: Create main node types + lo_element_root = lo_document->create_simple_element( name = lc_xml_node_types + parent = lo_document ). + lo_element_root->set_attribute_ns( name = 'xmlns' + value = lc_xml_node_types_ns ). + +********************************************************************** +* STEP 4: Create subnodes + + " rels 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_rels_ext ). + lo_element->set_attribute_ns( name = lc_xml_attr_contenttype + value = lc_xml_node_rels_ct ). + lo_element_root->append_child( new_child = lo_element ). + + " 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_xml_ext ). + lo_element->set_attribute_ns( name = lc_xml_attr_contenttype + value = lc_xml_node_xml_ct ). + lo_element_root->append_child( new_child = lo_element ). + + " Theme node + lo_element = lo_document->create_simple_element( name = lc_xml_node_override + parent = lo_document ). + lo_element->set_attribute_ns( name = lc_xml_attr_partname + value = lc_xml_node_theme_pn ). + lo_element->set_attribute_ns( name = lc_xml_attr_contenttype + value = lc_xml_node_theme_ct ). + lo_element_root->append_child( new_child = lo_element ). + + " Styles node + lo_element = lo_document->create_simple_element( name = lc_xml_node_override + parent = lo_document ). + lo_element->set_attribute_ns( name = lc_xml_attr_partname + value = lc_xml_node_styles_pn ). + lo_element->set_attribute_ns( name = lc_xml_attr_contenttype + value = lc_xml_node_styles_ct ). + lo_element_root->append_child( new_child = lo_element ). + + " Workbook node + lo_element = lo_document->create_simple_element( name = lc_xml_node_override + parent = lo_document ). + lo_element->set_attribute_ns( name = lc_xml_attr_partname + value = lc_xml_node_workb_pn ). + lo_element->set_attribute_ns( name = lc_xml_attr_contenttype + value = lc_xml_node_workb_ct ). + lo_element_root->append_child( new_child = lo_element ). + + " Properties node + lo_element = lo_document->create_simple_element( name = lc_xml_node_override + parent = lo_document ). + lo_element->set_attribute_ns( name = lc_xml_attr_partname + value = lc_xml_node_props_pn ). + lo_element->set_attribute_ns( name = lc_xml_attr_contenttype + value = lc_xml_node_props_ct ). + lo_element_root->append_child( new_child = lo_element ). + + " Worksheet node + lv_worksheets_num = excel->get_worksheets_size( ). + DO lv_worksheets_num TIMES. + lo_element = lo_document->create_simple_element( name = lc_xml_node_override + parent = lo_document ). + + MOVE sy-index TO lv_worksheets_numc. + SHIFT lv_worksheets_numc LEFT DELETING LEADING '0'. + lv_xml_node_worksheet_pn = lc_xml_node_worksheet_pn. + REPLACE ALL OCCURRENCES OF '#' IN lv_xml_node_worksheet_pn WITH lv_worksheets_numc. + lo_element->set_attribute_ns( name = lc_xml_attr_partname + value = lv_xml_node_worksheet_pn ). + lo_element->set_attribute_ns( name = lc_xml_attr_contenttype + value = lc_xml_node_worksheet_ct ). + lo_element_root->append_child( new_child = lo_element ). + ENDDO. + + lo_iterator = me->excel->get_worksheets_iterator( ). + WHILE lo_iterator->if_object_collection_iterator~has_next( ) EQ abap_true. + lo_worksheet ?= lo_iterator->if_object_collection_iterator~get_next( ). + + 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_value = lo_table->get_name( ). + CONCATENATE '/xl/tables/' lv_value '.xml' INTO lv_value. + + lo_element = lo_document->create_simple_element( name = lc_xml_node_override + parent = lo_document ). + lo_element->set_attribute_ns( name = lc_xml_attr_partname + value = lv_value ). + lo_element->set_attribute_ns( name = lc_xml_attr_contenttype + value = lc_xml_node_table_ct ). + lo_element_root->append_child( new_child = lo_element ). + ENDWHILE. + + " Drawings + DATA: lo_drawings TYPE REF TO zcl_excel_drawings. + + lo_drawings = lo_worksheet->get_drawings( ). + IF lo_drawings->is_empty( ) = abap_false. + lv_index_str = lv_drawing_index. + CONDENSE lv_index_str NO-GAPS. + CONCATENATE '/' me->c_xl_drawings INTO lv_value. + REPLACE '#' WITH lv_index_str INTO lv_value. + + lo_element = lo_document->create_simple_element( name = lc_xml_node_override + parent = lo_document ). + lo_element->set_attribute_ns( name = lc_xml_attr_partname + value = lv_value ). + lo_element->set_attribute_ns( name = lc_xml_attr_contenttype + value = lc_xml_node_drawings_ct ). + lo_element_root->append_child( new_child = lo_element ). + + ADD 1 TO lv_drawing_index. + ENDIF. + ENDWHILE. + + " media mimes + DATA: lo_drawing TYPE REF TO zcl_excel_drawing, + lt_media_type TYPE TABLE OF mimetypes-extension, + lv_media_type TYPE mimetypes-extension, + lv_mime_type TYPE mimetypes-type. + + lo_iterator = me->excel->get_drawings_iterator( zcl_excel_drawing=>type_image ). + WHILE lo_iterator->if_object_collection_iterator~has_next( ) = abap_true. + lo_drawing ?= lo_iterator->if_object_collection_iterator~get_next( ). + + lv_media_type = lo_drawing->get_media_type( ). + COLLECT lv_media_type INTO lt_media_type. + ENDWHILE. + + LOOP AT lt_media_type INTO lv_media_type. + CALL FUNCTION 'SDOK_MIMETYPE_GET' + EXPORTING + extension = lv_media_type + IMPORTING + mimetype = lv_mime_type. + + lo_element = lo_document->create_simple_element( name = lc_xml_node_default + parent = lo_document ). + lv_value = lv_media_type. + lo_element->set_attribute_ns( name = lc_xml_attr_extension + value = lv_value ). + lv_value = lv_mime_type. + lo_element->set_attribute_ns( name = lc_xml_attr_contenttype + value = lv_value ). + lo_element_root->append_child( new_child = lo_element ). + ENDLOOP. + + " Charts + lo_iterator = me->excel->get_drawings_iterator( zcl_excel_drawing=>type_chart ). + WHILE lo_iterator->if_object_collection_iterator~has_next( ) = abap_true. + lo_drawing ?= lo_iterator->if_object_collection_iterator~get_next( ). + + lo_element = lo_document->create_simple_element( name = lc_xml_node_override + parent = lo_document ). + lv_index_str = lo_drawing->get_index( ). + CONDENSE lv_index_str. + lv_value = lc_xml_node_chart_pn. + REPLACE ALL OCCURRENCES OF '#' IN lv_value WITH lv_index_str. + lo_element->set_attribute_ns( name = lc_xml_attr_partname + value = lv_value ). + lo_element->set_attribute_ns( name = lc_xml_attr_contenttype + value = lc_xml_node_chart_ct ). + lo_element_root->append_child( new_child = lo_element ). + ENDWHILE. + + " Strings node + lo_element = lo_document->create_simple_element( name = lc_xml_node_override + parent = lo_document ). + lo_element->set_attribute_ns( name = lc_xml_attr_partname + value = lc_xml_node_strings_pn ). + lo_element->set_attribute_ns( name = lc_xml_attr_contenttype + value = lc_xml_node_strings_ct ). + lo_element_root->append_child( new_child = lo_element ). + + " Strings node + lo_element = lo_document->create_simple_element( name = lc_xml_node_override + parent = lo_document ). + lo_element->set_attribute_ns( name = lc_xml_attr_partname + value = lc_xml_node_core_pn ). + lo_element->set_attribute_ns( name = lc_xml_attr_contenttype + value = lc_xml_node_core_ct ). + lo_element_root->append_child( new_child = lo_element ). + +********************************************************************** +* 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( ). + + endmethod. + + + + method CREATE_DOCPROPS_APP. + + +** Constant node name + DATA: lc_xml_node_properties TYPE string VALUE 'Properties', + lc_xml_node_application TYPE string VALUE 'Application', + lc_xml_node_docsecurity TYPE string VALUE 'DocSecurity', + lc_xml_node_scalecrop TYPE string VALUE 'ScaleCrop', + lc_xml_node_headingpairs TYPE string VALUE 'HeadingPairs', + lc_xml_node_vector TYPE string VALUE 'vector', + lc_xml_node_variant TYPE string VALUE 'variant', + lc_xml_node_lpstr TYPE string VALUE 'lpstr', + lc_xml_node_i4 TYPE string VALUE 'i4', + lc_xml_node_titlesofparts TYPE string VALUE 'TitlesOfParts', + lc_xml_node_company TYPE string VALUE 'Company', + lc_xml_node_linksuptodate TYPE string VALUE 'LinksUpToDate', + lc_xml_node_shareddoc TYPE string VALUE 'SharedDoc', + lc_xml_node_hyperlinkschanged TYPE string VALUE 'HyperlinksChanged', + lc_xml_node_appversion TYPE string VALUE 'AppVersion', + " Namespace prefix + lc_vt_ns TYPE string VALUE 'vt', + lc_xml_node_props_ns TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/extended-properties', + lc_xml_node_props_vt_ns TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes', + " Node attributes + lc_xml_attr_size TYPE string VALUE 'size', + lc_xml_attr_basetype TYPE string VALUE 'baseType'. + + 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 TYPE REF TO if_ixml_element, + lo_sub_element_vector TYPE REF TO if_ixml_element, + lo_sub_element_variant TYPE REF TO if_ixml_element, + lo_sub_element_lpstr TYPE REF TO if_ixml_element, + lo_sub_element_i4 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_worksheet TYPE REF TO zcl_excel_worksheet. + + DATA: lv_value TYPE string. + +********************************************************************** +* STEP 1: Create [Content_Types].xml into the root of the ZIP + 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 ). + +********************************************************************** +* STEP 3: Create main node properties + lo_element_root = lo_document->create_simple_element( name = lc_xml_node_properties + parent = lo_document ). + lo_element_root->set_attribute_ns( name = 'xmlns' + value = lc_xml_node_props_ns ). + lo_element_root->set_attribute_ns( name = 'xmlns:vt' + value = lc_xml_node_props_vt_ns ). + +********************************************************************** +* STEP 4: Create subnodes + " Application + lo_element = lo_document->create_simple_element( name = lc_xml_node_application + parent = lo_document ). + lv_value = excel->zif_excel_book_properties~application. + lo_element->set_value( value = lv_value ). + lo_element_root->append_child( new_child = lo_element ). + + " DocSecurity + lo_element = lo_document->create_simple_element( name = lc_xml_node_docsecurity + parent = lo_document ). + lv_value = excel->zif_excel_book_properties~docsecurity. + lo_element->set_value( value = lv_value ). + lo_element_root->append_child( new_child = lo_element ). + + " ScaleCrop + lo_element = lo_document->create_simple_element( name = lc_xml_node_scalecrop + parent = lo_document ). + lv_value = me->flag2bool( excel->zif_excel_book_properties~scalecrop ). + lo_element->set_value( value = lv_value ). + lo_element_root->append_child( new_child = lo_element ). + + " HeadingPairs + lo_element = lo_document->create_simple_element( name = lc_xml_node_headingpairs + parent = lo_document ). + + + " * vector node + lo_sub_element_vector = lo_document->create_simple_element_ns( name = lc_xml_node_vector + prefix = lc_vt_ns + parent = lo_document ). + lo_sub_element_vector->set_attribute_ns( name = lc_xml_attr_size + value = '2' ). + lo_sub_element_vector->set_attribute_ns( name = lc_xml_attr_basetype + value = lc_xml_node_variant ). + + " ** variant node + lo_sub_element_variant = lo_document->create_simple_element_ns( name = lc_xml_node_variant + prefix = lc_vt_ns + parent = lo_document ). + + " *** lpstr node + lo_sub_element_lpstr = lo_document->create_simple_element_ns( name = lc_xml_node_lpstr + prefix = lc_vt_ns + parent = lo_document ). + lv_value = excel->get_worksheets_name( ). + lo_sub_element_lpstr->set_value( value = lv_value ). + lo_sub_element_variant->append_child( new_child = lo_sub_element_lpstr ). " lpstr node + + lo_sub_element_vector->append_child( new_child = lo_sub_element_variant ). " variant node + + " ** variant node + lo_sub_element_variant = lo_document->create_simple_element_ns( name = lc_xml_node_variant + prefix = lc_vt_ns + parent = lo_document ). + + " *** i4 node + lo_sub_element_i4 = lo_document->create_simple_element_ns( name = lc_xml_node_i4 + prefix = lc_vt_ns + parent = lo_document ). + lv_value = excel->get_worksheets_size( ). + SHIFT lv_value RIGHT DELETING TRAILING space. + SHIFT lv_value LEFT DELETING LEADING space. + lo_sub_element_i4->set_value( value = lv_value ). + lo_sub_element_variant->append_child( new_child = lo_sub_element_i4 ). " lpstr node + + lo_sub_element_vector->append_child( new_child = lo_sub_element_variant ). " variant node + + lo_element->append_child( new_child = lo_sub_element_vector ). " vector node + + lo_element_root->append_child( new_child = lo_element ). " HeadingPairs + + + " TitlesOfParts + lo_element = lo_document->create_simple_element( name = lc_xml_node_titlesofparts + parent = lo_document ). + + + " * vector node + lo_sub_element_vector = lo_document->create_simple_element_ns( name = lc_xml_node_vector + prefix = lc_vt_ns + parent = lo_document ). + lv_value = excel->get_worksheets_size( ). + SHIFT lv_value RIGHT DELETING TRAILING space. + SHIFT lv_value LEFT DELETING LEADING space. + lo_sub_element_vector->set_attribute_ns( name = lc_xml_attr_size + value = lv_value ). + lo_sub_element_vector->set_attribute_ns( name = lc_xml_attr_basetype + value = lc_xml_node_lpstr ). + + lo_iterator = excel->get_worksheets_iterator( ). + + WHILE lo_iterator->if_object_collection_iterator~has_next( ) EQ abap_true. + " ** lpstr node + lo_sub_element_lpstr = lo_document->create_simple_element_ns( name = lc_xml_node_lpstr + prefix = lc_vt_ns + parent = lo_document ). + lo_worksheet ?= lo_iterator->if_object_collection_iterator~get_next( ). + lv_value = lo_worksheet->get_title( ). + lo_sub_element_lpstr->set_value( value = lv_value ). + lo_sub_element_vector->append_child( new_child = lo_sub_element_lpstr ). " lpstr node + ENDWHILE. + + lo_element->append_child( new_child = lo_sub_element_vector ). " vector node + + lo_element_root->append_child( new_child = lo_element ). " TitlesOfParts + + + + " Company + IF excel->zif_excel_book_properties~company IS NOT INITIAL. + lo_element = lo_document->create_simple_element( name = lc_xml_node_company + parent = lo_document ). + lv_value = excel->zif_excel_book_properties~company. + lo_element->set_value( value = lv_value ). + lo_element_root->append_child( new_child = lo_element ). + ENDIF. + + " LinksUpToDate + lo_element = lo_document->create_simple_element( name = lc_xml_node_linksuptodate + parent = lo_document ). + lv_value = me->flag2bool( excel->zif_excel_book_properties~linksuptodate ). + lo_element->set_value( value = lv_value ). + lo_element_root->append_child( new_child = lo_element ). + + " SharedDoc + lo_element = lo_document->create_simple_element( name = lc_xml_node_shareddoc + parent = lo_document ). + lv_value = me->flag2bool( excel->zif_excel_book_properties~shareddoc ). + lo_element->set_value( value = lv_value ). + lo_element_root->append_child( new_child = lo_element ). + + " HyperlinksChanged + lo_element = lo_document->create_simple_element( name = lc_xml_node_hyperlinkschanged + parent = lo_document ). + lv_value = me->flag2bool( excel->zif_excel_book_properties~hyperlinkschanged ). + lo_element->set_value( value = lv_value ). + lo_element_root->append_child( new_child = lo_element ). + + " AppVersion + lo_element = lo_document->create_simple_element( name = lc_xml_node_appversion + parent = lo_document ). + lv_value = excel->zif_excel_book_properties~appversion. + lo_element->set_value( value = lv_value ). + lo_element_root->append_child( new_child = lo_element ). + +********************************************************************** +* 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( ). + + endmethod. + + + + method CREATE_DOCPROPS_CORE. + + +** Constant node name + DATA: lc_xml_node_coreproperties TYPE string VALUE 'coreProperties', + lc_xml_node_creator TYPE string VALUE 'creator', + lc_xml_node_lastmodifiedby TYPE string VALUE 'lastModifiedBy', + lc_xml_node_created TYPE string VALUE 'created', + lc_xml_node_modified TYPE string VALUE 'modified', + " Node attributes + lc_xml_attr_type TYPE string VALUE 'type', + lc_xml_attr_target TYPE string VALUE 'dcterms:W3CDTF', + " Node namespace + lc_cp_ns TYPE string VALUE 'cp', + lc_dc_ns TYPE string VALUE 'dc', + lc_dcterms_ns TYPE string VALUE 'dcterms', +* lc_dcmitype_ns TYPE string VALUE 'dcmitype', + lc_xsi_ns TYPE string VALUE 'xsi', + lc_xml_node_cp_ns TYPE string VALUE 'http://schemas.openxmlformats.org/package/2006/metadata/core-properties', + lc_xml_node_dc_ns TYPE string VALUE 'http://purl.org/dc/elements/1.1/', + lc_xml_node_dcterms_ns TYPE string VALUE 'http://purl.org/dc/terms/', + lc_xml_node_dcmitype_ns TYPE string VALUE 'http://purl.org/dc/dcmitype/', + lc_xml_node_xsi_ns TYPE string VALUE 'http://www.w3.org/2001/XMLSchema-instance'. + + 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 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. + + DATA: lv_value TYPE string, + lv_date TYPE sydatum, + lv_time TYPE syuzeit. + +********************************************************************** +* STEP 1: Create [Content_Types].xml into the root of the ZIP + 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 ). + +********************************************************************** +* STEP 3: Create main node coreProperties + lo_element_root = lo_document->create_simple_element_ns( name = lc_xml_node_coreproperties + prefix = lc_cp_ns + parent = lo_document ). + lo_element_root->set_attribute_ns( name = 'xmlns:cp' + value = lc_xml_node_cp_ns ). + lo_element_root->set_attribute_ns( name = 'xmlns:dc' + value = lc_xml_node_dc_ns ). + lo_element_root->set_attribute_ns( name = 'xmlns:dcterms' + value = lc_xml_node_dcterms_ns ). + lo_element_root->set_attribute_ns( name = 'xmlns:dcmitype' + value = lc_xml_node_dcmitype_ns ). + lo_element_root->set_attribute_ns( name = 'xmlns:xsi' + value = lc_xml_node_xsi_ns ). + +********************************************************************** +* STEP 4: Create subnodes + " Creator node + lo_element = lo_document->create_simple_element_ns( name = lc_xml_node_creator + prefix = lc_dc_ns + parent = lo_document ). + lv_value = excel->zif_excel_book_properties~creator. + lo_element->set_value( value = lv_value ). + lo_element_root->append_child( new_child = lo_element ). + + " lastModifiedBy node + lo_element = lo_document->create_simple_element_ns( name = lc_xml_node_lastmodifiedby + prefix = lc_cp_ns + parent = lo_document ). + lv_value = excel->zif_excel_book_properties~lastmodifiedby. + lo_element->set_value( value = lv_value ). + lo_element_root->append_child( new_child = lo_element ). + + " Created node + lo_element = lo_document->create_simple_element_ns( name = lc_xml_node_created + prefix = lc_dcterms_ns + parent = lo_document ). + lo_element->set_attribute_ns( name = lc_xml_attr_type + prefix = lc_xsi_ns + value = lc_xml_attr_target ). + + CONVERT TIME STAMP excel->zif_excel_book_properties~created TIME ZONE sy-zonlo INTO DATE lv_date TIME lv_time. + CONCATENATE lv_date lv_time INTO lv_value RESPECTING BLANKS. + REPLACE ALL OCCURRENCES OF REGEX '([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})' IN lv_value WITH '$1-$2-$3T$4:$5:$6Z'. +* lv_value = excel->zif_excel_book_properties~created. +* lv_value = '2010-07-04T14:58:53Z'. + lo_element->set_value( value = lv_value ). + lo_element_root->append_child( new_child = lo_element ). + + " Modified node + lo_element = lo_document->create_simple_element_ns( name = lc_xml_node_modified + prefix = lc_dcterms_ns + parent = lo_document ). + lo_element->set_attribute_ns( name = lc_xml_attr_type + prefix = lc_xsi_ns + value = lc_xml_attr_target ). + CONVERT TIME STAMP excel->zif_excel_book_properties~modified TIME ZONE sy-zonlo INTO DATE lv_date TIME lv_time. + CONCATENATE lv_date lv_time INTO lv_value RESPECTING BLANKS. + REPLACE ALL OCCURRENCES OF REGEX '([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})' IN lv_value WITH '$1-$2-$3T$4:$5:$6Z'. +* lv_value = excel->zif_excel_book_properties~modified. +* lv_value = '2010-07-04T14:58:53Z'. + lo_element->set_value( value = lv_value ). + lo_element_root->append_child( new_child = lo_element ). + +********************************************************************** +* 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( ). + + endmethod. + + + + method CREATE_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 namespace + lc_xml_node_rels_ns TYPE string VALUE 'http://schemas.openxmlformats.org/package/2006/relationships', + " Node id + lc_xml_node_rId1_id TYPE string VALUE 'rId1', + lc_xml_node_rId2_id TYPE string VALUE 'rId2', + lc_xml_node_rId3_id TYPE string VALUE 'rId3', + " Node type + lc_xml_node_rId1_tp TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument', + lc_xml_node_rId2_tp TYPE string VALUE 'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties', + lc_xml_node_rId3_tp TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties', + " Node target + lc_xml_node_rId1_tg TYPE string VALUE 'xl/workbook.xml', + lc_xml_node_rId2_tg TYPE string VALUE 'docProps/core.xml', + lc_xml_node_rId3_tg TYPE string VALUE 'docProps/app.xml'. + + 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 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. + +********************************************************************** +* STEP 1: Create [Content_Types].xml into the root of the ZIP + 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 ). + +********************************************************************** +* STEP 3: Create main node relationships + lo_element_root = lo_document->create_simple_element( name = lc_xml_node_relationships + parent = lo_document ). + lo_element_root->set_attribute_ns( name = 'xmlns' + value = lc_xml_node_rels_ns ). + +********************************************************************** +* STEP 4: Create subnodes + " Theme node + lo_element = lo_document->create_simple_element( name = lc_xml_node_relationship + parent = lo_document ). + lo_element->set_attribute_ns( name = lc_xml_attr_id + value = lc_xml_node_rId3_id ). + lo_element->set_attribute_ns( name = lc_xml_attr_type + value = lc_xml_node_rId3_tp ). + lo_element->set_attribute_ns( name = lc_xml_attr_target + value = lc_xml_node_rId3_tg ). + lo_element_root->append_child( new_child = lo_element ). + + " Styles node + lo_element = lo_document->create_simple_element( name = lc_xml_node_relationship + parent = lo_document ). + lo_element->set_attribute_ns( name = lc_xml_attr_id + value = lc_xml_node_rId2_id ). + lo_element->set_attribute_ns( name = lc_xml_attr_type + value = lc_xml_node_rId2_tp ). + lo_element->set_attribute_ns( name = lc_xml_attr_target + value = lc_xml_node_rId2_tg ). + lo_element_root->append_child( new_child = lo_element ). + + " rels node + lo_element = lo_document->create_simple_element( name = lc_xml_node_relationship + parent = lo_document ). + lo_element->set_attribute_ns( name = lc_xml_attr_id + value = lc_xml_node_rId1_id ). + lo_element->set_attribute_ns( name = lc_xml_attr_type + value = lc_xml_node_rId1_tp ). + lo_element->set_attribute_ns( name = lc_xml_attr_target + value = lc_xml_node_rId1_tg ). + lo_element_root->append_child( new_child = lo_element ). + +********************************************************************** +* 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( ). + + endmethod. + + + + + method CREATE_XL_CHARTS. + + +** Constant node name + CONSTANTS: lc_xml_node_chartspace TYPE string VALUE 'c:chartSpace', + lc_xml_node_ns_c TYPE string VALUE 'http://schemas.openxmlformats.org/drawingml/2006/chart', + lc_xml_node_ns_a TYPE string VALUE 'http://schemas.openxmlformats.org/drawingml/2006/main', + lc_xml_node_ns_r TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships', + lc_xml_node_date1904 TYPE string VALUE 'c:date1904', + lc_xml_node_lang TYPE string VALUE 'c:lang', + lc_xml_node_roundedcorners TYPE string VALUE 'c:roundedCorners', + lc_xml_node_altcont TYPE string VALUE 'mc:AlternateContent', + lc_xml_node_altcont_ns_mc TYPE string VALUE 'http://schemas.openxmlformats.org/markup-compatibility/2006', + lc_xml_node_choice TYPE string VALUE 'mc:Choice', + lc_xml_node_choice_ns_requires TYPE string VALUE 'c14', + lc_xml_node_choice_ns_c14 TYPE string VALUE 'http://schemas.microsoft.com/office/drawing/2007/8/2/chart', + lc_xml_node_style TYPE string VALUE 'c14:style', + lc_xml_node_fallback TYPE string VALUE 'mc:Fallback', + lc_xml_node_style2 TYPE string VALUE 'c:style', + + "---------------------------CHART + lc_xml_node_chart TYPE string VALUE 'c:chart', + lc_xml_node_autotitledeleted TYPE string VALUE 'c:autoTitleDeleted', + "plotArea + lc_xml_node_plotarea TYPE string VALUE 'c:plotArea', + lc_xml_node_layout TYPE string VALUE 'c:layout', + lc_xml_node_varycolors TYPE string VALUE 'c:varyColors', + lc_xml_node_ser TYPE string VALUE 'c:ser', + lc_xml_node_idx TYPE string VALUE 'c:idx', + lc_xml_node_order TYPE string VALUE 'c:order', + lc_xml_node_tx TYPE string VALUE 'c:tx', + lc_xml_node_v TYPE string VALUE 'c:v', + lc_xml_node_val TYPE string VALUE 'c:val', + lc_xml_node_cat TYPE string VALUE 'c:cat', + lc_xml_node_numref TYPE string VALUE 'c:numRef', + lc_xml_node_strref TYPE string VALUE 'c:strRef', + lc_xml_node_f TYPE string VALUE 'c:f', "this is the range + "note: numcache avoided + lc_xml_node_dlbls TYPE string VALUE 'c:dLbls', + lc_xml_node_showlegendkey TYPE string VALUE 'c:showLegendKey', + lc_xml_node_showval TYPE string VALUE 'c:showVal', + lc_xml_node_showcatname TYPE string VALUE 'c:showCatName', + lc_xml_node_showsername TYPE string VALUE 'c:showSerName', + lc_xml_node_showpercent TYPE string VALUE 'c:showPercent', + lc_xml_node_showbubblesize TYPE string VALUE 'c:showBubbleSize', + "plotArea->pie + lc_xml_node_piechart TYPE string VALUE 'c:pieChart', + lc_xml_node_showleaderlines TYPE string VALUE 'c:showLeaderLines', + lc_xml_node_firstsliceang TYPE string VALUE 'c:firstSliceAng', + "plotArea->line + lc_xml_node_linechart TYPE string VALUE 'c:lineChart', + lc_xml_node_symbol TYPE string VALUE 'c:symbol', + lc_xml_node_marker TYPE string VALUE 'c:marker', + lc_xml_node_smooth TYPE string VALUE 'c:smooth', + "plotArea->bar + lc_xml_node_invertifnegative TYPE string VALUE 'c:invertIfNegative', + lc_xml_node_barchart TYPE string VALUE 'c:barChart', + lc_xml_node_bardir TYPE string VALUE 'c:barDir', + lc_xml_node_gapwidth TYPE string VALUE 'c:gapWidth', + "plotArea->line + plotArea->bar + lc_xml_node_grouping TYPE string VALUE 'c:grouping', + lc_xml_node_axid TYPE string VALUE 'c:axId', + lc_xml_node_catax TYPE string VALUE 'c:catAx', + lc_xml_node_valax TYPE string VALUE 'c:valAx', + lc_xml_node_scaling TYPE string VALUE 'c:scaling', + lc_xml_node_orientation TYPE string VALUE 'c:orientation', + lc_xml_node_delete TYPE string VALUE 'c:delete', + lc_xml_node_axpos TYPE string VALUE 'c:axPos', + lc_xml_node_numfmt TYPE string VALUE 'c:numFmt', + lc_xml_node_majorgridlines TYPE string VALUE 'c:majorGridlines', + lc_xml_node_majortickmark TYPE string VALUE 'c:majorTickMark', + lc_xml_node_minortickmark TYPE string VALUE 'c:minorTickMark', + lc_xml_node_ticklblpos TYPE string VALUE 'c:tickLblPos', + lc_xml_node_crossax TYPE string VALUE 'c:crossAx', + lc_xml_node_crosses TYPE string VALUE 'c:crosses', + lc_xml_node_auto TYPE string VALUE 'c:auto', + lc_xml_node_lblalgn TYPE string VALUE 'c:lblAlgn', + lc_xml_node_lbloffset TYPE string VALUE 'c:lblOffset', + lc_xml_node_nomultilvllbl TYPE string VALUE 'c:noMultiLvlLbl', + lc_xml_node_crossbetween TYPE string VALUE 'c:crossBetween', + "legend + lc_xml_node_legend TYPE string VALUE 'c:legend', + "legend->pie + lc_xml_node_legendpos TYPE string VALUE 'c:legendPos', +* lc_xml_node_layout TYPE string VALUE 'c:layout', "already exist + lc_xml_node_overlay TYPE string VALUE 'c:overlay', + lc_xml_node_txpr TYPE string VALUE 'c:txPr', + lc_xml_node_bodypr TYPE string VALUE 'a:bodyPr', + lc_xml_node_lststyle TYPE string VALUE 'a:lstStyle', + lc_xml_node_p TYPE string VALUE 'a:p', + lc_xml_node_ppr TYPE string VALUE 'a:pPr', + lc_xml_node_defrpr TYPE string VALUE 'a:defRPr', + lc_xml_node_endpararpr TYPE string VALUE 'a:endParaRPr', + "legend->bar + legend->line + lc_xml_node_plotvisonly TYPE string VALUE 'c:plotVisOnly', + lc_xml_node_dispblanksas TYPE string VALUE 'c:dispBlanksAs', + lc_xml_node_showdlblsovermax TYPE string VALUE 'c:showDLblsOverMax', + "---------------------------END OF CHART + + lc_xml_node_printsettings TYPE string VALUE 'c:printSettings', + lc_xml_node_headerfooter TYPE string VALUE 'c:headerFooter', + lc_xml_node_pagemargins TYPE string VALUE 'c:pageMargins', + lc_xml_node_pagesetup TYPE string VALUE 'c:pageSetup'. + + + 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_cellanchor 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. + DATA: lv_rel_id TYPE i. + + DATA lo_element TYPE REF TO if_ixml_element. + DATA lo_element2 TYPE REF TO if_ixml_element. + DATA lo_element3 TYPE REF TO if_ixml_element. + DATA lo_el_rootchart TYPE REF TO if_ixml_element. + DATA lo_element4 TYPE REF TO if_ixml_element. + DATA lo_element5 TYPE REF TO if_ixml_element. + DATA lo_element6 TYPE REF TO if_ixml_element. + DATA lo_element7 TYPE REF TO if_ixml_element. + +********************************************************************** +* STEP 1: Create [Content_Types].xml into the root of the ZIP + 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 ). + +*********************************************************************** +* STEP 3: Create main node relationships + lo_element_root = lo_document->create_simple_element( name = lc_xml_node_chartspace + parent = lo_document ). + lo_element_root->set_attribute_ns( name = 'xmlns:c' + value = lc_xml_node_ns_c ). + lo_element_root->set_attribute_ns( name = 'xmlns:a' + value = lc_xml_node_ns_a ). + lo_element_root->set_attribute_ns( name = 'xmlns:r' + value = lc_xml_node_ns_r ). + +********************************************************************** +* STEP 4: Create chart + + DATA lo_chartb TYPE REF TO zcl_excel_graph_bars. + DATA lo_chartp TYPE REF TO zcl_excel_graph_pie. + DATA lo_chartl TYPE REF TO zcl_excel_graph_line. + DATA lo_chart TYPE REF TO zcl_excel_graph. + + DATA ls_serie TYPE zcl_excel_graph=>s_series. + DATA ls_ax TYPE zcl_excel_graph_bars=>s_ax. + DATA lv_str TYPE string. + + "Identify chart type + CASE io_drawing->graph_type. + WHEN zcl_excel_drawing=>c_graph_bars. + lo_chartb ?= io_drawing->graph. + WHEN zcl_excel_drawing=>c_graph_pie. + lo_chartp ?= io_drawing->graph. + WHEN zcl_excel_drawing=>c_graph_line. + lo_chartl ?= io_drawing->graph. + WHEN OTHERS. + ENDCASE. + + + lo_chart = io_drawing->graph. + + lo_element = lo_document->create_simple_element( name = lc_xml_node_date1904 + parent = lo_element_root ). + lo_element->set_attribute_ns( name = 'val' + value = lo_chart->ns_1904val ). + + lo_element = lo_document->create_simple_element( name = lc_xml_node_lang + parent = lo_element_root ). + lo_element->set_attribute_ns( name = 'val' + value = lo_chart->ns_langval ). + + lo_element = lo_document->create_simple_element( name = lc_xml_node_roundedcorners + parent = lo_element_root ). + lo_element->set_attribute_ns( name = 'val' + value = lo_chart->ns_roundedcornersval ). + + lo_element = lo_document->create_simple_element( name = lc_xml_node_altcont + parent = lo_element_root ). + lo_element->set_attribute_ns( name = 'xmlns:mc' + value = lc_xml_node_altcont_ns_mc ). + + "Choice + lo_element2 = lo_document->create_simple_element( name = lc_xml_node_choice + parent = lo_element ). + lo_element2->set_attribute_ns( name = 'Requires' + value = lc_xml_node_choice_ns_requires ). + lo_element2->set_attribute_ns( name = 'xmlns:c14' + value = lc_xml_node_choice_ns_c14 ). + + "C14:style + lo_element3 = lo_document->create_simple_element( name = lc_xml_node_style + parent = lo_element2 ). + lo_element3->set_attribute_ns( name = 'val' + value = lo_chart->ns_c14styleval ). + + "Fallback + lo_element2 = lo_document->create_simple_element( name = lc_xml_node_fallback + parent = lo_element ). + + "C:style + lo_element3 = lo_document->create_simple_element( name = lc_xml_node_style2 + parent = lo_element2 ). + lo_element3->set_attribute_ns( name = 'val' + value = lo_chart->ns_styleval ). + + "---------------------------CHART + lo_element = lo_document->create_simple_element( name = lc_xml_node_chart + parent = lo_element_root ). + lo_element2 = lo_document->create_simple_element( name = lc_xml_node_autotitledeleted + parent = lo_element ). + lo_element2->set_attribute_ns( name = 'val' + value = lo_chart->ns_autotitledeletedval ). + + "plotArea + lo_element2 = lo_document->create_simple_element( name = lc_xml_node_plotarea + parent = lo_element ). + lo_element3 = lo_document->create_simple_element( name = lc_xml_node_layout + parent = lo_element2 ). + CASE io_drawing->graph_type. + WHEN zcl_excel_drawing=>c_graph_bars. + "----bar + lo_element3 = lo_document->create_simple_element( name = lc_xml_node_barchart + parent = lo_element2 ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_bardir + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = lo_chartb->ns_bardirval ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_grouping + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = lo_chartb->ns_groupingval ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_varycolors + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = lo_chartb->ns_varycolorsval ). + + "series + LOOP AT lo_chartb->series INTO ls_serie. + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_ser + parent = lo_element3 ). + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_idx + parent = lo_element4 ). + IF ls_serie-idx IS NOT INITIAL. + lv_str = ls_serie-idx. + ELSE. + lv_str = sy-tabix - 1. + ENDIF. + CONDENSE lv_str. + lo_element5->set_attribute_ns( name = 'val' + value = lv_str ). + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_order + parent = lo_element4 ). + lv_str = ls_serie-order. + CONDENSE lv_str. + lo_element5->set_attribute_ns( name = 'val' + value = lv_str ). + IF ls_serie-sername IS NOT INITIAL. + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_tx + parent = lo_element4 ). + lo_element6 = lo_document->create_simple_element( name = lc_xml_node_v + parent = lo_element5 ). + lo_element6->set_value( value = ls_serie-sername ). + ENDIF. + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_invertifnegative + parent = lo_element4 ). + lo_element5->set_attribute_ns( name = 'val' + value = ls_serie-invertifnegative ). + IF ls_serie-lbl IS NOT INITIAL. + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_cat + parent = lo_element4 ). + lo_element6 = lo_document->create_simple_element( name = lc_xml_node_strref + parent = lo_element5 ). + lo_element7 = lo_document->create_simple_element( name = lc_xml_node_f + parent = lo_element6 ). + lo_element7->set_value( value = ls_serie-lbl ). + ENDIF. + IF ls_serie-ref IS NOT INITIAL. + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_val + parent = lo_element4 ). + lo_element6 = lo_document->create_simple_element( name = lc_xml_node_numref + parent = lo_element5 ). + lo_element7 = lo_document->create_simple_element( name = lc_xml_node_f + parent = lo_element6 ). + lo_element7->set_value( value = ls_serie-ref ). + ENDIF. + ENDLOOP. + "endseries + + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_dlbls + parent = lo_element3 ). + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_showlegendkey + parent = lo_element4 ). + lo_element5->set_attribute_ns( name = 'val' + value = lo_chartb->ns_showlegendkeyval ). + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_showval + parent = lo_element4 ). + lo_element5->set_attribute_ns( name = 'val' + value = lo_chartb->ns_showvalval ). + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_showcatname + parent = lo_element4 ). + lo_element5->set_attribute_ns( name = 'val' + value = lo_chartb->ns_showcatnameval ). + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_showsername + parent = lo_element4 ). + lo_element5->set_attribute_ns( name = 'val' + value = lo_chartb->ns_showsernameval ). + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_showpercent + parent = lo_element4 ). + lo_element5->set_attribute_ns( name = 'val' + value = lo_chartb->ns_showpercentval ). + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_showbubblesize + parent = lo_element4 ). + lo_element5->set_attribute_ns( name = 'val' + value = lo_chartb->ns_showbubblesizeval ). + + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_gapwidth + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = lo_chartb->ns_gapwidthval ). + + "axes + lo_el_rootchart = lo_element3. + LOOP AT lo_chartb->axes INTO ls_ax. + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_axid + parent = lo_el_rootchart ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-axid ). + CASE ls_ax-type. + WHEN zcl_excel_graph_bars=>c_catax. + lo_element3 = lo_document->create_simple_element( name = lc_xml_node_catax + parent = lo_element2 ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_axid + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-axid ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_scaling + parent = lo_element3 ). + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_orientation + parent = lo_element4 ). + lo_element5->set_attribute_ns( name = 'val' + value = ls_ax-orientation ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_delete + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-delete ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_axpos + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-axpos ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_numfmt + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'formatCode' + value = ls_ax-formatcode ). + lo_element4->set_attribute_ns( name = 'sourceLinked' + value = ls_ax-sourcelinked ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_majortickmark + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-majortickmark ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_minortickmark + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-minortickmark ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_ticklblpos + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-ticklblpos ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_crossax + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-crossax ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_crosses + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-crosses ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_auto + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-auto ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_lblalgn + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-lblalgn ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_lbloffset + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-lbloffset ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_nomultilvllbl + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-nomultilvllbl ). + WHEN zcl_excel_graph_bars=>c_valax. + lo_element3 = lo_document->create_simple_element( name = lc_xml_node_valax + parent = lo_element2 ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_axid + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-axid ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_scaling + parent = lo_element3 ). + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_orientation + parent = lo_element4 ). + lo_element5->set_attribute_ns( name = 'val' + value = ls_ax-orientation ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_delete + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-delete ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_axpos + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-axpos ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_majorgridlines + parent = lo_element3 ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_numfmt + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'formatCode' + value = ls_ax-formatcode ). + lo_element4->set_attribute_ns( name = 'sourceLinked' + value = ls_ax-sourcelinked ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_majortickmark + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-majortickmark ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_minortickmark + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-minortickmark ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_ticklblpos + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-ticklblpos ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_crossax + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-crossax ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_crosses + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-crosses ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_crossbetween + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-crossbetween ). + WHEN OTHERS. + ENDCASE. + ENDLOOP. + "endaxes + + WHEN zcl_excel_drawing=>c_graph_pie. + "----pie + lo_element3 = lo_document->create_simple_element( name = lc_xml_node_piechart + parent = lo_element2 ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_varycolors + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = lo_chartp->ns_varycolorsval ). + + "series + LOOP AT lo_chartp->series INTO ls_serie. + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_ser + parent = lo_element3 ). + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_idx + parent = lo_element4 ). + IF ls_serie-idx IS NOT INITIAL. + lv_str = ls_serie-idx. + ELSE. + lv_str = sy-tabix - 1. + ENDIF. + CONDENSE lv_str. + lo_element5->set_attribute_ns( name = 'val' + value = lv_str ). + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_order + parent = lo_element4 ). + lv_str = ls_serie-order. + CONDENSE lv_str. + lo_element5->set_attribute_ns( name = 'val' + value = lv_str ). + IF ls_serie-sername IS NOT INITIAL. + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_tx + parent = lo_element4 ). + lo_element6 = lo_document->create_simple_element( name = lc_xml_node_v + parent = lo_element5 ). + lo_element6->set_value( value = ls_serie-sername ). + ENDIF. + IF ls_serie-lbl IS NOT INITIAL. + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_cat + parent = lo_element4 ). + lo_element6 = lo_document->create_simple_element( name = lc_xml_node_strref + parent = lo_element5 ). + lo_element7 = lo_document->create_simple_element( name = lc_xml_node_f + parent = lo_element6 ). + lo_element7->set_value( value = ls_serie-lbl ). + ENDIF. + IF ls_serie-ref IS NOT INITIAL. + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_val + parent = lo_element4 ). + lo_element6 = lo_document->create_simple_element( name = lc_xml_node_numref + parent = lo_element5 ). + lo_element7 = lo_document->create_simple_element( name = lc_xml_node_f + parent = lo_element6 ). + lo_element7->set_value( value = ls_serie-ref ). + ENDIF. + ENDLOOP. + "endseries + + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_dlbls + parent = lo_element3 ). + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_showlegendkey + parent = lo_element4 ). + lo_element5->set_attribute_ns( name = 'val' + value = lo_chartp->ns_showlegendkeyval ). + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_showval + parent = lo_element4 ). + lo_element5->set_attribute_ns( name = 'val' + value = lo_chartp->ns_showvalval ). + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_showcatname + parent = lo_element4 ). + lo_element5->set_attribute_ns( name = 'val' + value = lo_chartp->ns_showcatnameval ). + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_showsername + parent = lo_element4 ). + lo_element5->set_attribute_ns( name = 'val' + value = lo_chartp->ns_showsernameval ). + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_showpercent + parent = lo_element4 ). + lo_element5->set_attribute_ns( name = 'val' + value = lo_chartp->ns_showpercentval ). + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_showbubblesize + parent = lo_element4 ). + lo_element5->set_attribute_ns( name = 'val' + value = lo_chartp->ns_showbubblesizeval ). + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_showleaderlines + parent = lo_element4 ). + lo_element5->set_attribute_ns( name = 'val' + value = lo_chartp->ns_showleaderlinesval ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_firstsliceang + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = lo_chartp->ns_firstsliceangval ). + WHEN zcl_excel_drawing=>c_graph_line. + "----line + lo_element3 = lo_document->create_simple_element( name = lc_xml_node_linechart + parent = lo_element2 ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_grouping + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = lo_chartl->ns_groupingval ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_varycolors + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = lo_chartl->ns_varycolorsval ). + + "series + LOOP AT lo_chartl->series INTO ls_serie. + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_ser + parent = lo_element3 ). + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_idx + parent = lo_element4 ). + IF ls_serie-idx IS NOT INITIAL. + lv_str = ls_serie-idx. + ELSE. + lv_str = sy-tabix - 1. + ENDIF. + CONDENSE lv_str. + lo_element5->set_attribute_ns( name = 'val' + value = lv_str ). + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_order + parent = lo_element4 ). + lv_str = ls_serie-order. + CONDENSE lv_str. + lo_element5->set_attribute_ns( name = 'val' + value = lv_str ). + IF ls_serie-sername IS NOT INITIAL. + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_tx + parent = lo_element4 ). + lo_element6 = lo_document->create_simple_element( name = lc_xml_node_v + parent = lo_element5 ). + lo_element6->set_value( value = ls_serie-sername ). + ENDIF. + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_marker + parent = lo_element4 ). + lo_element6 = lo_document->create_simple_element( name = lc_xml_node_symbol + parent = lo_element5 ). + lo_element6->set_attribute_ns( name = 'val' + value = ls_serie-symbol ). + IF ls_serie-lbl IS NOT INITIAL. + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_cat + parent = lo_element4 ). + lo_element6 = lo_document->create_simple_element( name = lc_xml_node_strref + parent = lo_element5 ). + lo_element7 = lo_document->create_simple_element( name = lc_xml_node_f + parent = lo_element6 ). + lo_element7->set_value( value = ls_serie-lbl ). + ENDIF. + IF ls_serie-ref IS NOT INITIAL. + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_val + parent = lo_element4 ). + lo_element6 = lo_document->create_simple_element( name = lc_xml_node_numref + parent = lo_element5 ). + lo_element7 = lo_document->create_simple_element( name = lc_xml_node_f + parent = lo_element6 ). + lo_element7->set_value( value = ls_serie-ref ). + ENDIF. + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_smooth + parent = lo_element4 ). + lo_element5->set_attribute_ns( name = 'val' + value = ls_serie-smooth ). + ENDLOOP. + "endseries + + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_dlbls + parent = lo_element3 ). + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_showlegendkey + parent = lo_element4 ). + lo_element5->set_attribute_ns( name = 'val' + value = lo_chartl->ns_showlegendkeyval ). + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_showval + parent = lo_element4 ). + lo_element5->set_attribute_ns( name = 'val' + value = lo_chartl->ns_showvalval ). + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_showcatname + parent = lo_element4 ). + lo_element5->set_attribute_ns( name = 'val' + value = lo_chartl->ns_showcatnameval ). + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_showsername + parent = lo_element4 ). + lo_element5->set_attribute_ns( name = 'val' + value = lo_chartl->ns_showsernameval ). + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_showpercent + parent = lo_element4 ). + lo_element5->set_attribute_ns( name = 'val' + value = lo_chartl->ns_showpercentval ). + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_showbubblesize + parent = lo_element4 ). + lo_element5->set_attribute_ns( name = 'val' + value = lo_chartl->ns_showbubblesizeval ). + + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_marker + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = lo_chartl->NS_MARKERVAL ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_smooth + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = lo_chartl->NS_SMOOTHVAL ). + + "axes + lo_el_rootchart = lo_element3. + LOOP AT lo_chartl->axes INTO ls_ax. + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_axid + parent = lo_el_rootchart ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-axid ). + CASE ls_ax-type. + WHEN zcl_excel_graph_line=>c_catax. + lo_element3 = lo_document->create_simple_element( name = lc_xml_node_catax + parent = lo_element2 ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_axid + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-axid ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_scaling + parent = lo_element3 ). + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_orientation + parent = lo_element4 ). + lo_element5->set_attribute_ns( name = 'val' + value = ls_ax-orientation ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_delete + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-delete ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_axpos + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-axpos ). +* lo_element4 = lo_document->create_simple_element( name = lc_xml_node_numfmt +* parent = lo_element3 ). +* lo_element4->set_attribute_ns( name = 'formatCode' +* value = ls_ax-formatcode ). +* lo_element4->set_attribute_ns( name = 'sourceLinked' +* value = ls_ax-sourcelinked ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_majortickmark + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-majortickmark ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_minortickmark + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-minortickmark ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_ticklblpos + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-ticklblpos ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_crossax + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-crossax ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_crosses + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-crosses ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_auto + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-auto ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_lblalgn + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-lblalgn ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_lbloffset + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-lbloffset ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_nomultilvllbl + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-nomultilvllbl ). + WHEN zcl_excel_graph_line=>c_valax. + lo_element3 = lo_document->create_simple_element( name = lc_xml_node_valax + parent = lo_element2 ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_axid + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-axid ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_scaling + parent = lo_element3 ). + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_orientation + parent = lo_element4 ). + lo_element5->set_attribute_ns( name = 'val' + value = ls_ax-orientation ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_delete + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-delete ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_axpos + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-axpos ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_majorgridlines + parent = lo_element3 ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_numfmt + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'formatCode' + value = ls_ax-formatcode ). + lo_element4->set_attribute_ns( name = 'sourceLinked' + value = ls_ax-sourcelinked ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_majortickmark + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-majortickmark ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_minortickmark + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-minortickmark ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_ticklblpos + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-ticklblpos ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_crossax + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-crossax ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_crosses + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-crosses ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_crossbetween + parent = lo_element3 ). + lo_element4->set_attribute_ns( name = 'val' + value = ls_ax-crossbetween ). + WHEN OTHERS. + ENDCASE. + ENDLOOP. + "endaxes + + WHEN OTHERS. + ENDCASE. + + "legend + IF lo_chart->print_label EQ abap_true. + lo_element2 = lo_document->create_simple_element( name = lc_xml_node_legend + parent = lo_element ). + CASE io_drawing->graph_type. + WHEN zcl_excel_drawing=>c_graph_bars. + "----bar + lo_element3 = lo_document->create_simple_element( name = lc_xml_node_legendpos + parent = lo_element2 ). + lo_element3->set_attribute_ns( name = 'val' + value = lo_chartb->ns_legendposval ). + lo_element3 = lo_document->create_simple_element( name = lc_xml_node_layout + parent = lo_element2 ). + lo_element3 = lo_document->create_simple_element( name = lc_xml_node_overlay + parent = lo_element2 ). + lo_element3->set_attribute_ns( name = 'val' + value = lo_chartb->ns_overlayval ). + WHEN zcl_excel_drawing=>c_graph_line. + "----line + lo_element3 = lo_document->create_simple_element( name = lc_xml_node_legendpos + parent = lo_element2 ). + lo_element3->set_attribute_ns( name = 'val' + value = lo_chartl->ns_legendposval ). + lo_element3 = lo_document->create_simple_element( name = lc_xml_node_layout + parent = lo_element2 ). + lo_element3 = lo_document->create_simple_element( name = lc_xml_node_overlay + parent = lo_element2 ). + lo_element3->set_attribute_ns( name = 'val' + value = lo_chartl->ns_overlayval ). + WHEN zcl_excel_drawing=>c_graph_pie. + "----pie + lo_element3 = lo_document->create_simple_element( name = lc_xml_node_legendpos + parent = lo_element2 ). + lo_element3->set_attribute_ns( name = 'val' + value = lo_chartp->ns_legendposval ). + lo_element3 = lo_document->create_simple_element( name = lc_xml_node_layout + parent = lo_element2 ). + lo_element3 = lo_document->create_simple_element( name = lc_xml_node_overlay + parent = lo_element2 ). + lo_element3->set_attribute_ns( name = 'val' + value = lo_chartp->ns_overlayval ). + lo_element3 = lo_document->create_simple_element( name = lc_xml_node_txpr + parent = lo_element2 ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_bodypr + parent = lo_element3 ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_lststyle + parent = lo_element3 ). + lo_element4 = lo_document->create_simple_element( name = lc_xml_node_p + parent = lo_element3 ). + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_ppr + parent = lo_element4 ). + lo_element5->set_attribute_ns( name = 'rtl' + value = lo_chartp->ns_pprrtl ). + lo_element6 = lo_document->create_simple_element( name = lc_xml_node_defrpr + parent = lo_element5 ). + lo_element5 = lo_document->create_simple_element( name = lc_xml_node_endpararpr + parent = lo_element4 ). + lo_element5->set_attribute_ns( name = 'lang' + value = lo_chartp->ns_endpararprlang ). + WHEN OTHERS. + ENDCASE. + ENDIF. + + lo_element2 = lo_document->create_simple_element( name = lc_xml_node_plotvisonly + parent = lo_element ). + lo_element2->set_attribute_ns( name = 'val' + value = lo_chart->ns_plotvisonlyval ). + lo_element2 = lo_document->create_simple_element( name = lc_xml_node_dispblanksas + parent = lo_element ). + lo_element2->set_attribute_ns( name = 'val' + value = lo_chart->ns_dispblanksasval ). + lo_element2 = lo_document->create_simple_element( name = lc_xml_node_showdlblsovermax + parent = lo_element ). + lo_element2->set_attribute_ns( name = 'val' + value = lo_chart->ns_showdlblsovermaxval ). + "---------------------------END OF CHART + + "printSettings + lo_element = lo_document->create_simple_element( name = lc_xml_node_printsettings + parent = lo_element_root ). + "headerFooter + lo_element2 = lo_document->create_simple_element( name = lc_xml_node_headerfooter + parent = lo_element ). + "pageMargins + lo_element2 = lo_document->create_simple_element( name = lc_xml_node_pagemargins + parent = lo_element ). + lo_element2->set_attribute_ns( name = 'b' + value = lo_chart->pagemargins-b ). + lo_element2->set_attribute_ns( name = 'l' + value = lo_chart->pagemargins-l ). + lo_element2->set_attribute_ns( name = 'r' + value = lo_chart->pagemargins-r ). + lo_element2->set_attribute_ns( name = 't' + value = lo_chart->pagemargins-t ). + lo_element2->set_attribute_ns( name = 'header' + value = lo_chart->pagemargins-header ). + lo_element2->set_attribute_ns( name = 'footer' + value = lo_chart->pagemargins-footer ). + "pageSetup + lo_element2 = lo_document->create_simple_element( name = lc_xml_node_pagesetup + parent = lo_element ). + +********************************************************************** +* 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( ). + + endmethod. + + + + + method CREATE_XL_DRAWINGS. + + +** Constant node name + CONSTANTS: lc_xml_node_wsdr TYPE string VALUE 'xdr:wsDr', + lc_xml_node_ns_xdr TYPE string VALUE 'http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing', + lc_xml_node_ns_a TYPE string VALUE 'http://schemas.openxmlformats.org/drawingml/2006/main'. + + CONSTANTS: lc_on TYPE string VALUE '1', + lc_off TYPE string VALUE '0'. + + 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_cellanchor 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_drawings TYPE REF TO zcl_excel_drawings, + lo_drawing TYPE REF TO zcl_excel_drawing. + DATA: lv_rel_id TYPE i. + + + +********************************************************************** +* STEP 1: Create [Content_Types].xml into the root of the ZIP + 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 ). + +*********************************************************************** +* STEP 3: Create main node relationships + lo_element_root = lo_document->create_simple_element( name = lc_xml_node_wsdr + parent = lo_document ). + lo_element_root->set_attribute_ns( name = 'xmlns:xdr' + value = lc_xml_node_ns_xdr ). + lo_element_root->set_attribute_ns( name = 'xmlns:a' + value = lc_xml_node_ns_a ). + +********************************************************************** +* STEP 4: Create drawings + + CLEAR: lv_rel_id. + + lo_drawings = io_worksheet->get_drawings( ). + + lo_iterator = lo_drawings->get_iterator( ). + WHILE lo_iterator->if_object_collection_iterator~has_next( ) EQ abap_true. + lo_drawing ?= lo_iterator->if_object_collection_iterator~get_next( ). + + ADD 1 TO lv_rel_id. + lo_element_cellanchor = me->create_xl_drawing_anchor( + io_drawing = lo_drawing + io_document = lo_document + ip_index = lv_rel_id ). + + lo_element_root->append_child( new_child = lo_element_cellanchor ). + + ENDWHILE. + +********************************************************************** +* 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( ). + + endmethod. + + + + + method CREATE_XL_DRAWINGS_RELS. + +** 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 namespace + lc_xml_node_rels_ns TYPE string VALUE 'http://schemas.openxmlformats.org/package/2006/relationships', + lc_xml_node_rid_image_tp TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', + lc_xml_node_rid_chart_tp TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart'. + + 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 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_drawings TYPE REF TO zcl_excel_drawings, + lo_drawing TYPE REF TO zcl_excel_drawing. + + DATA: lv_value TYPE string, + lv_counter TYPE i. + +********************************************************************** +* STEP 1: Create [Content_Types].xml into the root of the ZIP + 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 ). + +********************************************************************** +* STEP 3: Create main node relationships + lo_element_root = lo_document->create_simple_element( name = lc_xml_node_relationships + parent = lo_document ). + lo_element_root->set_attribute_ns( name = 'xmlns' + value = lc_xml_node_rels_ns ). + +********************************************************************** +* STEP 4: Create subnodes + + " Add sheet Relationship nodes here + lv_counter = 0. + lo_drawings = io_worksheet->get_drawings( ). + lo_iterator = lo_drawings->get_iterator( ). + WHILE lo_iterator->if_object_collection_iterator~has_next( ) EQ abap_true. + lo_drawing ?= lo_iterator->if_object_collection_iterator~get_next( ). + ADD 1 TO lv_counter. + + lv_value = lv_counter. + CONDENSE lv_value. + CONCATENATE 'rId' lv_value INTO lv_value. + + lo_element = lo_document->create_simple_element( name = lc_xml_node_relationship + parent = lo_document ). + lo_element->set_attribute_ns( name = lc_xml_attr_id + value = lv_value ). + + lv_value = lo_drawing->get_media_name( ). + CASE lo_drawing->get_type( ). + WHEN zcl_excel_drawing=>type_image. + CONCATENATE '../media/' lv_value INTO lv_value. + lo_element->set_attribute_ns( name = lc_xml_attr_type + value = lc_xml_node_rid_image_tp ). + + WHEN zcl_excel_drawing=>type_chart. + CONCATENATE '../charts/' lv_value INTO lv_value. + lo_element->set_attribute_ns( name = lc_xml_attr_type + value = lc_xml_node_rid_chart_tp ). + + ENDCASE. + lo_element->set_attribute_ns( name = lc_xml_attr_target + value = lv_value ). + lo_element_root->append_child( new_child = lo_element ). + ENDWHILE. + + +********************************************************************** +* 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( ). + + endmethod. + + + + + + + method CREATE_XL_DRAWING_ANCHOR. + +** Constant node name + CONSTANTS: lc_xml_node_onecellanchor TYPE string VALUE 'xdr:oneCellAnchor', + lc_xml_node_twocellanchor TYPE string VALUE 'xdr:twoCellAnchor', + lc_xml_node_from TYPE string VALUE 'xdr:from', + lc_xml_node_to TYPE string VALUE 'xdr:to', + lc_xml_node_pic TYPE string VALUE 'xdr:pic', + lc_xml_node_ext TYPE string VALUE 'xdr:ext', + lc_xml_node_clientdata TYPE string VALUE 'xdr:clientData', + + lc_xml_node_col TYPE string VALUE 'xdr:col', + lc_xml_node_coloff TYPE string VALUE 'xdr:colOff', + lc_xml_node_row TYPE string VALUE 'xdr:row', + lc_xml_node_rowoff TYPE string VALUE 'xdr:rowOff', + + lc_xml_node_nvpicpr TYPE string VALUE 'xdr:nvPicPr', + lc_xml_node_cnvpr TYPE string VALUE 'xdr:cNvPr', + lc_xml_node_cnvpicpr TYPE string VALUE 'xdr:cNvPicPr', + lc_xml_node_piclocks TYPE string VALUE 'a:picLocks', + + lc_xml_node_sppr TYPE string VALUE 'xdr:spPr', + lc_xml_node_apgeom TYPE string VALUE 'a:prstGeom', + lc_xml_node_aavlst TYPE string VALUE 'a:avLst', + + lc_xml_node_graphicframe TYPE string VALUE 'xdr:graphicFrame', + lc_xml_node_nvgraphicframepr TYPE string VALUE 'xdr:nvGraphicFramePr', + lc_xml_node_cnvgraphicframepr TYPE string VALUE 'xdr:cNvGraphicFramePr', + lc_xml_node_graphicframelocks TYPE string VALUE 'a:graphicFrameLocks', + lc_xml_node_xfrm TYPE string VALUE 'xdr:xfrm', + lc_xml_node_aoff TYPE string VALUE 'a:off', + lc_xml_node_aext TYPE string VALUE 'a:ext', + lc_xml_node_agraphic TYPE string VALUE 'a:graphic', + lc_xml_node_agraphicdata TYPE string VALUE 'a:graphicData', + + lc_xml_node_ns_c TYPE string VALUE 'http://schemas.openxmlformats.org/drawingml/2006/chart', + lc_xml_node_cchart TYPE string VALUE 'c:chart', + + lc_xml_node_blipfill TYPE string VALUE 'xdr:blipFill', + lc_xml_node_ablip TYPE string VALUE 'a:blip', + lc_xml_node_astretch TYPE string VALUE 'a:stretch', + lc_xml_node_ns_r TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'. + + + CONSTANTS: lc_on TYPE string VALUE '1', + lc_off TYPE string VALUE '0'. + + DATA: lo_element_graphicframe TYPE REF TO if_ixml_element, + lo_element TYPE REF TO if_ixml_element, + lo_element2 TYPE REF TO if_ixml_element, + lo_element3 TYPE REF TO if_ixml_element, + lo_element_from TYPE REF TO if_ixml_element, + lo_element_to TYPE REF TO if_ixml_element, + lo_element_ext TYPE REF TO if_ixml_element, + lo_element_pic TYPE REF TO if_ixml_element, + lo_element_clientdata TYPE REF TO if_ixml_element, + + ls_position TYPE zexcel_drawing_position, + + lv_col TYPE string, " zexcel_cell_column, + lv_row TYPE string, " zexcel_cell_row. + lv_col_offset TYPE string, + lv_row_offset TYPE string, + lv_value TYPE string. + + ls_position = io_drawing->get_position( ). + + IF ls_position-anchor = 'ONE'. + ep_anchor = io_document->create_simple_element( name = lc_xml_node_onecellanchor + parent = io_document ). + ELSE. + ep_anchor = io_document->create_simple_element( name = lc_xml_node_twocellanchor + parent = io_document ). + ENDIF. + +* from cell ****************************** + lo_element_from = io_document->create_simple_element( name = lc_xml_node_from + parent = io_document ). + + lv_col = ls_position-from-col. + lv_row = ls_position-from-row. + lv_col_offset = ls_position-from-col_offset. + lv_row_offset = ls_position-from-row_offset. + CONDENSE lv_col NO-GAPS. + CONDENSE lv_row NO-GAPS. + CONDENSE lv_col_offset NO-GAPS. + CONDENSE lv_row_offset NO-GAPS. + + lo_element = io_document->create_simple_element( name = lc_xml_node_col + parent = io_document ). + lo_element->set_value( value = lv_col ). + lo_element_from->append_child( new_child = lo_element ). + + lo_element = io_document->create_simple_element( name = lc_xml_node_coloff + parent = io_document ). + lo_element->set_value( value = lv_col_offset ). + lo_element_from->append_child( new_child = lo_element ). + + lo_element = io_document->create_simple_element( name = lc_xml_node_row + parent = io_document ). + lo_element->set_value( value = lv_row ). + lo_element_from->append_child( new_child = lo_element ). + + lo_element = io_document->create_simple_element( name = lc_xml_node_rowoff + parent = io_document ). + lo_element->set_value( value = lv_row_offset ). + lo_element_from->append_child( new_child = lo_element ). + ep_anchor->append_child( new_child = lo_element_from ). + + IF ls_position-anchor = 'ONE'. + +* ext ****************************** + lo_element_ext = io_document->create_simple_element( name = lc_xml_node_ext + parent = io_document ). + + lv_value = io_drawing->get_width_emu_str( ). + lo_element_ext->set_attribute_ns( name = 'cx' + value = lv_value ). + lv_value = io_drawing->get_height_emu_str( ). + lo_element_ext->set_attribute_ns( name = 'cy' + value = lv_value ). + ep_anchor->append_child( new_child = lo_element_ext ). + + ELSEIF ls_position-anchor = 'TWO'. + +* to cell ****************************** + lo_element_to = io_document->create_simple_element( name = lc_xml_node_to + parent = io_document ). + + lv_col = ls_position-to-col. + lv_row = ls_position-to-row. + lv_col_offset = ls_position-to-col_offset. + lv_row_offset = ls_position-to-row_offset. + CONDENSE lv_col NO-GAPS. + CONDENSE lv_row NO-GAPS. + CONDENSE lv_col_offset NO-GAPS. + CONDENSE lv_row_offset NO-GAPS. + + lo_element = io_document->create_simple_element( name = lc_xml_node_col + parent = io_document ). + lo_element->set_value( value = lv_col ). + lo_element_to->append_child( new_child = lo_element ). + + lo_element = io_document->create_simple_element( name = lc_xml_node_coloff + parent = io_document ). + lo_element->set_value( value = lv_col_offset ). + lo_element_to->append_child( new_child = lo_element ). + + lo_element = io_document->create_simple_element( name = lc_xml_node_row + parent = io_document ). + lo_element->set_value( value = lv_row ). + lo_element_to->append_child( new_child = lo_element ). + + lo_element = io_document->create_simple_element( name = lc_xml_node_rowoff + parent = io_document ). + lo_element->set_value( value = lv_row_offset ). + lo_element_to->append_child( new_child = lo_element ). + ep_anchor->append_child( new_child = lo_element_to ). + + ENDIF. + + CASE io_drawing->get_type( ). + WHEN zcl_excel_drawing=>type_image. +* pic ********************************** + lo_element_pic = io_document->create_simple_element( name = lc_xml_node_pic + parent = io_document ). +* nvPicPr + lo_element = io_document->create_simple_element( name = lc_xml_node_nvpicpr + parent = io_document ). +* cNvPr + lo_element2 = io_document->create_simple_element( name = lc_xml_node_cnvpr + parent = io_document ). + lv_value = sy-index. + CONDENSE lv_value. + lo_element2->set_attribute_ns( name = 'id' + value = lv_value ). + lo_element2->set_attribute_ns( name = 'name' + value = io_drawing->title ). + lo_element->append_child( new_child = lo_element2 ). + +* cNvPicPr + lo_element2 = io_document->create_simple_element( name = lc_xml_node_cnvpicpr + parent = io_document ). + +* picLocks + lo_element3 = io_document->create_simple_element( name = lc_xml_node_piclocks + parent = io_document ). + lo_element3->set_attribute_ns( name = 'noChangeAspect' + value = '1' ). + + lo_element2->append_child( new_child = lo_element3 ). + lo_element->append_child( new_child = lo_element2 ). + lo_element_pic->append_child( new_child = lo_element ). + +* blipFill + lv_value = ip_index. + CONDENSE lv_value. + CONCATENATE 'rId' lv_value INTO lv_value. + + lo_element = io_document->create_simple_element( name = lc_xml_node_blipfill + parent = io_document ). + lo_element2 = io_document->create_simple_element( name = lc_xml_node_ablip + parent = io_document ). + lo_element2->set_attribute_ns( name = 'xmlns:r' + value = lc_xml_node_ns_r ). + lo_element2->set_attribute_ns( name = 'r:embed' + value = lv_value ). + lo_element->append_child( new_child = lo_element2 ). + + lo_element2 = io_document->create_simple_element( name = lc_xml_node_astretch + parent = io_document ). + lo_element->append_child( new_child = lo_element2 ). + + lo_element_pic->append_child( new_child = lo_element ). + +* spPr + lo_element = io_document->create_simple_element( name = lc_xml_node_sppr + parent = io_document ). + + lo_element2 = io_document->create_simple_element( name = lc_xml_node_apgeom + parent = io_document ). + lo_element2->set_attribute_ns( name = 'prst' + value = 'rect' ). + lo_element3 = io_document->create_simple_element( name = lc_xml_node_aavlst + parent = io_document ). + lo_element2->append_child( new_child = lo_element3 ). + lo_element->append_child( new_child = lo_element2 ). + + lo_element_pic->append_child( new_child = lo_element ). + ep_anchor->append_child( new_child = lo_element_pic ). + WHEN zcl_excel_drawing=>type_chart. +* graphicFrame ********************************** + lo_element_graphicframe = io_document->create_simple_element( name = lc_xml_node_graphicframe + parent = io_document ). +* nvGraphicFramePr + lo_element = io_document->create_simple_element( name = lc_xml_node_nvgraphicframepr + parent = io_document ). +* cNvPr + lo_element2 = io_document->create_simple_element( name = lc_xml_node_cnvpr + parent = io_document ). + lv_value = sy-index. + CONDENSE lv_value. + lo_element2->set_attribute_ns( name = 'id' + value = lv_value ). + lo_element2->set_attribute_ns( name = 'name' + value = io_drawing->title ). + lo_element->append_child( new_child = lo_element2 ). +* cNvGraphicFramePr + lo_element2 = io_document->create_simple_element( name = lc_xml_node_cnvgraphicframepr + parent = io_document ). + lo_element3 = io_document->create_simple_element( name = lc_xml_node_graphicframelocks + parent = io_document ). + lo_element2->append_child( new_child = lo_element3 ). + lo_element->append_child( new_child = lo_element2 ). + lo_element_graphicframe->append_child( new_child = lo_element ). + +* xfrm + lo_element = io_document->create_simple_element( name = lc_xml_node_xfrm + parent = io_document ). +* off + lo_element2 = io_document->create_simple_element( name = lc_xml_node_aoff + parent = io_document ). + lo_element2->set_attribute_ns( name = 'y' value = '0' ). + lo_element2->set_attribute_ns( name = 'x' value = '0' ). + lo_element->append_child( new_child = lo_element2 ). +* ext + lo_element2 = io_document->create_simple_element( name = lc_xml_node_aext + parent = io_document ). + lo_element2->set_attribute_ns( name = 'cy' value = '0' ). + lo_element2->set_attribute_ns( name = 'cx' value = '0' ). + lo_element->append_child( new_child = lo_element2 ). + lo_element_graphicframe->append_child( new_child = lo_element ). + +* graphic + lo_element = io_document->create_simple_element( name = lc_xml_node_agraphic + parent = io_document ). +* graphicData + lo_element2 = io_document->create_simple_element( name = lc_xml_node_agraphicdata + parent = io_document ). + lo_element2->set_attribute_ns( name = 'uri' value = lc_xml_node_ns_c ). + +* chart + lo_element3 = io_document->create_simple_element( name = lc_xml_node_cchart + parent = io_document ). + + lo_element3->set_attribute_ns( name = 'xmlns:r' + value = lc_xml_node_ns_r ). + lo_element3->set_attribute_ns( name = 'xmlns:c' + value = lc_xml_node_ns_c ). + + lv_value = ip_index. + CONDENSE lv_value. + CONCATENATE 'rId' lv_value INTO lv_value. + lo_element3->set_attribute_ns( name = 'r:id' + value = lv_value ). + lo_element2->append_child( new_child = lo_element3 ). + lo_element->append_child( new_child = lo_element2 ). + lo_element_graphicframe->append_child( new_child = lo_element ). + ep_anchor->append_child( new_child = lo_element_graphicframe ). + + ENDCASE. + +* client data *************************** + lo_element_clientdata = io_document->create_simple_element( name = lc_xml_node_clientdata + parent = io_document ). + ep_anchor->append_child( new_child = lo_element_clientdata ). + + 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 namespace + lc_xml_node_rels_ns TYPE string VALUE 'http://schemas.openxmlformats.org/package/2006/relationships', + " Node id + lc_xml_node_ridx_id TYPE string VALUE 'rId#', + " Node type + lc_xml_node_rid_sheet_tp TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet', + lc_xml_node_rid_theme_tp TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme', + lc_xml_node_rid_styles_tp TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles', + lc_xml_node_rid_shared_tp TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings', + " Node target + lc_xml_node_ridx_tg TYPE string VALUE 'worksheets/sheet#.xml', + lc_xml_node_rid_shared_tg TYPE string VALUE 'sharedStrings.xml', + lc_xml_node_rid_styles_tg TYPE string VALUE 'styles.xml', + lc_xml_node_rid_theme_tg TYPE string VALUE 'theme/theme1.xml'. + + 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 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. + + DATA: lv_xml_node_ridx_tg TYPE string, + lv_xml_node_ridx_id TYPE string, + lv_size TYPE i, + lv_syindex(3) TYPE c. + +********************************************************************** +* STEP 1: Create [Content_Types].xml into the root of the ZIP + 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 ). + +********************************************************************** +* STEP 3: Create main node relationships + lo_element_root = lo_document->create_simple_element( name = lc_xml_node_relationships + parent = lo_document ). + lo_element_root->set_attribute_ns( name = 'xmlns' + value = lc_xml_node_rels_ns ). + +********************************************************************** +* STEP 4: Create subnodes + + lv_size = excel->get_worksheets_size( ). + + " Relationship node + lo_element = lo_document->create_simple_element( name = lc_xml_node_relationship + parent = lo_document ). + lv_size = lv_size + 2. + 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_styles_tp ). + lo_element->set_attribute_ns( name = lc_xml_attr_target + value = lc_xml_node_rid_styles_tg ). + lo_element_root->append_child( new_child = lo_element ). + + + " Relationship node + lo_element = lo_document->create_simple_element( name = lc_xml_node_relationship + parent = lo_document ). + lv_size = lv_size - 1. + 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_theme_tp ). + lo_element->set_attribute_ns( name = lc_xml_attr_target + value = lc_xml_node_rid_theme_tg ). + lo_element_root->append_child( new_child = lo_element ). + + lv_size = excel->get_worksheets_size( ). + + DO lv_size TIMES. + " Relationship node + lo_element = lo_document->create_simple_element( name = lc_xml_node_relationship + parent = lo_document ). + lv_xml_node_ridx_id = lc_xml_node_ridx_id. + lv_xml_node_ridx_tg = lc_xml_node_ridx_tg. + lv_syindex = sy-index. + SHIFT lv_syindex RIGHT DELETING TRAILING space. + SHIFT lv_syindex LEFT DELETING LEADING space. + REPLACE ALL OCCURRENCES OF '#' IN lv_xml_node_ridx_id WITH lv_syindex. + REPLACE ALL OCCURRENCES OF '#' IN lv_xml_node_ridx_tg 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_sheet_tp ). + lo_element->set_attribute_ns( name = lc_xml_attr_target + value = lv_xml_node_ridx_tg ). + lo_element_root->append_child( new_child = lo_element ). + ENDDO. + + " Relationship node + lo_element = lo_document->create_simple_element( name = lc_xml_node_relationship + parent = lo_document ). + ADD 3 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_shared_tp ). + lo_element->set_attribute_ns( name = lc_xml_attr_target + value = lc_xml_node_rid_shared_tg ). + lo_element_root->append_child( new_child = lo_element ). + +********************************************************************** +* 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( ). + + endmethod. + + + + method CREATE_XL_SHAREDSTRINGS. + + +** Constant node name + DATA: lc_xml_node_sst TYPE string VALUE 'sst', + lc_xml_node_si TYPE string VALUE 'si', + lc_xml_node_t TYPE string VALUE 't', + " Node attributes + lc_xml_attr_count TYPE string VALUE 'count', + lc_xml_attr_uniquecount TYPE string VALUE 'uniqueCount', + " 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 TYPE REF TO if_ixml_element, + lo_sub_element 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_worksheet TYPE REF TO zcl_excel_worksheet. + + DATA: lt_cell_data TYPE zexcel_t_cell_data_unsorted, + ls_shared_string TYPE zexcel_s_shared_string, + lv_value TYPE string, + lv_count_str TYPE string, + lv_uniquecount_str TYPE string, + lv_sytabix TYPE sytabix, + lv_count TYPE i, + lv_uniquecount TYPE i. + + FIELD-SYMBOLS: <fs_sheet_content> TYPE zexcel_s_cell_data, + <fs_sheet_string> TYPE zexcel_s_shared_string. + +********************************************************************** +* STEP 1: Collect strings from each worksheet + lo_iterator = excel->get_worksheets_iterator( ). + + WHILE lo_iterator->if_object_collection_iterator~has_next( ) EQ abap_true. + lo_worksheet ?= lo_iterator->if_object_collection_iterator~get_next( ). + APPEND LINES OF lo_worksheet->sheet_content TO lt_cell_data. + ENDWHILE. + + DELETE lt_cell_data WHERE cell_formula IS NOT INITIAL. " delete formula content + + DESCRIBE TABLE lt_cell_data LINES lv_count. + MOVE lv_count TO lv_count_str. + + SHIFT lv_count_str RIGHT DELETING TRAILING space. + SHIFT lv_count_str LEFT DELETING LEADING space. + + SORT lt_cell_data BY cell_value. + DELETE ADJACENT DUPLICATES FROM lt_cell_data COMPARING cell_value. + + DESCRIBE TABLE lt_cell_data LINES lv_uniquecount. + MOVE lv_uniquecount TO lv_uniquecount_str. + + SHIFT lv_uniquecount_str RIGHT DELETING TRAILING space. + SHIFT lv_uniquecount_str LEFT DELETING LEADING space. + + LOOP AT lt_cell_data ASSIGNING <fs_sheet_content>. + lv_sytabix = sy-tabix - 1. + MOVE lv_sytabix TO ls_shared_string-string_no. + MOVE <fs_sheet_content>-cell_value TO ls_shared_string-string_value. + APPEND ls_shared_string TO shared_strings. + ENDLOOP. + + +********************************************************************** +* STEP 1: Create [Content_Types].xml into the root of the ZIP + 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 ). + +********************************************************************** +* STEP 3: Create main node + lo_element_root = lo_document->create_simple_element( name = lc_xml_node_sst + parent = lo_document ). + lo_element_root->set_attribute_ns( name = 'xmlns' + value = lc_xml_node_ns ). + lo_element_root->set_attribute_ns( name = lc_xml_attr_count + value = lv_count_str ). + lo_element_root->set_attribute_ns( name = lc_xml_attr_uniquecount + value = lv_uniquecount_str ). + +********************************************************************** +* STEP 4: Create subnode + LOOP AT shared_strings ASSIGNING <fs_sheet_string>. + lo_element = lo_document->create_simple_element( name = lc_xml_node_si + parent = lo_document ). + lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_t + parent = lo_document ). + lo_sub_element->set_value( value = <fs_sheet_string>-string_value ). + lo_element->append_child( new_child = lo_sub_element ). + lo_element_root->append_child( new_child = lo_element ). + ENDLOOP. + +********************************************************************** +* 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( ). + + endmethod. + + + + + + + method CREATE_XL_SHEET. +*--------------------------------------------------------------------* +* issue #237 - Error writing column-style +* - Stefan Schmöcker, 2012-11-01 +*--------------------------------------------------------------------* + + TYPES: BEGIN OF cfvo, + value TYPE zexcel_conditional_value, + type TYPE zexcel_conditional_type, + END OF cfvo. + +*--------------------------------------------------------------------* +* issue #220 - If cell in tables-area don't use default from row or column or sheet - Declarations 1 - start +*--------------------------------------------------------------------* + TYPES: BEGIN OF lty_table_area, + left TYPE i, + right TYPE i, + top TYPE i, + bottom TYPE i, + END OF lty_table_area. +*--------------------------------------------------------------------* +* issue #220 - If cell in tables-area don't use default from row or column or sheet - Declarations 1 - end +*--------------------------------------------------------------------* + + +** Constant node name + DATA: lc_xml_node_worksheet TYPE string VALUE 'worksheet', + lc_xml_node_sheetpr TYPE string VALUE 'sheetPr', + lc_xml_node_tabcolor TYPE string VALUE 'tabColor', + lc_xml_node_outlinepr TYPE string VALUE 'outlinePr', + lc_xml_node_dimension TYPE string VALUE 'dimension', + lc_xml_node_sheetviews TYPE string VALUE 'sheetViews', + lc_xml_node_sheetview TYPE string VALUE 'sheetView', + lc_xml_node_selection TYPE string VALUE 'selection', + lc_xml_node_pane TYPE string VALUE 'pane', + lc_xml_node_sheetformatpr TYPE string VALUE 'sheetFormatPr', + lc_xml_node_cols TYPE string VALUE 'cols', + lc_xml_node_col TYPE string VALUE 'col', + lc_xml_node_sheetdata TYPE string VALUE 'sheetData', + lc_xml_node_row TYPE string VALUE 'row', + lc_xml_node_c TYPE string VALUE 'c', + lc_xml_node_v TYPE string VALUE 'v', + lc_xml_node_f TYPE string VALUE 'f', + lc_xml_node_sheetprotection TYPE string VALUE 'sheetProtection', + lc_xml_node_pagemargins TYPE string VALUE 'pageMargins', + lc_xml_node_pagesetup TYPE string VALUE 'pageSetup', + lc_xml_node_pagesetuppr TYPE string VALUE 'pageSetUpPr', + lc_xml_node_condformatting TYPE string VALUE 'conditionalFormatting', + lc_xml_node_cfrule TYPE string VALUE 'cfRule', + lc_xml_node_color TYPE string VALUE 'color', " Databar by Albert Lladanosa + lc_xml_node_databar TYPE string VALUE 'dataBar', " Databar by Albert Lladanosa + lc_xml_node_iconset TYPE string VALUE 'iconSet', + lc_xml_node_cfvo TYPE string VALUE 'cfvo', + lc_xml_node_formula TYPE string VALUE 'formula', + lc_xml_node_datavalidations TYPE string VALUE 'dataValidations', + lc_xml_node_datavalidation TYPE string VALUE 'dataValidation', + lc_xml_node_formula1 TYPE string VALUE 'formula1', + lc_xml_node_formula2 TYPE string VALUE 'formula2', + lc_xml_node_mergecell TYPE string VALUE 'mergeCell', + lc_xml_node_mergecells TYPE string VALUE 'mergeCells', + lc_xml_node_drawing TYPE string VALUE 'drawing', + lc_xml_node_headerfooter TYPE string VALUE 'headerFooter', + lc_xml_node_oddheader TYPE string VALUE 'oddHeader', + lc_xml_node_oddfooter TYPE string VALUE 'oddFooter', + lc_xml_node_evenheader TYPE string VALUE 'evenHeader', + lc_xml_node_evenfooter TYPE string VALUE 'evenFooter', + lc_xml_node_autofilter TYPE string VALUE 'autoFilter', + lc_xml_node_filtercolumn TYPE string VALUE 'filterColumn', + lc_xml_node_filters TYPE string VALUE 'filters', + lc_xml_node_filter TYPE string VALUE 'filter', + " Node attributes + lc_xml_attr_ref TYPE string VALUE 'ref', + lc_xml_attr_summarybelow TYPE string VALUE 'summaryBelow', + lc_xml_attr_summaryright TYPE string VALUE 'summaryRight', + lc_xml_attr_tabselected TYPE string VALUE 'tabSelected', + lc_xml_attr_showzeros TYPE string VALUE 'showZeros', + lc_xml_attr_zoomscale TYPE string VALUE 'zoomScale', + lc_xml_attr_zoomscalenormal TYPE string VALUE 'zoomScaleNormal', + lc_xml_attr_zoomscalepageview TYPE string VALUE 'zoomScalePageLayoutView', + lc_xml_attr_zoomscalesheetview TYPE string VALUE 'zoomScaleSheetLayoutView', + lc_xml_attr_workbookviewid TYPE string VALUE 'workbookViewId', + lc_xml_attr_showgridlines TYPE string VALUE 'showGridLines', + lc_xml_attr_gridlines TYPE string VALUE 'gridLines', + lc_xml_attr_showrowcolheaders TYPE string VALUE 'showRowColHeaders', + lc_xml_attr_activecell TYPE string VALUE 'activeCell', + lc_xml_attr_sqref TYPE string VALUE 'sqref', + lc_xml_attr_min TYPE string VALUE 'min', + lc_xml_attr_max TYPE string VALUE 'max', + lc_xml_attr_hidden TYPE string VALUE 'hidden', + lc_xml_attr_width TYPE string VALUE 'width', + lc_xml_attr_defaultwidth TYPE string VALUE '9.10', + lc_xml_attr_style TYPE string VALUE 'style', + lc_xml_attr_true TYPE string VALUE 'true', + lc_xml_attr_bestfit TYPE string VALUE 'bestFit', + lc_xml_attr_customheight TYPE string VALUE 'customHeight', + lc_xml_attr_customwidth TYPE string VALUE 'customWidth', + lc_xml_attr_collapsed TYPE string VALUE 'collapsed', + lc_xml_attr_defaultrowheight TYPE string VALUE 'defaultRowHeight', + lc_xml_attr_defaultcolwidth TYPE string VALUE 'defaultColWidth', + lc_xml_attr_outlinelevelrow TYPE string VALUE 'x14ac:outlineLevelRow', + lc_xml_attr_outlinelevelcol TYPE string VALUE 'x14ac:outlineLevelCol', + lc_xml_attr_outlinelevel TYPE string VALUE 'outlineLevel', + lc_xml_attr_r TYPE string VALUE 'r', + lc_xml_attr_s TYPE string VALUE 's', + lc_xml_attr_spans TYPE string VALUE 'spans', + lc_xml_attr_t TYPE string VALUE 't', + lc_xml_attr_password TYPE string VALUE 'password', + lc_xml_attr_sheet TYPE string VALUE 'sheet', + lc_xml_attr_objects TYPE string VALUE 'objects', + lc_xml_attr_scenarios TYPE string VALUE 'scenarios', + lc_xml_attr_autofilter TYPE string VALUE 'autoFilter', + lc_xml_attr_deletecolumns TYPE string VALUE 'deleteColumns', + lc_xml_attr_deleterows TYPE string VALUE 'deleteRows', + lc_xml_attr_formatcells TYPE string VALUE 'formatCells', + lc_xml_attr_formatcolumns TYPE string VALUE 'formatColumns', + lc_xml_attr_formatrows TYPE string VALUE 'formatRows', + lc_xml_attr_insertcolumns TYPE string VALUE 'insertColumns', + lc_xml_attr_inserthyperlinks TYPE string VALUE 'insertHyperlinks', + lc_xml_attr_insertrows TYPE string VALUE 'insertRows', + lc_xml_attr_pivottables TYPE string VALUE 'pivotTables', + lc_xml_attr_selectlockedcells TYPE string VALUE 'selectLockedCells', + lc_xml_attr_selectunlockedcell TYPE string VALUE 'selectUnlockedCells', + lc_xml_attr_sort TYPE string VALUE 'sort', + lc_xml_attr_left TYPE string VALUE 'left', + lc_xml_attr_right TYPE string VALUE 'right', + lc_xml_attr_top TYPE string VALUE 'top', + lc_xml_attr_bottom TYPE string VALUE 'bottom', + lc_xml_attr_header TYPE string VALUE 'header', + lc_xml_attr_footer TYPE string VALUE 'footer', + lc_xml_attr_type TYPE string VALUE 'type', + lc_xml_attr_iconset TYPE string VALUE 'iconSet', + lc_xml_attr_showvalue TYPE string VALUE 'showValue', + lc_xml_attr_val TYPE string VALUE 'val', + lc_xml_attr_dxfid TYPE string VALUE 'dxfId', + lc_xml_attr_priority TYPE string VALUE 'priority', + lc_xml_attr_operator TYPE string VALUE 'operator', + lc_xml_attr_allowblank TYPE string VALUE 'allowBlank', + lc_xml_attr_showinputmessage TYPE string VALUE 'showInputMessage', + lc_xml_attr_showerrormessage TYPE string VALUE 'showErrorMessage', + lc_xml_attr_errortitle TYPE string VALUE 'errorTitle', + lc_xml_attr_error TYPE string VALUE 'error', + lc_xml_attr_prompttitle TYPE string VALUE 'promptTitle', + lc_xml_attr_prompt TYPE string VALUE 'prompt', + lc_xml_attr_count TYPE string VALUE 'count', + lc_xml_attr_blackandwhite TYPE string VALUE 'blackAndWhite', + lc_xml_attr_cellcomments TYPE string VALUE 'cellComments', + lc_xml_attr_copies TYPE string VALUE 'copies', + lc_xml_attr_draft TYPE string VALUE 'draft', + lc_xml_attr_errors TYPE string VALUE 'errors', + lc_xml_attr_firstpagenumber TYPE string VALUE 'firstPageNumber', + lc_xml_attr_fittopage TYPE string VALUE 'fitToPage', + lc_xml_attr_fittoheight TYPE string VALUE 'fitToHeight', + lc_xml_attr_fittowidth TYPE string VALUE 'fitToWidth', + lc_xml_attr_horizontaldpi TYPE string VALUE 'horizontalDpi', + lc_xml_attr_orientation TYPE string VALUE 'orientation', + lc_xml_attr_pageorder TYPE string VALUE 'pageOrder', + lc_xml_attr_paperheight TYPE string VALUE 'paperHeight', + lc_xml_attr_papersize TYPE string VALUE 'paperSize', + lc_xml_attr_paperwidth TYPE string VALUE 'paperWidth', + lc_xml_attr_scale TYPE string VALUE 'scale', + lc_xml_attr_usefirstpagenumber TYPE string VALUE 'useFirstPageNumber', + lc_xml_attr_useprinterdefaults TYPE string VALUE 'usePrinterDefaults', + lc_xml_attr_verticaldpi TYPE string VALUE 'verticalDpi', + lc_xml_attr_differentoddeven TYPE string VALUE 'differentOddEven', + lc_xml_attr_colid TYPE string VALUE 'colId', + lc_xml_attr_filtermode TYPE string VALUE 'filterMode', + lc_xml_attr_tabcolor_rgb TYPE string VALUE 'rgb', + lc_xml_attr_tabcolor_theme TYPE string VALUE 'theme', + " Node namespace + lc_xml_node_ns TYPE string VALUE 'http://schemas.openxmlformats.org/spreadsheetml/2006/main', + lc_xml_node_r_ns TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships', + lc_xml_node_comp_ns TYPE string VALUE 'http://schemas.openxmlformats.org/markup-compatibility/2006', + lc_xml_node_comp_pref TYPE string VALUE 'x14ac', + lc_xml_node_ig_ns TYPE string VALUE 'http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac'. + + 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 TYPE REF TO if_ixml_element, + lo_element_2 TYPE REF TO if_ixml_element, + lo_element_3 TYPE REF TO if_ixml_element, + lo_element_4 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_style_conditional TYPE REF TO zcl_excel_style_conditional, + lo_data_validation TYPE REF TO zcl_excel_data_validation, + lo_table TYPE REF TO zcl_excel_table, + row_dimension TYPE REF TO zcl_excel_worksheet_rowdimensi, + default_col_dimension TYPE REF TO zcl_excel_worksheet_columndime, + default_row_dimension TYPE REF TO zcl_excel_worksheet_rowdimensi. + + DATA: lv_value TYPE string, + lt_range_merge TYPE string_table, + lv_merge TYPE string, + lv_column_p TYPE zexcel_cell_column_alpha, + lv_column TYPE zexcel_cell_column, + lv_cell_value TYPE zexcel_cell_value, + lv_style_guid TYPE zexcel_cell_style, + lv_flag TYPE c, + ls_databar TYPE zexcel_conditional_databar, " Databar by Albert Lladanosa + ls_iconset TYPE zexcel_conditional_iconset, + ls_cellis TYPE zexcel_conditional_cellis, + ls_expression TYPE zexcel_conditional_expression, + lt_cfvo TYPE TABLE OF cfvo, + ls_cfvo TYPE cfvo, + lv_cell_row_s TYPE string, + ls_last_row TYPE zexcel_s_cell_data, + ls_style_mapping TYPE zexcel_s_styles_mapping, + lv_freeze_cell_row TYPE zexcel_cell_row, + lv_freeze_cell_column TYPE zexcel_cell_column, + lv_freeze_cell_column_alpha TYPE zexcel_cell_column_alpha, + column_dimensions TYPE zexcel_t_worksheet_columndime, + row_dimensions TYPE zexcel_t_worksheet_rowdimensio, + ls_style_cond_mapping TYPE zexcel_s_styles_cond_mapping, + lv_relation_id TYPE i VALUE 0, + outline_level_row TYPE i VALUE 0, + outline_level_col TYPE i VALUE 0, + col_count TYPE int4, + merge_count TYPE int4, + write_current_row TYPE boolean, + lt_values TYPE zexcel_t_autofilter_values, + ls_values TYPE zexcel_s_autofilter_values, + lv_guid TYPE uuid, + lo_autofilters TYPE REF TO zcl_excel_autofilters, + lo_autofilter TYPE REF TO zcl_excel_autofilter, + l_autofilter_hidden TYPE flag, + ls_area TYPE zexcel_s_autofilter_area, + lv_ref TYPE string, + lv_style_index TYPE i. " issue #237 + + + FIELD-SYMBOLS: <ls_sheet_content> TYPE zexcel_s_cell_data, + <fs_range_merge> LIKE LINE OF lt_range_merge, + <column_dimension> TYPE zexcel_s_worksheet_columndime, + <row_dimension> TYPE zexcel_s_worksheet_rowdimensio. + +*--------------------------------------------------------------------* +* issue #220 - If cell in tables-area don't use default from row or column or sheet - Declarations 2 - start +*--------------------------------------------------------------------* + DATA: lt_table_areas TYPE SORTED TABLE OF lty_table_area WITH NON-UNIQUE KEY left right top bottom, + ls_table_area LIKE LINE OF lt_table_areas. +*--------------------------------------------------------------------* +* issue #220 - If cell in tables-area don't use default from row or column or sheet - Declarations 2 - end +*--------------------------------------------------------------------* + + + +********************************************************************** +* STEP 1: Create [Content_Types].xml into the root of the ZIP + 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 ). + +*********************************************************************** +* STEP 3: Create main node relationships + lo_element_root = lo_document->create_simple_element( name = lc_xml_node_worksheet + parent = lo_document ). + lo_element_root->set_attribute_ns( name = 'xmlns' + value = lc_xml_node_ns ). + lo_element_root->set_attribute_ns( name = 'xmlns:r' + value = lc_xml_node_r_ns ). + lo_element_root->set_attribute_ns( name = 'xmlns:mc' + value = lc_xml_node_comp_ns ). + lo_element_root->set_attribute_ns( name = 'mc:Ignorable' + value = lc_xml_node_comp_pref ). + lo_element_root->set_attribute_ns( name = 'xmlns:x14ac' + value = lc_xml_node_ig_ns ). + + +********************************************************************** +* STEP 4: Create subnodes + " sheetPr + lo_element = lo_document->create_simple_element( name = lc_xml_node_sheetpr + parent = lo_document ). + " TODO tabColor + IF io_worksheet->tabcolor IS NOT INITIAL. + lo_element_2 = lo_document->create_simple_element( name = lc_xml_node_tabcolor + parent = lo_element ). +* Theme not supported yet - start with RGB + lv_value = io_worksheet->tabcolor-rgb. + lo_element_2->set_attribute_ns( name = lc_xml_attr_tabcolor_rgb + value = lv_value ). + ENDIF. + + " outlinePr + lo_element_2 = lo_document->create_simple_element( name = lc_xml_node_outlinepr + parent = lo_document ). + + lv_value = io_worksheet->zif_excel_sheet_properties~summarybelow. + CONDENSE lv_value. + lo_element_2->set_attribute_ns( name = lc_xml_attr_summarybelow + value = lv_value ). + + lv_value = io_worksheet->zif_excel_sheet_properties~summaryright. + CONDENSE lv_value. + lo_element_2->set_attribute_ns( name = lc_xml_attr_summaryright + value = lv_value ). + + lo_element->append_child( new_child = lo_element_2 ). + + IF io_worksheet->sheet_setup->fit_to_page IS NOT INITIAL. + lo_element_2 = lo_document->create_simple_element( name = lc_xml_node_pagesetuppr + parent = lo_document ). + lo_element_2->set_attribute_ns( name = lc_xml_attr_fittopage + value = `1` ). + lo_element->append_child( new_child = lo_element_2 ). " pageSetupPr node + ENDIF. + + lo_element_root->append_child( new_child = lo_element ). + + " dimension node + lo_element = lo_document->create_simple_element( name = lc_xml_node_dimension + parent = lo_document ). + lv_value = io_worksheet->get_dimension_range( ). + lo_element->set_attribute_ns( name = lc_xml_attr_ref + value = lv_value ). + lo_element_root->append_child( new_child = lo_element ). + + " sheetViews node + lo_element = lo_document->create_simple_element( name = lc_xml_node_sheetviews + parent = lo_document ). + " sheetView node + lo_element_2 = lo_document->create_simple_element( name = lc_xml_node_sheetview + parent = lo_document ). + IF io_worksheet->zif_excel_sheet_properties~show_zeros EQ abap_false. + lo_element_2->set_attribute_ns( name = lc_xml_attr_showzeros + value = '0' ). + ENDIF. + IF iv_active = abap_true + OR io_worksheet->zif_excel_sheet_properties~selected EQ abap_true. + lo_element_2->set_attribute_ns( name = lc_xml_attr_tabselected + value = '1' ). + ELSE. + lo_element_2->set_attribute_ns( name = lc_xml_attr_tabselected + value = '0' ). + ENDIF. + " Zoom scale + IF io_worksheet->zif_excel_sheet_properties~zoomscale GT 400. + io_worksheet->zif_excel_sheet_properties~zoomscale = 400. + ELSEIF io_worksheet->zif_excel_sheet_properties~zoomscale LT 10. + io_worksheet->zif_excel_sheet_properties~zoomscale = 10. + ENDIF. + lv_value = io_worksheet->zif_excel_sheet_properties~zoomscale. + CONDENSE lv_value. + lo_element_2->set_attribute_ns( name = lc_xml_attr_zoomscale + value = lv_value ). + IF io_worksheet->zif_excel_sheet_properties~zoomscale_normal NE 0. + IF io_worksheet->zif_excel_sheet_properties~zoomscale_normal GT 400. + io_worksheet->zif_excel_sheet_properties~zoomscale_normal = 400. + ELSEIF io_worksheet->zif_excel_sheet_properties~zoomscale_normal LT 10. + io_worksheet->zif_excel_sheet_properties~zoomscale_normal = 10. + ENDIF. + lv_value = io_worksheet->zif_excel_sheet_properties~zoomscale_normal. + CONDENSE lv_value. + lo_element_2->set_attribute_ns( name = lc_xml_attr_zoomscalenormal + value = lv_value ). + ENDIF. + IF io_worksheet->zif_excel_sheet_properties~zoomscale_pagelayoutview NE 0. + IF io_worksheet->zif_excel_sheet_properties~zoomscale_pagelayoutview GT 400. + io_worksheet->zif_excel_sheet_properties~zoomscale_pagelayoutview = 400. + ELSEIF io_worksheet->zif_excel_sheet_properties~zoomscale_pagelayoutview LT 10. + io_worksheet->zif_excel_sheet_properties~zoomscale_pagelayoutview = 10. + ENDIF. + lv_value = io_worksheet->zif_excel_sheet_properties~zoomscale_pagelayoutview. + CONDENSE lv_value. + lo_element_2->set_attribute_ns( name = lc_xml_attr_zoomscalepageview + value = lv_value ). + ENDIF. + IF io_worksheet->zif_excel_sheet_properties~zoomscale_sheetlayoutview NE 0. + IF io_worksheet->zif_excel_sheet_properties~zoomscale_sheetlayoutview GT 400. + io_worksheet->zif_excel_sheet_properties~zoomscale_sheetlayoutview = 400. + ELSEIF io_worksheet->zif_excel_sheet_properties~zoomscale_sheetlayoutview LT 10. + io_worksheet->zif_excel_sheet_properties~zoomscale_sheetlayoutview = 10. + ENDIF. + lv_value = io_worksheet->zif_excel_sheet_properties~zoomscale_sheetlayoutview. + CONDENSE lv_value. + lo_element_2->set_attribute_ns( name = lc_xml_attr_zoomscalesheetview + value = lv_value ). + ENDIF. + lo_element_2->set_attribute_ns( name = lc_xml_attr_workbookviewid + value = '0' ). + " showGridLines attribute + IF io_worksheet->show_gridlines = abap_true. + lo_element_2->set_attribute_ns( name = lc_xml_attr_showgridlines + value = '1' ). + ELSE. + lo_element_2->set_attribute_ns( name = lc_xml_attr_showgridlines + value = '0' ). + ENDIF. + + " showRowColHeaders attribute + IF io_worksheet->show_rowcolheaders = abap_true. + lo_element_2->set_attribute_ns( name = lc_xml_attr_showrowcolheaders + value = '1' ). + ELSE. + lo_element_2->set_attribute_ns( name = lc_xml_attr_showrowcolheaders + value = '0' ). + ENDIF. + + + " freeze panes + io_worksheet->get_freeze_cell( IMPORTING ep_row = lv_freeze_cell_row + ep_column = lv_freeze_cell_column ). + + IF lv_freeze_cell_row IS NOT INITIAL AND lv_freeze_cell_column IS NOT INITIAL. + lo_element_3 = lo_document->create_simple_element( name = lc_xml_node_pane + parent = lo_element_2 ). + + IF lv_freeze_cell_row > 1. + lv_value = lv_freeze_cell_row - 1. + CONDENSE lv_value. + lo_element_3->set_attribute_ns( name = 'ySplit' + value = lv_value ). + ENDIF. + + IF lv_freeze_cell_column > 1. + lv_value = lv_freeze_cell_column - 1. + CONDENSE lv_value. + lo_element_3->set_attribute_ns( name = 'xSplit' + value = lv_value ). + ENDIF. + + lv_freeze_cell_column_alpha = zcl_excel_common=>convert_column2alpha( ip_column = lv_freeze_cell_column ). + lv_value = zcl_excel_common=>number_to_excel_string( ip_value = lv_freeze_cell_row ). + CONCATENATE lv_freeze_cell_column_alpha lv_value INTO lv_value. + lo_element_3->set_attribute_ns( name = 'topLeftCell' + value = lv_value ). + + lo_element_3->set_attribute_ns( name = 'activePane' + value = 'bottomRight' ). + + lo_element_3->set_attribute_ns( name = 'state' + value = 'frozen' ). + + lo_element_2->append_child( new_child = lo_element_3 ). + ENDIF. + " selection node + lo_element_3 = lo_document->create_simple_element( name = lc_xml_node_selection + parent = lo_document ). + lv_value = io_worksheet->get_active_cell( ). + lo_element_3->set_attribute_ns( name = lc_xml_attr_activecell + value = lv_value ). + + lo_element_3->set_attribute_ns( name = lc_xml_attr_sqref + value = lv_value ). + + lo_element_2->append_child( new_child = lo_element_3 ). " sheetView node + + lo_element->append_child( new_child = lo_element_2 ). " sheetView node + + lo_element_root->append_child( new_child = lo_element ). " sheetViews node + + + column_dimensions[] = io_worksheet->get_column_dimensions( ). + " Calculate col + IF NOT column_dimensions IS INITIAL. + io_worksheet->calculate_column_widths( ). + column_dimensions[] = io_worksheet->get_column_dimensions( ). + ENDIF. + row_dimensions[] = io_worksheet->get_row_dimensions( ). + " sheetFormatPr node + lo_element = lo_document->create_simple_element( name = lc_xml_node_sheetformatpr + parent = lo_document ). + " defaultRowHeight + default_row_dimension = io_worksheet->get_default_row_dimension( ). + IF default_row_dimension IS BOUND. + IF default_row_dimension->get_row_height( ) >= 0. + lo_element->set_attribute_ns( name = lc_xml_attr_customheight + value = lc_xml_attr_true ). + lv_value = default_row_dimension->get_row_height( ). + ELSE. + lv_value = '12.75'. + ENDIF. + ELSE. + lv_value = '12.75'. + ENDIF. + SHIFT lv_value RIGHT DELETING TRAILING space. + SHIFT lv_value LEFT DELETING LEADING space. + lo_element->set_attribute_ns( name = lc_xml_attr_defaultrowheight + value = lv_value ). + " defaultColWidth + default_col_dimension = io_worksheet->get_default_column_dimension( ). + IF default_col_dimension IS BOUND. + IF default_col_dimension->get_width( ) >= 0. + lv_value = default_col_dimension->get_width( ). + SHIFT lv_value RIGHT DELETING TRAILING space. + SHIFT lv_value LEFT DELETING LEADING space. + lo_element->set_attribute_ns( name = lc_xml_attr_defaultcolwidth + value = lv_value ). + ENDIF. + ENDIF. + " outlineLevelRow + LOOP AT row_dimensions ASSIGNING <row_dimension>. + IF <row_dimension>-row_dimension->get_outline_level( ) > outline_level_row. + outline_level_row = <row_dimension>-row_dimension->get_outline_level( ). + ENDIF. + ENDLOOP. + lv_value = outline_level_row. + SHIFT lv_value RIGHT DELETING TRAILING space. + SHIFT lv_value LEFT DELETING LEADING space. + lo_element->set_attribute_ns( name = lc_xml_attr_outlinelevelrow + value = lv_value ). + " outlineLevelCol + LOOP AT column_dimensions ASSIGNING <column_dimension>. + IF <column_dimension>-column_dimension->get_outline_level( ) > outline_level_col. + outline_level_col = <column_dimension>-column_dimension->get_outline_level( ). + ENDIF. + ENDLOOP. + lv_value = outline_level_col. + SHIFT lv_value RIGHT DELETING TRAILING space. + SHIFT lv_value LEFT DELETING LEADING space. + lo_element->set_attribute_ns( name = lc_xml_attr_outlinelevelcol + value = lv_value ). +* lv_value = 0. +* SHIFT lv_value RIGHT DELETING TRAILING space. +* SHIFT lv_value LEFT DELETING LEADING space. +* lo_element->set_attribute_ns( name = lc_xml_attr_dydescent +* value = lv_value ). + + lo_element_root->append_child( new_child = lo_element ). " sheetFormatPr node + + IF io_worksheet->zif_excel_sheet_properties~get_style( ) IS NOT INITIAL OR NOT column_dimensions IS INITIAL. + " cols node + lo_element = lo_document->create_simple_element( name = lc_xml_node_cols + parent = lo_document ). + " This code have to be enhanced in order to manage also column style properties + " Now it is an out/out + IF NOT column_dimensions IS INITIAL. + LOOP AT column_dimensions ASSIGNING <column_dimension>. + " col node + lo_element_2 = lo_document->create_simple_element( name = lc_xml_node_col + parent = lo_document ). + lv_value = <column_dimension>-column_dimension->get_column_index( ). + SHIFT lv_value RIGHT DELETING TRAILING space. + SHIFT lv_value LEFT DELETING LEADING space. + lo_element_2->set_attribute_ns( name = lc_xml_attr_min + value = lv_value ). + lo_element_2->set_attribute_ns( name = lc_xml_attr_max + value = lv_value ). + " Width + IF <column_dimension>-column_dimension->get_width( ) < 0. + lo_element_2->set_attribute_ns( name = lc_xml_attr_width + value = lc_xml_attr_defaultwidth ). + ELSE. + lv_value = <column_dimension>-column_dimension->get_width( ). + lo_element_2->set_attribute_ns( name = lc_xml_attr_width + value = lv_value ). + ENDIF. + " Column visibility + IF <column_dimension>-column_dimension->get_visible( ) = abap_false. + lo_element_2->set_attribute_ns( name = lc_xml_attr_hidden + value = lc_xml_attr_true ). + ENDIF. + " Auto size? + IF <column_dimension>-column_dimension->get_auto_size( ) = abap_true. + lo_element_2->set_attribute_ns( name = lc_xml_attr_bestfit + value = lc_xml_attr_true ). + ENDIF. + " Custom width? + IF default_col_dimension IS BOUND. + IF <column_dimension>-column_dimension->get_width( ) + <> default_col_dimension->get_width( ). + lo_element_2->set_attribute_ns( name = lc_xml_attr_customwidth + value = lc_xml_attr_true ). + + ENDIF. + ELSE. + lo_element_2->set_attribute_ns( name = lc_xml_attr_customwidth + value = lc_xml_attr_true ). + ENDIF. + " Collapsed + IF <column_dimension>-column_dimension->get_collapsed( ) = abap_true. + lo_element_2->set_attribute_ns( name = lc_xml_attr_collapsed + value = lc_xml_attr_true ). + ENDIF. + " outlineLevel + IF <column_dimension>-column_dimension->get_outline_level( ) > 0. + lv_value = <column_dimension>-column_dimension->get_outline_level( ). + + SHIFT lv_value RIGHT DELETING TRAILING space. + SHIFT lv_value LEFT DELETING LEADING space. + lo_element_2->set_attribute_ns( name = lc_xml_attr_outlinelevel + value = lv_value ). + ENDIF. + " Style +* lv_value = <column_dimension>-column_dimension->get_xf_index( ). "del issue #157 - set column style + lv_style_guid = <column_dimension>-column_dimension->get_column_style_guid( ). "ins issue #157 - set column style +* lv_value = me->excel->get_style_index_in_styles( lv_style_guid ). "del issue #237 + lv_style_index = me->excel->get_style_index_in_styles( lv_style_guid ). "ins issue #237 + IF lv_style_index > 0. "ins issue #237 + lv_value = lv_style_index - 1. "ins issue #237 + SHIFT lv_value RIGHT DELETING TRAILING space. + SHIFT lv_value LEFT DELETING LEADING space. + lo_element_2->set_attribute_ns( name = lc_xml_attr_style + value = lv_value ). + ENDIF. "ins issue #237 + + lo_element->append_child( new_child = lo_element_2 ). " col node + ENDLOOP. +* ELSE. "del issue #157 - set sheet style ( add missing columns +* IF io_worksheet->zif_excel_sheet_properties~get_style( ) IS NOT INITIAL. "del issue #157 - set sheet style ( add missing columns +* Begin of insertion issue #157 - set sheet style ( add missing columns + ENDIF. +* Always pass through this coding + IF io_worksheet->zif_excel_sheet_properties~get_style( ) IS NOT INITIAL. + DATA: lts_sorted_columns TYPE SORTED TABLE OF zexcel_cell_column WITH UNIQUE KEY table_line. + TYPES: BEGIN OF ty_missing_columns, + first_column TYPE zexcel_cell_column, + last_column TYPE zexcel_cell_column, + END OF ty_missing_columns. + DATA: t_missing_columns TYPE STANDARD TABLE OF ty_missing_columns WITH NON-UNIQUE DEFAULT KEY, + missing_column LIKE LINE OF t_missing_columns. + +* First collect columns that were already handled before. The rest has to be inserted now + LOOP AT column_dimensions ASSIGNING <column_dimension>. + lv_column = zcl_excel_common=>convert_column2int( <column_dimension>-column ). + INSERT lv_column INTO TABLE lts_sorted_columns. + ENDLOOP. + +* Now find all columns that were missing so far + missing_column-first_column = 1. + LOOP AT lts_sorted_columns INTO lv_column. + IF lv_column > missing_column-first_column. + missing_column-last_column = lv_column - 1. + APPEND missing_column TO t_missing_columns. + ENDIF. + missing_column-first_column = lv_column + 1. + ENDLOOP. + missing_column-last_column = zcl_excel_common=>c_excel_sheet_max_col. + APPEND missing_column TO t_missing_columns. +* Now apply stylesetting ( and other defaults - I copy it from above. Whoever programmed that seems to know what to do :o) + LOOP AT t_missing_columns INTO missing_column. +* End of insertion issue #157 - set column style + lo_element_2 = lo_document->create_simple_element( name = lc_xml_node_col + parent = lo_document ). +* lv_value = zcl_excel_common=>c_excel_sheet_min_col."del issue #157 - set sheet style ( add missing columns + lv_value = missing_column-first_column. "ins issue #157 - set sheet style ( add missing columns + CONDENSE lv_value. + lo_element_2->set_attribute_ns( name = lc_xml_attr_min + value = lv_value ). +* lv_value = zcl_excel_common=>c_excel_sheet_max_col."del issue #157 - set sheet style ( add missing columns + lv_value = missing_column-last_column. "ins issue #157 - set sheet style ( add missing columns + CONDENSE lv_value. + lo_element_2->set_attribute_ns( name = lc_xml_attr_max + value = lv_value ). + lo_element_2->set_attribute_ns( name = lc_xml_attr_width + value = lc_xml_attr_defaultwidth ). + lv_style_guid = io_worksheet->zif_excel_sheet_properties~get_style( ). + READ TABLE styles_mapping INTO ls_style_mapping WITH KEY guid = lv_style_guid. + lv_value = ls_style_mapping-style. + CONDENSE lv_value. + lo_element_2->set_attribute_ns( name = lc_xml_attr_style + value = lv_value ). + lo_element->append_child( new_child = lo_element_2 ). " col node + ENDLOOP. "ins issue #157 - set sheet style ( add missing columns + + ENDIF. + lo_element_root->append_child( new_child = lo_element ). " cols node + ENDIF. + " sheetData node + lo_element = lo_document->create_simple_element( name = lc_xml_node_sheetdata + parent = lo_document ). + " Get column count + col_count = io_worksheet->get_highest_column( ). + " Get autofilter + lv_guid = io_worksheet->get_guid( ) . + lo_autofilters = excel->get_autofilters_reference( ). + lo_autofilter = lo_autofilters->get( i_sheet_guid = lv_guid ) . + IF lo_autofilter IS BOUND. + lt_values = lo_autofilter->get_values( ) . + ls_area = lo_autofilter->get_filter_area( ) . + l_autofilter_hidden = abap_true. " First defautl is not showing + ENDIF. +*--------------------------------------------------------------------* +* issue #220 - If cell in tables-area don't use default from row or column or sheet - Coding 1 - start +*--------------------------------------------------------------------* +* Build table to hold all table-areas attached to this sheet + lo_iterator = io_worksheet->get_tables_iterator( ). + WHILE lo_iterator->if_object_collection_iterator~has_next( ) EQ abap_true. + lo_table ?= lo_iterator->if_object_collection_iterator~get_next( ). + ls_table_area-left = zcl_excel_common=>convert_column2int( lo_table->settings-top_left_column ). + ls_table_area-right = lo_table->get_right_column_integer( ). + ls_table_area-top = lo_table->settings-top_left_row. + ls_table_area-bottom = lo_table->get_bottom_row_integer( ). + INSERT ls_table_area INTO TABLE lt_table_areas. + ENDWHILE. +*--------------------------------------------------------------------* +* issue #220 - If cell in tables-area don't use default from row or column or sheet - Coding 1 - end +*--------------------------------------------------------------------* + + LOOP AT io_worksheet->sheet_content ASSIGNING <ls_sheet_content>. + READ TABLE lt_values INTO ls_values WITH KEY column = ls_last_row-cell_column. + IF sy-subrc = 0 AND ls_values-value = ls_last_row-cell_value. + CLEAR l_autofilter_hidden. + ENDIF. + CLEAR ls_style_mapping. + IF ls_last_row-cell_row NE <ls_sheet_content>-cell_row. + IF lo_autofilter IS BOUND. + IF ls_area-row_start >= ls_last_row-cell_row OR " One less for header + ls_area-row_end < ls_last_row-cell_row . + CLEAR l_autofilter_hidden. + ENDIF. + ELSE. + CLEAR l_autofilter_hidden. + ENDIF. + IF ls_last_row-cell_row IS NOT INITIAL. + " Row visibility of previos row. + IF row_dimension->get_visible( ) = abap_false OR + l_autofilter_hidden = abap_true. + lo_element_2->set_attribute_ns( name = 'hidden' value = 'true'). + ENDIF. + lo_element->append_child( new_child = lo_element_2 ). " row node + ENDIF. + " Add new row + lo_element_2 = lo_document->create_simple_element( name = lc_xml_node_row + parent = lo_document ). + " r + lv_value = <ls_sheet_content>-cell_row. + SHIFT lv_value RIGHT DELETING TRAILING space. + SHIFT lv_value LEFT DELETING LEADING space. + + lo_element_2->set_attribute_ns( name = lc_xml_attr_r + value = lv_value ). + " Spans + lv_value = col_count. + CONCATENATE '1:' lv_value INTO lv_value. + SHIFT lv_value RIGHT DELETING TRAILING space. + SHIFT lv_value LEFT DELETING LEADING space. + lo_element_2->set_attribute_ns( name = lc_xml_attr_spans + value = lv_value ). + row_dimension = io_worksheet->get_row_dimension( <ls_sheet_content>-cell_row ). + " Do we need the row dimension attributes? + IF row_dimension->get_row_height( ) >= 0 OR + row_dimension->get_collapsed( ) = abap_true OR + row_dimension->get_outline_level( ) > 0 OR + row_dimension->get_xf_index( ) <> 0 OR + l_autofilter_hidden = abap_true. + " Row dimensions + IF row_dimension->get_row_height( ) >= 0. + lo_element_2->set_attribute_ns( name = 'customHeight' value = '1'). + lv_value = row_dimension->get_row_height( ). + lo_element_2->set_attribute_ns( name = 'ht' value = lv_value ). + ENDIF. + " Collapsed + IF row_dimension->get_collapsed( ) = abap_true. + lo_element_2->set_attribute_ns( name = 'collapsed' value = 'true'). + ENDIF. + " Outline level + IF row_dimension->get_outline_level( ) > 0. + lv_value = row_dimension->get_outline_level( ). + SHIFT lv_value RIGHT DELETING TRAILING space. + SHIFT lv_value LEFT DELETING LEADING space. + lo_element_2->set_attribute_ns( name = 'outlineLevel' value = lv_value ). + ENDIF. + " Style + IF row_dimension->get_xf_index( ) <> 0. + lv_value = row_dimension->get_xf_index( ). + lo_element_2->set_attribute_ns( name = 's' value = lv_value ). + lo_element_2->set_attribute_ns( name = 'customFormat' value = '1'). + ENDIF. + ENDIF. + l_autofilter_hidden = abap_true. " First default is not showing + ENDIF. + + lo_element_3 = lo_document->create_simple_element( name = lc_xml_node_c + parent = lo_document ). + + lo_element_3->set_attribute_ns( name = lc_xml_attr_r + value = <ls_sheet_content>-cell_coords ). + +* begin of change issue #157 - allow column cellstyle +* if no cellstyle is set, look into column, then into sheet + IF <ls_sheet_content>-cell_style IS NOT INITIAL. + lv_style_guid = <ls_sheet_content>-cell_style. + ELSE. +*--------------------------------------------------------------------* +* issue #220 - If cell in tables-area don't use default from row or column or sheet - Coding 2 - start +*--------------------------------------------------------------------* +* Check if cell in any of the table areas + LOOP AT lt_table_areas TRANSPORTING NO FIELDS WHERE top <= <ls_sheet_content>-cell_row + AND bottom >= <ls_sheet_content>-cell_row + AND left <= <ls_sheet_content>-cell_column + AND right >= <ls_sheet_content>-cell_column. + EXIT. + ENDLOOP. + IF sy-subrc = 0. + CLEAR lv_style_guid. " No style --> EXCEL will use built-in-styles as declared in the tables-section + ELSE. +*--------------------------------------------------------------------* +* issue #220 - If cell in tables-area don't use default from row or column or sheet - Coding 2 - end +*--------------------------------------------------------------------* + lv_column_p = zcl_excel_common=>convert_column2alpha( <ls_sheet_content>-cell_column ). + READ TABLE column_dimensions WITH KEY column = lv_column_p ASSIGNING <column_dimension>. + IF sy-subrc = 0. + lv_style_guid = <column_dimension>-column_dimension->get_column_style_guid( ). + IF lv_style_guid IS INITIAL. + lv_style_guid = io_worksheet->zif_excel_sheet_properties~get_style( ). + ENDIF. + ELSE. + lv_style_guid = io_worksheet->zif_excel_sheet_properties~get_style( ). + ENDIF. +*--------------------------------------------------------------------* +* issue #220 - If cell in tables-area don't use default from row or column or sheet - Coding 3 - start +*--------------------------------------------------------------------* + ENDIF. +*--------------------------------------------------------------------* +* issue #220 - If cell in tables-area don't use default from row or column or sheet - Coding 3 - end +*--------------------------------------------------------------------* + ENDIF. +* IF <ls_sheet_content>-cell_style IS NOT INITIAL. +* READ TABLE styles_mapping INTO ls_style_mapping WITH KEY guid = <ls_sheet_content>-cell_style. + IF lv_style_guid IS NOT INITIAL. + READ TABLE styles_mapping INTO ls_style_mapping WITH KEY guid = lv_style_guid. +* end of change issue #157 - allow column cellstyles + lv_value = ls_style_mapping-style. + SHIFT lv_value RIGHT DELETING TRAILING space. + SHIFT lv_value LEFT DELETING LEADING space. + lo_element_3->set_attribute_ns( name = lc_xml_attr_s + value = lv_value ). + ENDIF. + + " For cells with formula ignore the value - Excel will calculate it + IF <ls_sheet_content>-cell_formula IS NOT INITIAL. + " fomula node + lo_element_4 = lo_document->create_simple_element( name = lc_xml_node_f + parent = lo_document ). + lv_value = <ls_sheet_content>-cell_formula. + CONDENSE lv_value. + lo_element_4->set_value( value = lv_value ). + lo_element_3->append_child( new_child = lo_element_4 ). " fomula node + ELSEIF <ls_sheet_content>-cell_value IS NOT INITIAL. "cell can have just style or formula + IF <ls_sheet_content>-data_type IS NOT INITIAL. + lo_element_3->set_attribute_ns( name = lc_xml_attr_t + value = <ls_sheet_content>-data_type ). + ENDIF. + + " value node + lo_element_4 = lo_document->create_simple_element( name = lc_xml_node_v + parent = lo_document ). + + IF <ls_sheet_content>-data_type EQ 's'. + lv_value = me->get_shared_string_index( <ls_sheet_content>-cell_value ). + CONDENSE lv_value. + lo_element_4->set_value( value = lv_value ). + ELSE. + lv_value = <ls_sheet_content>-cell_value. + CONDENSE lv_value. + lo_element_4->set_value( value = lv_value ). + ENDIF. + + lo_element_3->append_child( new_child = lo_element_4 ). " value node + ENDIF. + + lo_element_2->append_child( new_child = lo_element_3 ). " column node + ls_last_row = <ls_sheet_content>. + ENDLOOP. + IF sy-subrc = 0. + READ TABLE lt_values INTO ls_values WITH KEY column = ls_last_row-cell_column. + IF sy-subrc = 0 AND ls_values-value = ls_last_row-cell_value. + CLEAR l_autofilter_hidden. + ENDIF. + IF lo_autofilter IS BOUND. + IF ls_area-row_start >= ls_last_row-cell_row OR " One less for header + ls_area-row_end < ls_last_row-cell_row . + CLEAR l_autofilter_hidden. + ENDIF. + ELSE. + CLEAR l_autofilter_hidden. + ENDIF. + " Row visibility of previos row. + IF row_dimension->get_visible( ) = abap_false OR + l_autofilter_hidden = abap_true. + lo_element_2->set_attribute_ns( name = 'hidden' value = 'true'). + ENDIF. + lo_element->append_child( new_child = lo_element_2 ). " row node + ENDIF. + + lo_element_root->append_child( new_child = lo_element ). " sheetData node + + IF lo_autofilter IS BOUND. +* Create node autofilter + lo_element = lo_document->create_simple_element( name = lc_xml_node_autofilter + parent = lo_document ). + lv_ref = lo_autofilter->get_filter_range( ) . + CONDENSE lv_ref NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_ref + value = lv_ref ). + lt_values = lo_autofilter->get_values( ) . + IF lt_values IS NOT INITIAL. +* If we filter we need to set the filter mode to 1. + lo_element_2 = lo_document->find_from_name( name = lc_xml_node_sheetpr ). + lo_element_2->set_attribute_ns( name = lc_xml_attr_filtermode + value = '1' ). +* Create node filtercolumn + CLEAR lv_column. + LOOP AT lt_values INTO ls_values. + IF ls_values-column <> lv_column. + IF lv_column IS NOT INITIAL. + lo_element_2->append_child( new_child = lo_element_3 ). + lo_element->append_child( new_child = lo_element_2 ). + ENDIF. + lo_element_2 = lo_document->create_simple_element( name = lc_xml_node_filtercolumn + parent = lo_element ). + lv_column = ls_values-column - lo_autofilter->filter_area-col_start. + lv_value = lv_column. + CONDENSE lv_value NO-GAPS. + lo_element_2->set_attribute_ns( name = lc_xml_attr_colid + value = lv_value ). + lo_element_3 = lo_document->create_simple_element( name = lc_xml_node_filters + parent = lo_element_2 ). + lv_column = ls_values-column. + ENDIF. + lo_element_4 = lo_document->create_simple_element( name = lc_xml_node_filter + parent = lo_element_3 ). + lo_element_4->set_attribute_ns( name = lc_xml_attr_val + value = ls_values-value ). + lo_element_3->append_child( new_child = lo_element_4 ). " value node + ENDLOOP. + lo_element_2->append_child( new_child = lo_element_3 ). + lo_element->append_child( new_child = lo_element_2 ). + ENDIF. + lo_element_root->append_child( new_child = lo_element ). + ENDIF. + + IF io_worksheet->zif_excel_sheet_protection~protected EQ abap_true. + " sheetProtection node + lo_element = lo_document->create_simple_element( name = lc_xml_node_sheetprotection + parent = lo_document ). + MOVE io_worksheet->zif_excel_sheet_protection~password TO lv_value. + IF lv_value IS NOT INITIAL. + lo_element->set_attribute_ns( name = lc_xml_attr_password + value = lv_value ). + ENDIF. + lv_value = io_worksheet->zif_excel_sheet_protection~auto_filter. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_autofilter + value = lv_value ). + lv_value = io_worksheet->zif_excel_sheet_protection~delete_columns. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_deletecolumns + value = lv_value ). + lv_value = io_worksheet->zif_excel_sheet_protection~delete_rows. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_deleterows + value = lv_value ). + lv_value = io_worksheet->zif_excel_sheet_protection~format_cells. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_formatcells + value = lv_value ). + lv_value = io_worksheet->zif_excel_sheet_protection~format_columns. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_formatcolumns + value = lv_value ). + lv_value = io_worksheet->zif_excel_sheet_protection~format_rows. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_formatrows + value = lv_value ). + lv_value = io_worksheet->zif_excel_sheet_protection~insert_columns. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_insertcolumns + value = lv_value ). + lv_value = io_worksheet->zif_excel_sheet_protection~insert_hyperlinks. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_inserthyperlinks + value = lv_value ). + lv_value = io_worksheet->zif_excel_sheet_protection~insert_rows. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_insertrows + value = lv_value ). + lv_value = io_worksheet->zif_excel_sheet_protection~objects. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_objects + value = lv_value ). + lv_value = io_worksheet->zif_excel_sheet_protection~pivot_tables. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_pivottables + value = lv_value ). + lv_value = io_worksheet->zif_excel_sheet_protection~scenarios. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_scenarios + value = lv_value ). + lv_value = io_worksheet->zif_excel_sheet_protection~select_locked_cells. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_selectlockedcells + value = lv_value ). + lv_value = io_worksheet->zif_excel_sheet_protection~select_unlocked_cells. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_selectunlockedcell + value = lv_value ). + lv_value = io_worksheet->zif_excel_sheet_protection~sheet. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_sheet + value = lv_value ). + lv_value = io_worksheet->zif_excel_sheet_protection~sort. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_sort + value = lv_value ). + + lo_element_root->append_child( new_child = lo_element ). + ENDIF. + + " Merged cells + lt_range_merge = io_worksheet->get_merge( ). + IF lt_range_merge IS NOT INITIAL. + lo_element = lo_document->create_simple_element( name = lc_xml_node_mergecells + parent = lo_document ). + DESCRIBE TABLE lt_range_merge LINES merge_count. + lv_value = merge_count. + CONDENSE lv_value. + lo_element->set_attribute_ns( name = lc_xml_attr_count + value = lv_value ). + LOOP AT lt_range_merge ASSIGNING <fs_range_merge>. + lo_element_2 = lo_document->create_simple_element( name = lc_xml_node_mergecell + parent = lo_document ). + + lo_element_2->set_attribute_ns( name = lc_xml_attr_ref + value = <fs_range_merge> ). + lo_element->append_child( new_child = lo_element_2 ). + lo_element_root->append_child( new_child = lo_element ). + io_worksheet->delete_merge( ). + ENDLOOP. + ENDIF. + + " Conditional formatting node + lo_iterator = io_worksheet->get_cond_styles_iterator( ). + WHILE lo_iterator->if_object_collection_iterator~has_next( ) EQ abap_true. + lo_style_conditional ?= lo_iterator->if_object_collection_iterator~get_next( ). + IF lo_style_conditional->rule IS INITIAL. + CONTINUE. + ENDIF. + lo_element = lo_document->create_simple_element( name = lc_xml_node_condformatting + parent = lo_document ). + lv_value = lo_style_conditional->get_dimension_range( ) . + lo_element->set_attribute_ns( name = lc_xml_attr_sqref + value = lv_value ). + + " cfRule node + lo_element_2 = lo_document->create_simple_element( name = lc_xml_node_cfrule + parent = lo_document ). + lv_value = lo_style_conditional->rule. + lo_element_2->set_attribute_ns( name = lc_xml_attr_type + value = lv_value ). + lv_value = lo_style_conditional->priority. + SHIFT lv_value RIGHT DELETING TRAILING space. + SHIFT lv_value LEFT DELETING LEADING space. + lo_element_2->set_attribute_ns( name = lc_xml_attr_priority + value = lv_value ). + + CASE lo_style_conditional->rule. + " Start >> Databar by Albert Lladanosa + WHEN zcl_excel_style_conditional=>c_rule_databar. + + ls_databar = lo_style_conditional->mode_databar. + + CLEAR lt_cfvo. + lo_element_3 = lo_document->create_simple_element( name = lc_xml_node_databar + parent = lo_document ). + + MOVE ls_databar-cfvo1_value TO ls_cfvo-value. + MOVE ls_databar-cfvo1_type TO ls_cfvo-type. + APPEND ls_cfvo TO lt_cfvo. + + MOVE ls_databar-cfvo2_value TO ls_cfvo-value. + MOVE ls_databar-cfvo2_type TO ls_cfvo-type. + APPEND ls_cfvo TO lt_cfvo. + + LOOP AT lt_cfvo INTO ls_cfvo. + " cfvo node + lo_element_4 = lo_document->create_simple_element( name = lc_xml_node_cfvo + parent = lo_document ). + lv_value = ls_cfvo-type. + lo_element_4->set_attribute_ns( name = lc_xml_attr_type + value = lv_value ). + lv_value = ls_cfvo-value. + lo_element_4->set_attribute_ns( name = lc_xml_attr_val + value = lv_value ). + lo_element_3->append_child( new_child = lo_element_4 ). " cfvo node + ENDLOOP. + + lo_element_4 = lo_document->create_simple_element( name = lc_xml_node_color + parent = lo_document ). + lv_value = ls_databar-colorrgb. + lo_element_4->set_attribute_ns( name = lc_xml_attr_tabcolor_rgb + value = lv_value ). + + lo_element_3->append_child( new_child = lo_element_4 ). " color node + + lo_element_2->append_child( new_child = lo_element_3 ). " databar node + " End << Databar by Albert Lladanosa + WHEN zcl_excel_style_conditional=>c_rule_iconset. + + ls_iconset = lo_style_conditional->mode_iconset. + + CLEAR lt_cfvo. + " iconset node + lo_element_3 = lo_document->create_simple_element( name = lc_xml_node_iconset + parent = lo_document ). + IF ls_iconset-iconset NE zcl_excel_style_conditional=>c_iconset_3trafficlights. + lv_value = ls_iconset-iconset. + lo_element_3->set_attribute_ns( name = lc_xml_attr_iconset + value = lv_value ). + ENDIF. + + " Set the showValue attribute + lv_value = ls_iconset-showvalue. + lo_element_3->set_attribute_ns( name = lc_xml_attr_showvalue + value = lv_value ). + + CASE ls_iconset-iconset. + WHEN zcl_excel_style_conditional=>c_iconset_3trafficlights2 OR + zcl_excel_style_conditional=>c_iconset_3arrows OR + zcl_excel_style_conditional=>c_iconset_3arrowsgray OR + zcl_excel_style_conditional=>c_iconset_3flags OR + zcl_excel_style_conditional=>c_iconset_3signs OR + zcl_excel_style_conditional=>c_iconset_3symbols OR + zcl_excel_style_conditional=>c_iconset_3symbols2 OR + zcl_excel_style_conditional=>c_iconset_3trafficlights OR + zcl_excel_style_conditional=>c_iconset_3trafficlights2. + MOVE ls_iconset-cfvo1_value TO ls_cfvo-value. + MOVE ls_iconset-cfvo1_type TO ls_cfvo-type. + APPEND ls_cfvo TO lt_cfvo. + MOVE ls_iconset-cfvo2_value TO ls_cfvo-value. + MOVE ls_iconset-cfvo2_type TO ls_cfvo-type. + APPEND ls_cfvo TO lt_cfvo. + MOVE ls_iconset-cfvo3_value TO ls_cfvo-value. + MOVE ls_iconset-cfvo3_type TO ls_cfvo-type. + APPEND ls_cfvo TO lt_cfvo. + WHEN zcl_excel_style_conditional=>c_iconset_4arrows OR + zcl_excel_style_conditional=>c_iconset_4arrowsgray OR + zcl_excel_style_conditional=>c_iconset_4rating OR + zcl_excel_style_conditional=>c_iconset_4redtoblack OR + zcl_excel_style_conditional=>c_iconset_4trafficlights. + MOVE ls_iconset-cfvo1_value TO ls_cfvo-value. + MOVE ls_iconset-cfvo1_type TO ls_cfvo-type. + APPEND ls_cfvo TO lt_cfvo. + MOVE ls_iconset-cfvo2_value TO ls_cfvo-value. + MOVE ls_iconset-cfvo2_type TO ls_cfvo-type. + APPEND ls_cfvo TO lt_cfvo. + MOVE ls_iconset-cfvo3_value TO ls_cfvo-value. + MOVE ls_iconset-cfvo3_type TO ls_cfvo-type. + APPEND ls_cfvo TO lt_cfvo. + MOVE ls_iconset-cfvo4_value TO ls_cfvo-value. + MOVE ls_iconset-cfvo4_type TO ls_cfvo-type. + APPEND ls_cfvo TO lt_cfvo. + WHEN zcl_excel_style_conditional=>c_iconset_5arrows OR + zcl_excel_style_conditional=>c_iconset_5arrowsgray OR + zcl_excel_style_conditional=>c_iconset_5quarters OR + zcl_excel_style_conditional=>c_iconset_5rating. + MOVE ls_iconset-cfvo1_value TO ls_cfvo-value. + MOVE ls_iconset-cfvo1_type TO ls_cfvo-type. + APPEND ls_cfvo TO lt_cfvo. + MOVE ls_iconset-cfvo2_value TO ls_cfvo-value. + MOVE ls_iconset-cfvo2_type TO ls_cfvo-type. + APPEND ls_cfvo TO lt_cfvo. + MOVE ls_iconset-cfvo3_value TO ls_cfvo-value. + MOVE ls_iconset-cfvo3_type TO ls_cfvo-type. + APPEND ls_cfvo TO lt_cfvo. + MOVE ls_iconset-cfvo4_value TO ls_cfvo-value. + MOVE ls_iconset-cfvo4_type TO ls_cfvo-type. + APPEND ls_cfvo TO lt_cfvo. + MOVE ls_iconset-cfvo5_value TO ls_cfvo-value. + MOVE ls_iconset-cfvo5_type TO ls_cfvo-type. + APPEND ls_cfvo TO lt_cfvo. + WHEN OTHERS. + CLEAR lt_cfvo. + ENDCASE. + + LOOP AT lt_cfvo INTO ls_cfvo. + " cfvo node + lo_element_4 = lo_document->create_simple_element( name = lc_xml_node_cfvo + parent = lo_document ). + lv_value = ls_cfvo-type. + lo_element_4->set_attribute_ns( name = lc_xml_attr_type + value = lv_value ). + lv_value = ls_cfvo-value. + lo_element_4->set_attribute_ns( name = lc_xml_attr_val + value = lv_value ). + lo_element_3->append_child( new_child = lo_element_4 ). " cfvo node + ENDLOOP. + + + lo_element_2->append_child( new_child = lo_element_3 ). " iconset node + WHEN zcl_excel_style_conditional=>c_rule_cellis. + ls_cellis = lo_style_conditional->mode_cellis. + READ TABLE me->styles_cond_mapping INTO ls_style_cond_mapping WITH KEY guid = ls_cellis-cell_style. + lv_value = ls_style_cond_mapping-dxf. + CONDENSE lv_value. + lo_element_2->set_attribute_ns( name = lc_xml_attr_dxfid + value = lv_value ). + lv_value = ls_cellis-operator. + lo_element_2->set_attribute_ns( name = lc_xml_attr_operator + value = lv_value ). + " formula node + lo_element_3 = lo_document->create_simple_element( name = lc_xml_node_formula + parent = lo_document ). + lv_value = ls_cellis-formula. + lo_element_3->set_value( value = lv_value ). + lo_element_2->append_child( new_child = lo_element_3 ). " formula node + WHEN zcl_excel_style_conditional=>c_rule_expression. + ls_expression = lo_style_conditional->mode_expression. + READ TABLE me->styles_cond_mapping INTO ls_style_cond_mapping WITH KEY guid = ls_expression-cell_style. + lv_value = ls_style_cond_mapping-dxf. + CONDENSE lv_value. + lo_element_2->set_attribute_ns( name = lc_xml_attr_dxfid + value = lv_value ). + " formula node + lo_element_3 = lo_document->create_simple_element( name = lc_xml_node_formula + parent = lo_document ). + lv_value = ls_expression-formula. + lo_element_3->set_value( value = lv_value ). + lo_element_2->append_child( new_child = lo_element_3 ). " formula node + ENDCASE. + + lo_element->append_child( new_child = lo_element_2 ). " cfRule node + + lo_element_root->append_child( new_child = lo_element ). " Conditional formatting node + ENDWHILE. + + IF io_worksheet->get_data_validations_size( ) GT 0. + " dataValidations node + lo_element = lo_document->create_simple_element( name = lc_xml_node_datavalidations + parent = lo_document ). + " Conditional formatting node + lo_iterator = io_worksheet->get_data_validations_iterator( ). + WHILE lo_iterator->if_object_collection_iterator~has_next( ) EQ abap_true. + lo_data_validation ?= lo_iterator->if_object_collection_iterator~get_next( ). + " dataValidation node + lo_element_2 = lo_document->create_simple_element( name = lc_xml_node_datavalidation + parent = lo_document ). + lv_value = lo_data_validation->type. + lo_element_2->set_attribute_ns( name = lc_xml_attr_type + value = lv_value ). + IF NOT lo_data_validation->operator IS INITIAL. + lv_value = lo_data_validation->operator. + lo_element_2->set_attribute_ns( name = lc_xml_attr_operator + value = lv_value ). + ENDIF. + IF lo_data_validation->allowblank EQ abap_true. + lv_value = '1'. + ELSE. + lv_value = '0'. + ENDIF. + lo_element_2->set_attribute_ns( name = lc_xml_attr_allowblank + value = lv_value ). + IF lo_data_validation->showinputmessage EQ abap_true. + lv_value = '1'. + ELSE. + lv_value = '0'. + ENDIF. + lo_element_2->set_attribute_ns( name = lc_xml_attr_showinputmessage + value = lv_value ). + IF lo_data_validation->showerrormessage EQ abap_true. + lv_value = '1'. + ELSE. + lv_value = '0'. + ENDIF. + lo_element_2->set_attribute_ns( name = lc_xml_attr_showerrormessage + value = lv_value ). + IF NOT lo_data_validation->errortitle IS INITIAL. + lv_value = lo_data_validation->errortitle. + lo_element_2->set_attribute_ns( name = lc_xml_attr_errortitle + value = lv_value ). + ENDIF. + IF NOT lo_data_validation->error IS INITIAL. + lv_value = lo_data_validation->error. + lo_element_2->set_attribute_ns( name = lc_xml_attr_error + value = lv_value ). + ENDIF. + IF NOT lo_data_validation->prompttitle IS INITIAL. + lv_value = lo_data_validation->prompttitle. + lo_element_2->set_attribute_ns( name = lc_xml_attr_prompttitle + value = lv_value ). + ENDIF. + IF NOT lo_data_validation->prompt IS INITIAL. + lv_value = lo_data_validation->prompt. + lo_element_2->set_attribute_ns( name = lc_xml_attr_prompt + value = lv_value ). + ENDIF. + lv_cell_row_s = lo_data_validation->cell_row. + CONDENSE lv_cell_row_s. + CONCATENATE lo_data_validation->cell_column lv_cell_row_s INTO lv_value. + IF lo_data_validation->cell_row_to IS NOT INITIAL. + lv_cell_row_s = lo_data_validation->cell_row_to. + CONDENSE lv_cell_row_s. + CONCATENATE lv_value ':' lo_data_validation->cell_column_to lv_cell_row_s INTO lv_value. + ENDIF. + lo_element_2->set_attribute_ns( name = lc_xml_attr_sqref + value = lv_value ). + " formula1 node + lo_element_3 = lo_document->create_simple_element( name = lc_xml_node_formula1 + parent = lo_document ). + lv_value = lo_data_validation->formula1. + lo_element_3->set_value( value = lv_value ). + + lo_element_2->append_child( new_child = lo_element_3 ). " formula1 node + " formula2 node + IF NOT lo_data_validation->formula2 IS INITIAL. + lo_element_3 = lo_document->create_simple_element( name = lc_xml_node_formula2 + parent = lo_document ). + lv_value = lo_data_validation->formula2. + lo_element_3->set_value( value = lv_value ). + + lo_element_2->append_child( new_child = lo_element_3 ). " formula2 node + ENDIF. + + lo_element->append_child( new_child = lo_element_2 ). " dataValidation node + ENDWHILE. + lo_element_root->append_child( new_child = lo_element ). " dataValidations node + ENDIF. + + " Hyperlinks + DATA: lv_hyperlinks_count TYPE i, + lo_link TYPE REF TO zcl_excel_hyperlink. + + lv_hyperlinks_count = io_worksheet->get_hyperlinks_size( ). + IF lv_hyperlinks_count > 0. + lo_element = lo_document->create_simple_element( name = 'hyperlinks' + parent = lo_document ). + + lo_iterator = io_worksheet->get_hyperlinks_iterator( ). + WHILE lo_iterator->if_object_collection_iterator~has_next( ) EQ abap_true. + lo_link ?= lo_iterator->if_object_collection_iterator~get_next( ). + + lo_element_2 = lo_document->create_simple_element( name = 'hyperlink' + parent = lo_element ). + + lv_value = lo_link->get_ref( ). + lo_element_2->set_attribute_ns( name = 'ref' + value = lv_value ). + + IF lo_link->is_internal( ) = abap_true. + lv_value = lo_link->get_url( ). + lo_element_2->set_attribute_ns( name = 'location' + value = lv_value ). + ELSE. + ADD 1 TO lv_relation_id. + + lv_value = lv_relation_id. + CONDENSE lv_value. + CONCATENATE 'rId' lv_value INTO lv_value. + + lo_element_2->set_attribute_ns( name = 'r:id' + value = lv_value ). + + ENDIF. + + lo_element->append_child( new_child = lo_element_2 ). + ENDWHILE. + + lo_element_root->append_child( new_child = lo_element ). + ENDIF. + + + " PrintOptions + IF io_worksheet->print_gridlines = abap_true OR + io_worksheet->sheet_setup->vertical_centered = abap_true OR + io_worksheet->sheet_setup->horizontal_centered = abap_true. + lo_element = lo_document->create_simple_element( name = 'printOptions' + parent = lo_document ). + + IF io_worksheet->print_gridlines = abap_true. + lo_element->set_attribute_ns( name = lc_xml_attr_gridlines + value = 'true' ). + ENDIF. + + IF io_worksheet->sheet_setup->horizontal_centered = abap_true. + lo_element->set_attribute_ns( name = 'horizontalCentered' + value = 'true' ). + ENDIF. + + IF io_worksheet->sheet_setup->vertical_centered = abap_true. + lo_element->set_attribute_ns( name = 'verticalCentered' + value = 'true' ). + ENDIF. + + lo_element_root->append_child( new_child = lo_element ). + ENDIF. + " pageMargins node + lo_element = lo_document->create_simple_element( name = lc_xml_node_pagemargins + parent = lo_document ). + + lv_value = io_worksheet->sheet_setup->margin_left. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_left + value = lv_value ). + lv_value = io_worksheet->sheet_setup->margin_right. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_right + value = lv_value ). + lv_value = io_worksheet->sheet_setup->margin_top. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_top + value = lv_value ). + lv_value = io_worksheet->sheet_setup->margin_bottom. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_bottom + value = lv_value ). + lv_value = io_worksheet->sheet_setup->margin_header. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_header + value = lv_value ). + lv_value = io_worksheet->sheet_setup->margin_footer. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_footer + value = lv_value ). + lo_element_root->append_child( new_child = lo_element ). " pageMargins node + +* pageSetup node + lo_element = lo_document->create_simple_element( name = lc_xml_node_pagesetup + parent = lo_document ). + + IF io_worksheet->sheet_setup->black_and_white IS NOT INITIAL. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_blackandwhite + value = `1` ). + ENDIF. + + IF io_worksheet->sheet_setup->cell_comments IS NOT INITIAL. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_cellcomments + value = io_worksheet->sheet_setup->cell_comments ). + ENDIF. + + IF io_worksheet->sheet_setup->copies IS NOT INITIAL. + lv_value = io_worksheet->sheet_setup->copies. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_copies + value = lv_value ). + ENDIF. + + IF io_worksheet->sheet_setup->draft IS NOT INITIAL. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_draft + value = `1` ). + ENDIF. + + IF io_worksheet->sheet_setup->errors IS NOT INITIAL. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_errors + value = io_worksheet->sheet_setup->errors ). + ENDIF. + + IF io_worksheet->sheet_setup->first_page_number IS NOT INITIAL. + lv_value = io_worksheet->sheet_setup->first_page_number. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_firstpagenumber + value = lv_value ). + ENDIF. + + IF io_worksheet->sheet_setup->fit_to_page IS NOT INITIAL. + lv_value = io_worksheet->sheet_setup->fit_to_height. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_fittoheight + value = lv_value ). + lv_value = io_worksheet->sheet_setup->fit_to_width. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_fittowidth + value = lv_value ). + ENDIF. + + IF io_worksheet->sheet_setup->horizontal_dpi IS NOT INITIAL. + lv_value = io_worksheet->sheet_setup->horizontal_dpi. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_horizontaldpi + value = lv_value ). + ENDIF. + + IF io_worksheet->sheet_setup->orientation IS NOT INITIAL. + lv_value = io_worksheet->sheet_setup->orientation. + lo_element->set_attribute_ns( name = lc_xml_attr_orientation + value = lv_value ). + ENDIF. + + IF io_worksheet->sheet_setup->page_order IS NOT INITIAL. + lo_element->set_attribute_ns( name = lc_xml_attr_pageorder + value = io_worksheet->sheet_setup->page_order ). + ENDIF. + + IF io_worksheet->sheet_setup->paper_height IS NOT INITIAL. + lv_value = io_worksheet->sheet_setup->paper_height. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_paperheight + value = lv_value ). + ENDIF. + + IF io_worksheet->sheet_setup->paper_size IS NOT INITIAL. + lv_value = io_worksheet->sheet_setup->paper_size. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_papersize + value = lv_value ). + ENDIF. + + IF io_worksheet->sheet_setup->paper_width IS NOT INITIAL. + lv_value = io_worksheet->sheet_setup->paper_width. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_paperwidth + value = lv_value ). + ENDIF. + + IF io_worksheet->sheet_setup->scale IS NOT INITIAL. + lv_value = io_worksheet->sheet_setup->scale. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_scale + value = lv_value ). + ENDIF. + + IF io_worksheet->sheet_setup->use_first_page_num IS NOT INITIAL. + lo_element->set_attribute_ns( name = lc_xml_attr_usefirstpagenumber + value = `1` ). + ENDIF. + + IF io_worksheet->sheet_setup->use_printer_defaults IS NOT INITIAL. + lo_element->set_attribute_ns( name = lc_xml_attr_useprinterdefaults + value = `1` ). + ENDIF. + + IF io_worksheet->sheet_setup->vertical_dpi IS NOT INITIAL. + lv_value = io_worksheet->sheet_setup->vertical_dpi. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_verticaldpi + value = lv_value ). + ENDIF. + + lo_element_root->append_child( new_child = lo_element ). " pageSetup node + +* { headerFooter necessary? > + IF io_worksheet->sheet_setup->odd_header IS NOT INITIAL + OR io_worksheet->sheet_setup->odd_footer IS NOT INITIAL + OR io_worksheet->sheet_setup->diff_oddeven_headerfooter = abap_true. + + lo_element = lo_document->create_simple_element( name = lc_xml_node_headerfooter + parent = lo_document ). + + " Different header/footer for odd/even pages? + IF io_worksheet->sheet_setup->diff_oddeven_headerfooter = abap_true. + lo_element->set_attribute_ns( name = lc_xml_attr_differentoddeven + value = '1' ). + ENDIF. + + " OddHeader + CLEAR: lv_value. + io_worksheet->sheet_setup->get_header_footer_string( IMPORTING ep_odd_header = lv_value ) . + IF lv_value IS NOT INITIAL. + lo_element_2 = lo_document->create_simple_element( name = lc_xml_node_oddheader + parent = lo_document ). + lo_element_2->set_value( value = lv_value ). + lo_element->append_child( new_child = lo_element_2 ). + ENDIF. + + " OddFooter + CLEAR: lv_value. + io_worksheet->sheet_setup->get_header_footer_string( IMPORTING ep_odd_footer = lv_value ) . + IF lv_value IS NOT INITIAL. + lo_element_2 = lo_document->create_simple_element( name = lc_xml_node_oddfooter + parent = lo_document ). + lo_element_2->set_value( value = lv_value ). + lo_element->append_child( new_child = lo_element_2 ). + ENDIF. + + " evenHeader + CLEAR: lv_value. + io_worksheet->sheet_setup->get_header_footer_string( IMPORTING ep_even_header = lv_value ) . + IF lv_value IS NOT INITIAL. + lo_element_2 = lo_document->create_simple_element( name = lc_xml_node_evenheader + parent = lo_document ). + lo_element_2->set_value( value = lv_value ). + lo_element->append_child( new_child = lo_element_2 ). + ENDIF. + + " evenFooter + CLEAR: lv_value. + io_worksheet->sheet_setup->get_header_footer_string( IMPORTING ep_even_footer = lv_value ) . + IF lv_value IS NOT INITIAL. + lo_element_2 = lo_document->create_simple_element( name = lc_xml_node_evenfooter + parent = lo_document ). + lo_element_2->set_value( value = lv_value ). + lo_element->append_child( new_child = lo_element_2 ). + ENDIF. + + + lo_element_root->append_child( new_child = lo_element ). " headerFooter + + ENDIF. + +* drawing + DATA: lo_drawings TYPE REF TO zcl_excel_drawings. + + lo_drawings = io_worksheet->get_drawings( ). + IF lo_drawings->is_empty( ) = abap_false. + lo_element = lo_document->create_simple_element( name = lc_xml_node_drawing + parent = lo_document ). + ADD 1 TO lv_relation_id. + + lv_value = lv_relation_id. + CONDENSE lv_value. + CONCATENATE 'rId' lv_value INTO lv_value. + lo_element->set_attribute( name = 'r:id' + value = lv_value ). + lo_element_root->append_child( new_child = lo_element ). + ENDIF. + +* tables + DATA lv_table_count TYPE i. + + lv_table_count = io_worksheet->get_tables_size( ). + IF lv_table_count > 0. + lo_element = lo_document->create_simple_element( name = 'tableParts' + parent = lo_document ). + lv_value = lv_table_count. + CONDENSE lv_value. + lo_element->set_attribute_ns( name = 'count' + value = lv_value ). + + lo_iterator = io_worksheet->get_tables_iterator( ). + WHILE lo_iterator->if_object_collection_iterator~has_next( ) EQ abap_true. + lo_table ?= lo_iterator->if_object_collection_iterator~get_next( ). + ADD 1 TO lv_relation_id. + + lv_value = lv_relation_id. + CONDENSE lv_value. + CONCATENATE 'rId' lv_value INTO lv_value. + lo_element_2 = lo_document->create_simple_element( name = 'tablePart' + parent = lo_element ). + lo_element_2->set_attribute_ns( name = 'r:id' + value = lv_value ). + lo_element->append_child( new_child = lo_element_2 ). + + ENDWHILE. + + 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( ). + + endmethod. + + + + + + method CREATE_XL_SHEET_RELS. + + +** 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', + lc_xml_attr_target_mode TYPE string VALUE 'TargetMode', + lc_xml_val_external TYPE string VALUE 'External', + " Node namespace + lc_xml_node_rels_ns TYPE string VALUE 'http://schemas.openxmlformats.org/package/2006/relationships', + lc_xml_node_rid_table_tp TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/table', + lc_xml_node_rid_printer_tp TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/printerSettings', + lc_xml_node_rid_drawing_tp TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing', + lc_xml_node_rid_link_tp TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink'. + + 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 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_table TYPE REF TO zcl_excel_table, + lo_link TYPE REF TO zcl_excel_hyperlink. + + DATA: lv_value TYPE string, + lv_relation_id TYPE i, + lv_index_str TYPE string. + +********************************************************************** +* STEP 1: Create [Content_Types].xml into the root of the ZIP + 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 ). + +********************************************************************** +* STEP 3: Create main node relationships + lo_element_root = lo_document->create_simple_element( name = lc_xml_node_relationships + parent = lo_document ). + lo_element_root->set_attribute_ns( name = 'xmlns' + value = lc_xml_node_rels_ns ). + +********************************************************************** +* STEP 4: Create subnodes + + " Add sheet Relationship nodes here + lv_relation_id = 0. + lo_iterator = io_worksheet->get_hyperlinks_iterator( ). + WHILE lo_iterator->if_object_collection_iterator~has_next( ) EQ abap_true. + lo_link ?= lo_iterator->if_object_collection_iterator~get_next( ). + ADD 1 TO lv_relation_id. + + lv_value = lv_relation_id. + CONDENSE lv_value. + CONCATENATE 'rId' lv_value INTO lv_value. + + lo_element = lo_document->create_simple_element( name = lc_xml_node_relationship + parent = lo_document ). + lo_element->set_attribute_ns( name = lc_xml_attr_id + value = lv_value ). + lo_element->set_attribute_ns( name = lc_xml_attr_type + value = lc_xml_node_rid_link_tp ). + + lv_value = lo_link->get_url( ). + lo_element->set_attribute_ns( name = lc_xml_attr_target + value = lv_value ). + lo_element->set_attribute_ns( name = lc_xml_attr_target_mode + value = lc_xml_val_external ). + lo_element_root->append_child( new_child = lo_element ). + ENDWHILE. + +* drawing + DATA: lo_drawings TYPE REF TO zcl_excel_drawings. + + lo_drawings = io_worksheet->get_drawings( ). + IF lo_drawings->is_empty( ) = abap_false. + lo_element = lo_document->create_simple_element( name = lc_xml_node_relationship + parent = lo_document ). + ADD 1 TO lv_relation_id. + + lv_value = lv_relation_id. + CONDENSE lv_value. + CONCATENATE 'rId' lv_value INTO lv_value. + lo_element->set_attribute_ns( name = lc_xml_attr_id + value = lv_value ). + lo_element->set_attribute_ns( name = lc_xml_attr_type + value = lc_xml_node_rid_drawing_tp ). + + lv_index_str = iv_drawing_index. + CONDENSE lv_index_str NO-GAPS. + MOVE me->c_xl_drawings TO lv_value. + REPLACE 'xl' WITH '..' INTO lv_value. + REPLACE '#' WITH lv_index_str INTO lv_value. + lo_element->set_attribute_ns( name = lc_xml_attr_target + value = lv_value ). + lo_element_root->append_child( new_child = lo_element ). + ENDIF. + + lo_iterator = io_worksheet->get_tables_iterator( ). + WHILE lo_iterator->if_object_collection_iterator~has_next( ) EQ abap_true. + lo_table ?= lo_iterator->if_object_collection_iterator~get_next( ). + ADD 1 TO lv_relation_id. + + lv_value = lv_relation_id. + CONDENSE lv_value. + CONCATENATE 'rId' lv_value INTO lv_value. + + lo_element = lo_document->create_simple_element( name = lc_xml_node_relationship + parent = lo_document ). + lo_element->set_attribute_ns( name = lc_xml_attr_id + value = lv_value ). + lo_element->set_attribute_ns( name = lc_xml_attr_type + value = lc_xml_node_rid_table_tp ). + + lv_value = lo_table->get_name( ). + CONCATENATE '../tables/' lv_value '.xml' INTO lv_value. + lo_element->set_attribute_ns( name = lc_xml_attr_target + value = lv_value ). + lo_element_root->append_child( new_child = lo_element ). + ENDWHILE. + +* IF io_worksheet->get_print_settings( )->is_empty( ) = abap_false. +* ADD 1 TO lv_relation_id. +* lv_value = lv_relation_id. +* CONDENSE lv_value. +* CONCATENATE 'rId' lv_value INTO lv_value. +* +* lo_element = lo_document->create_simple_element( name = lc_xml_node_relationship +* parent = lo_document ). +* lo_element->set_attribute_ns( name = lc_xml_attr_id +* value = lv_value ). +* lo_element->set_attribute_ns( name = lc_xml_attr_type +* value = lc_xml_node_rid_printer_tp ). +* +* lv_index_str = iv_printer_index. +* CONDENSE lv_index_str NO-GAPS. +* MOVE me->c_xl_printersettings TO lv_value. +* REPLACE 'xl' WITH '..' INTO lv_value. +* REPLACE '#' WITH lv_index_str INTO lv_value. +* lo_element->set_attribute_ns( name = lc_xml_attr_target +* value = lv_value ). +* +* 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( ). + + endmethod. + + + + METHOD create_xl_styles. + + +** 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'. + + 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: 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_index TYPE i, + lv_align_flag TYPE c. + +********************************************************************** +* STEP 1: Create [Content_Types].xml into the root of the ZIP + 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 ). + +*********************************************************************** +* 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 ). + +********************************************************************** +* 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 + 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( ). + + 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. + +* 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. + +* 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. + +* 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. + +* 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. + ELSE. + APPEND ls_protection TO lt_protections. + DESCRIBE TABLE lt_protections LINES ls_cellxfs-protectionid. + ENDIF. + ls_cellxfs-applyprotection = 1. + ENDIF. + 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. + + 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. + 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. +* elseif ls_numfmt-NUMFMT eq 'STD_NDEC'. +* ls_cellxfs-numfmtid = 2. + 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. + +* 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 ). + 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 + lv_index = ls_cellxfs-fontid + 1. + READ TABLE lt_fonts INTO ls_font INDEX lv_index. + 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( ). + +ENDMETHOD. + + + + + + + method CREATE_XL_STYLES_COLOR_NODE. + DATA: lo_sub_element TYPE REF TO if_ixml_element, + lv_value TYPE string. + + CONSTANTS: 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'. + +"add node only if at least one attribute is set + CHECK is_color-rgb IS NOT INITIAL OR + is_color-indexed <> zcl_excel_style_color=>c_indexed_not_set OR + is_color-theme <> zcl_excel_style_color=>c_theme_not_set OR + is_color-tint IS NOT INITIAL. + + lo_sub_element = io_document->create_simple_element( + name = iv_color_elem_name + parent = io_parent ). + + IF is_color-rgb IS NOT INITIAL. + lv_value = is_color-rgb. + lo_sub_element->set_attribute_ns( name = lc_xml_attr_rgb + value = lv_value ). + ENDIF. + + IF is_color-indexed <> zcl_excel_style_color=>c_indexed_not_set. + lv_value = zcl_excel_common=>number_to_excel_string( is_color-indexed ). + lo_sub_element->set_attribute_ns( name = lc_xml_attr_indexed + value = lv_value ). + ENDIF. + + IF is_color-theme <> zcl_excel_style_color=>c_theme_not_set. + lv_value = zcl_excel_common=>number_to_excel_string( is_color-theme ). + lo_sub_element->set_attribute_ns( name = lc_xml_attr_theme + value = lv_value ). + ENDIF. + + IF is_color-tint IS NOT INITIAL. + lv_value = zcl_excel_common=>number_to_excel_string( is_color-tint ). + lo_sub_element->set_attribute_ns( name = lc_xml_attr_tint + value = lv_value ). + ENDIF. + + io_parent->append_child( new_child = lo_sub_element ). + endmethod. + + + + + method CREATE_XL_TABLE. + + DATA: lc_xml_node_table TYPE string VALUE 'table', + lc_xml_node_relationship TYPE string VALUE 'Relationship', + " Node attributes + lc_xml_attr_id TYPE string VALUE 'id', + lc_xml_attr_name TYPE string VALUE 'name', + lc_xml_attr_display_name TYPE string VALUE 'displayName', + lc_xml_attr_ref TYPE string VALUE 'ref', + lc_xml_attr_totals TYPE string VALUE 'totalsRowShown', + " Node namespace + lc_xml_node_table_ns TYPE string VALUE 'http://schemas.openxmlformats.org/spreadsheetml/2006/main', + " Node id + lc_xml_node_ridx_id TYPE string VALUE 'rId#'. + + 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 TYPE REF TO if_ixml_element, + lo_element2 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, + + lv_table_name TYPE string, + lv_id TYPE i, + lv_match TYPE i, + lv_syindex TYPE char3, + lv_ref TYPE string, + lv_value TYPE string, + lo_iterator TYPE REF TO cl_object_collection_iterator, + lv_num_columns TYPE i, + ls_fieldcat TYPE zexcel_s_fieldcatalog. + + +********************************************************************** +* STEP 1: Create xml + 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 ). + +********************************************************************** +* STEP 3: Create main node table + lo_element_root = lo_document->create_simple_element( name = lc_xml_node_table + parent = lo_document ). + + lo_element_root->set_attribute_ns( name = 'xmlns' + value = lc_xml_node_table_ns ). + + lv_id = io_table->get_id( ). + lv_value = zcl_excel_common=>number_to_excel_string( ip_value = lv_id ). + lo_element_root->set_attribute_ns( name = lc_xml_attr_id + value = lv_value ). + + FIND ALL OCCURRENCES OF REGEX '[^_a-zA-Z0-9]' IN io_table->settings-table_name IGNORING CASE MATCH COUNT lv_match. + IF io_table->settings-table_name IS NOT INITIAL AND lv_match EQ 0. + lv_table_name = io_table->settings-table_name. + ELSE. + lv_table_name = io_table->get_name( ). + ENDIF. + lo_element_root->set_attribute_ns( name = lc_xml_attr_name + value = lv_table_name ). + + lo_element_root->set_attribute_ns( name = lc_xml_attr_display_name + value = lv_table_name ). + + lv_ref = io_table->get_reference( ). + lo_element_root->set_attribute_ns( name = lc_xml_attr_ref + value = lv_ref ). + IF io_table->has_totals( ) = abap_true. + lo_element_root->set_attribute_ns( name = 'totalsRowCount' + value = '1' ). + ELSE. + lo_element_root->set_attribute_ns( name = lc_xml_attr_totals + value = '0' ). + ENDIF. + +********************************************************************** +* STEP 4: Create subnodes + + " autoFilter + lo_element = lo_document->create_simple_element( name = 'autoFilter' + parent = lo_document ). + + lv_ref = io_table->get_reference( ip_include_totals_row = abap_false ). + lo_element->set_attribute_ns( name = 'ref' + value = lv_ref ). + + lo_element_root->append_child( new_child = lo_element ). + + "columns + lo_element = lo_document->create_simple_element( name = 'tableColumns' + parent = lo_document ). + +* lo_columns = io_table->get_columns( ). + LOOP AT io_table->fieldcat INTO ls_fieldcat WHERE dynpfld = abap_true. + ADD 1 TO lv_num_columns. + ENDLOOP. + + lv_value = lv_num_columns. + CONDENSE lv_value. + lo_element->set_attribute_ns( name = 'count' + value = lv_value ). + + lo_element_root->append_child( new_child = lo_element ). + + LOOP AT io_table->fieldcat INTO ls_fieldcat WHERE dynpfld = abap_true. + lo_element2 = lo_document->create_simple_element_ns( name = 'tableColumn' + parent = lo_element ). + + lv_value = ls_fieldcat-position. + SHIFT lv_value LEFT DELETING LEADING '0'. + lo_element2->set_attribute_ns( name = 'id' + value = lv_value ). + lv_value = ls_fieldcat-scrtext_l. + lo_element2->set_attribute_ns( name = 'name' + value = lv_value ). + + IF ls_fieldcat-totals_function IS NOT INITIAL. + lo_element2->set_attribute_ns( name = 'totalsRowFunction' + value = ls_fieldcat-totals_function ). + ENDIF. + + lo_element->append_child( new_child = lo_element2 ). + ENDLOOP. + + + lo_element = lo_document->create_simple_element( name = 'tableStyleInfo' + parent = lo_element_root ). + + lo_element->set_attribute_ns( name = 'name' + value = io_table->settings-table_style ). + + lo_element->set_attribute_ns( name = 'showFirstColumn' + value = '0' ). + + lo_element->set_attribute_ns( name = 'showLastColumn' + value = '0' ). + + IF io_table->settings-show_row_stripes = abap_true. + lv_value = '1'. + ELSE. + lv_value = '0'. + ENDIF. + + lo_element->set_attribute_ns( name = 'showRowStripes' + value = lv_value ). + + IF io_table->settings-show_column_stripes = abap_true. + lv_value = '1'. + ELSE. + lv_value = '0'. + ENDIF. + + lo_element->set_attribute_ns( name = 'showColumnStripes' + value = lv_value ). + + lo_element_root->append_child( new_child = lo_element ). +********************************************************************** +* 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( ). + + endmethod. + + + + method CREATE_XL_THEME. + + +* @TODO * + + DATA: lv_xl_theme TYPE string, + lv_xl_theme_01 TYPE string, + lv_xl_theme_02 TYPE string, + lv_xl_theme_03 TYPE string, + lv_xl_theme_04 TYPE string, + lv_xl_theme_05 TYPE string, + lv_xl_theme_06 TYPE string, + lv_xl_theme_07 TYPE string, + lv_xl_theme_08 TYPE string, + lv_xl_theme_09 TYPE string, + lv_xl_theme_10 TYPE string, + lv_xl_theme_11 TYPE string, + lv_xl_theme_12 TYPE string, + lv_xl_theme_13 TYPE string, + lv_xl_theme_14 TYPE string, + lv_xl_theme_15 TYPE string, + lv_xl_theme_16 TYPE string, + lv_xl_theme_17 TYPE string, + lv_xl_theme_18 TYPE string, + lv_xl_theme_19 TYPE string, + lv_xl_theme_20 TYPE string, + lv_xl_theme_21 TYPE string, + lv_xl_theme_22 TYPE string, + lv_xl_theme_23 TYPE string, + lv_xl_theme_24 TYPE string, + lv_xl_theme_25 TYPE string, + lv_xl_theme_26 TYPE string, + lv_xl_theme_27 TYPE string, + lv_xl_theme_28 TYPE string, + lv_xl_theme_29 TYPE string, + lv_xl_theme_30 TYPE string, + lv_xl_theme_31 TYPE string, + lv_xl_theme_32 TYPE string. + + lv_xl_theme_01 = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'. + lv_xl_theme_02 = '<a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" name="Office Theme"><a:themeElements><a:clrScheme name="Office"><a:dk1><a:sysClr val="windowText" lastClr="000000"/></a:dk1><a:lt1><a:sysClr val="window" '. + lv_xl_theme_03 = 'lastClr="FFFFFF"/></a:lt1><a:dk2><a:srgbClr val="1F497D"/></a:dk2><a:lt2><a:srgbClr val="EEECE1"/></a:lt2><a:accent1><a:srgbClr val="4F81BD"/></a:accent1><a:accent2><a:srgbClr val="C0504D"/></a:accent2><a:accent3><a:srgbClr '. + lv_xl_theme_04 = 'val="9BBB59"/></a:accent3><a:accent4><a:srgbClr val="8064A2"/></a:accent4><a:accent5><a:srgbClr val="4BACC6"/></a:accent5><a:accent6><a:srgbClr val="F79646"/></a:accent6><a:hlink><a:srgbClr val="0000FF"/></a:hlink><a:folHlink>'. + lv_xl_theme_05 = '<a:srgbClr val="800080"/></a:folHlink></a:clrScheme><a:fontScheme name="Office"><a:majorFont><a:latin typeface="Cambria"/><a:ea typeface=""/><a:cs typeface=""/>'. + lv_xl_theme_06 = '<a:font script="Arab" typeface="Times New Roman"/><a:font script="Hebr" typeface="Times New Roman"/><a:font script="Thai" '. + lv_xl_theme_07 = 'typeface="Tahoma"/><a:font script="Ethi" typeface="Nyala"/><a:font script="Beng" typeface="Vrinda"/><a:font script="Gujr" typeface="Shruti"/><a:font script="Khmr" typeface="MoolBoran"/><a:font script="Knda" typeface="Tunga"/><a:font '. + lv_xl_theme_08 = 'script="Guru" typeface="Raavi"/><a:font script="Cans" typeface="Euphemia"/><a:font script="Cher" typeface="Plantagenet Cherokee"/><a:font script="Yiii" typeface="Microsoft Yi Baiti"/><a:font script="Tibt" '. + lv_xl_theme_09 = 'typeface="Microsoft Himalaya"/><a:font script="Thaa" typeface="MV Boli"/><a:font script="Deva" typeface="Mangal"/><a:font script="Telu" typeface="Gautami"/><a:font script="Taml" typeface="Latha"/><a:font script="Syrc" '. + lv_xl_theme_10 = 'typeface="Estrangelo Edessa"/><a:font script="Orya" typeface="Kalinga"/><a:font script="Mlym" typeface="Kartika"/><a:font script="Laoo" typeface="DokChampa"/><a:font script="Sinh" typeface="Iskoola Pota"/><a:font script="Mong" '. + lv_xl_theme_11 = 'typeface="Mongolian Baiti"/><a:font script="Viet" typeface="Times New Roman"/><a:font script="Uigh" typeface="Microsoft Uighur"/></a:majorFont><a:minorFont><a:latin typeface="Calibri"/><a:ea typeface=""/><a:cs typeface=""/>'. + lv_xl_theme_12 = '<a:font script="Arab" typeface="Arial"/><a:font script="Hebr" '. + lv_xl_theme_13 = 'typeface="Arial"/><a:font script="Thai" typeface="Tahoma"/><a:font script="Ethi" typeface="Nyala"/><a:font script="Beng" typeface="Vrinda"/><a:font script="Gujr" typeface="Shruti"/><a:font script="Khmr" typeface="DaunPenh"/><a:font '. + lv_xl_theme_14 = 'script="Knda" typeface="Tunga"/><a:font script="Guru" typeface="Raavi"/><a:font script="Cans" typeface="Euphemia"/><a:font script="Cher" typeface="Plantagenet Cherokee"/><a:font script="Yiii" typeface="Microsoft Yi Baiti"/><a:font '. + lv_xl_theme_15 = 'script="Tibt" typeface="Microsoft Himalaya"/><a:font script="Thaa" typeface="MV Boli"/><a:font script="Deva" typeface="Mangal"/><a:font script="Telu" typeface="Gautami"/><a:font script="Taml" typeface="Latha"/><a:font script="Syrc" '. + lv_xl_theme_16 = 'typeface="Estrangelo Edessa"/><a:font script="Orya" typeface="Kalinga"/><a:font script="Mlym" typeface="Kartika"/><a:font script="Laoo" typeface="DokChampa"/><a:font script="Sinh" typeface="Iskoola Pota"/><a:font script="Mong" '. + lv_xl_theme_17 = 'typeface="Mongolian Baiti"/><a:font script="Viet" typeface="Arial"/><a:font script="Uigh" typeface="Microsoft Uighur"/></a:minorFont></a:fontScheme><a:fmtScheme name="Office"><a:fillStyleLst><a:solidFill><a:schemeClr val="phClr"/>'. + lv_xl_theme_18 = '</a:solidFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="50000"/><a:satMod val="300000"/></a:schemeClr></a:gs><a:gs pos="35000"><a:schemeClr val="phClr"><a:tint val="37000"/><a:satMod '. + lv_xl_theme_19 = 'val="300000"/></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:tint val="15000"/><a:satMod val="350000"/></a:schemeClr></a:gs></a:gsLst><a:lin ang="16200000" scaled="1"/></a:gradFill><a:gradFill rotWithShape="1">'. + lv_xl_theme_20 = '<a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:shade val="51000"/><a:satMod val="130000"/></a:schemeClr></a:gs><a:gs pos="80000"><a:schemeClr val="phClr"><a:shade val="93000"/><a:satMod val="130000"/></a:schemeClr></a:gs><a:gs '. + lv_xl_theme_21 = 'pos="100000"><a:schemeClr val="phClr"><a:shade val="94000"/><a:satMod val="135000"/></a:schemeClr></a:gs></a:gsLst><a:lin ang="16200000" scaled="0"/></a:gradFill></a:fillStyleLst><a:lnStyleLst><a:ln w="9525" cap="flat" cmpd="sng" '. + lv_xl_theme_22 = 'algn="ctr"><a:solidFill><a:schemeClr val="phClr"><a:shade val="95000"/><a:satMod val="105000"/></a:schemeClr></a:solidFill><a:prstDash val="solid"/></a:ln><a:ln w="25400" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr '. + lv_xl_theme_23 = 'val="phClr"/></a:solidFill><a:prstDash val="solid"/></a:ln><a:ln w="38100" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/></a:ln></a:lnStyleLst><a:effectStyleLst>'. + lv_xl_theme_24 = '<a:effectStyle><a:effectLst><a:outerShdw blurRad="40000" dist="20000" dir="5400000" rotWithShape="0"><a:srgbClr val="000000"><a:alpha val="38000"/></a:srgbClr></a:outerShdw></a:effectLst></a:effectStyle><a:effectStyle><a:effectLst>'. + lv_xl_theme_25 = '<a:outerShdw blurRad="40000" dist="23000" dir="5400000" rotWithShape="0"><a:srgbClr val="000000"><a:alpha val="35000"/></a:srgbClr></a:outerShdw></a:effectLst></a:effectStyle><a:effectStyle><a:effectLst><a:outerShdw blurRad="40000" '. + lv_xl_theme_26 = 'dist="23000" dir="5400000" rotWithShape="0"><a:srgbClr val="000000"><a:alpha val="35000"/></a:srgbClr></a:outerShdw></a:effectLst><a:scene3d><a:camera prst="orthographicFront"><a:rot lat="0" lon="0" rev="0"/></a:camera><a:lightRig '. + lv_xl_theme_27 = 'rig="threePt" dir="t"><a:rot lat="0" lon="0" rev="1200000"/></a:lightRig></a:scene3d><a:sp3d><a:bevelT w="63500" h="25400"/></a:sp3d></a:effectStyle></a:effectStyleLst><a:bgFillStyleLst><a:solidFill><a:schemeClr val="phClr"/>'. + lv_xl_theme_28 = '</a:solidFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="40000"/><a:satMod val="350000"/></a:schemeClr></a:gs><a:gs pos="40000"><a:schemeClr val="phClr"><a:tint val="45000"/><a:shade '. + lv_xl_theme_29 = 'val="99000"/><a:satMod val="350000"/></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:shade val="20000"/><a:satMod val="255000"/></a:schemeClr></a:gs></a:gsLst><a:path path="circle"><a:fillToRect l="50000" '. + lv_xl_theme_30 = 't="-80000" r="50000" b="180000"/></a:path></a:gradFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="80000"/><a:satMod val="300000"/></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr '. + lv_xl_theme_31 = 'val="phClr"><a:shade val="30000"/><a:satMod val="200000"/></a:schemeClr></a:gs></a:gsLst><a:path path="circle"><a:fillToRect l="50000" t="50000" r="50000" b="50000"/></a:path></a:gradFill></a:bgFillStyleLst></a:fmtScheme>'. + lv_xl_theme_32 = '</a:themeElements><a:objectDefaults/><a:extraClrSchemeLst/></a:theme>'. + + + CONCATENATE lv_xl_theme_01 lv_xl_theme_02 lv_xl_theme_03 lv_xl_theme_04 lv_xl_theme_05 lv_xl_theme_06 lv_xl_theme_07 lv_xl_theme_08 lv_xl_theme_09 lv_xl_theme_10 lv_xl_theme_11 lv_xl_theme_12 lv_xl_theme_13 lv_xl_theme_14 lv_xl_theme_15 + lv_xl_theme_16 lv_xl_theme_17 lv_xl_theme_18 lv_xl_theme_19 lv_xl_theme_20 lv_xl_theme_21 lv_xl_theme_22 lv_xl_theme_23 lv_xl_theme_24 lv_xl_theme_25 lv_xl_theme_26 lv_xl_theme_27 lv_xl_theme_28 lv_xl_theme_29 lv_xl_theme_30 + lv_xl_theme_31 lv_xl_theme_32 + INTO lv_xl_theme SEPARATED BY space. + + CALL FUNCTION 'SCMS_STRING_TO_XSTRING' + EXPORTING + text = lv_xl_theme + IMPORTING + buffer = ep_content. + + + endmethod. + + + + method CREATE_XL_WORKBOOK. +*--------------------------------------------------------------------* +* issue #230 - Pimp my Code +* - 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 +* changes: correction of pointer to localSheetId +*--------------------------------------------------------------------* + +** Constant node name + DATA: lc_xml_node_workbook TYPE string VALUE 'workbook', + lc_xml_node_fileversion TYPE string VALUE 'fileVersion', + lc_xml_node_workbookpr TYPE string VALUE 'workbookPr', + lc_xml_node_bookviews TYPE string VALUE 'bookViews', + lc_xml_node_workbookview TYPE string VALUE 'workbookView', + lc_xml_node_sheets TYPE string VALUE 'sheets', + lc_xml_node_sheet TYPE string VALUE 'sheet', + lc_xml_node_calcpr TYPE string VALUE 'calcPr', + lc_xml_node_workbookprotection TYPE string VALUE 'workbookProtection', + lc_xml_node_definednames TYPE string VALUE 'definedNames', + lc_xml_node_definedname TYPE string VALUE 'definedName', + " Node attributes + lc_xml_attr_appname TYPE string VALUE 'appName', + lc_xml_attr_lastedited TYPE string VALUE 'lastEdited', + lc_xml_attr_lowestedited TYPE string VALUE 'lowestEdited', + lc_xml_attr_rupbuild TYPE string VALUE 'rupBuild', + lc_xml_attr_themeversion TYPE string VALUE 'defaultThemeVersion', + lc_xml_attr_xwindow TYPE string VALUE 'xWindow', + lc_xml_attr_ywindow TYPE string VALUE 'yWindow', + lc_xml_attr_windowwidth TYPE string VALUE 'windowWidth', + lc_xml_attr_windowheight TYPE string VALUE 'windowHeight', + lc_xml_attr_activetab TYPE string VALUE 'activeTab', + lc_xml_attr_name TYPE string VALUE 'name', + lc_xml_attr_sheetid TYPE string VALUE 'sheetId', + lc_xml_attr_state TYPE string VALUE 'state', + lc_xml_attr_id TYPE string VALUE 'id', + lc_xml_attr_calcid TYPE string VALUE 'calcId', + lc_xml_attr_lockrevision TYPE string VALUE 'lockRevision', + lc_xml_attr_lockstructure TYPE string VALUE 'lockStructure', + lc_xml_attr_lockwindows TYPE string VALUE 'lockWindows', + lc_xml_attr_revisionspassword TYPE string VALUE 'revisionsPassword', + lc_xml_attr_workbookpassword TYPE string VALUE 'workbookPassword', + lc_xml_attr_hidden TYPE string VALUE 'hidden', + lc_xml_attr_localsheetid TYPE string VALUE 'localSheetId', + " Node namespace + lc_r_ns TYPE string VALUE 'r', + lc_xml_node_ns TYPE string VALUE 'http://schemas.openxmlformats.org/spreadsheetml/2006/main', + lc_xml_node_r_ns TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships', + " Node id + lc_xml_node_ridx_id TYPE string VALUE 'rId#'. + + 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 TYPE REF TO if_ixml_element, + lo_element_range TYPE REF TO if_ixml_element, + lo_sub_element 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_iterator_range TYPE REF TO cl_object_collection_iterator, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + lo_range TYPE REF TO zcl_excel_range, + lo_autofilters TYPE REF TO zcl_excel_autofilters, + lo_autofilter TYPE REF TO zcl_excel_autofilter. + + DATA: lv_xml_node_ridx_id TYPE string, + lv_value TYPE string, + lv_syindex TYPE string, + l_guid TYPE uuid, + lv_active_sheet TYPE zexcel_active_worksheet. + +********************************************************************** +* STEP 1: Create [Content_Types].xml into the root of the ZIP + 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 ). + +********************************************************************** +* STEP 3: Create main node + lo_element_root = lo_document->create_simple_element( name = lc_xml_node_workbook + parent = lo_document ). + lo_element_root->set_attribute_ns( name = 'xmlns' + value = lc_xml_node_ns ). + lo_element_root->set_attribute_ns( name = 'xmlns:r' + value = lc_xml_node_r_ns ). + +********************************************************************** +* STEP 4: Create subnode + " fileVersion node + lo_element = lo_document->create_simple_element( name = lc_xml_node_fileversion + parent = lo_document ). + lo_element->set_attribute_ns( name = lc_xml_attr_appname + value = 'xl' ). + lo_element->set_attribute_ns( name = lc_xml_attr_lastedited + value = '4' ). + lo_element->set_attribute_ns( name = lc_xml_attr_lowestedited + value = '4' ). + lo_element->set_attribute_ns( name = lc_xml_attr_rupbuild + value = '4506' ). + lo_element_root->append_child( new_child = lo_element ). + + " fileVersion node + lo_element = lo_document->create_simple_element( name = lc_xml_node_workbookpr + parent = lo_document ). + lo_element->set_attribute_ns( name = lc_xml_attr_themeversion + value = '124226' ). + lo_element_root->append_child( new_child = lo_element ). + + " workbookProtection node + IF me->excel->zif_excel_book_protection~protected EQ abap_true. + lo_element = lo_document->create_simple_element( name = lc_xml_node_workbookprotection + parent = lo_document ). + MOVE me->excel->zif_excel_book_protection~workbookpassword TO lv_value. + IF lv_value IS NOT INITIAL. + lo_element->set_attribute_ns( name = lc_xml_attr_workbookpassword + value = lv_value ). + ENDIF. + MOVE me->excel->zif_excel_book_protection~revisionspassword TO lv_value. + IF lv_value IS NOT INITIAL. + lo_element->set_attribute_ns( name = lc_xml_attr_revisionspassword + value = lv_value ). + ENDIF. + MOVE me->excel->zif_excel_book_protection~lockrevision TO lv_value. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_lockrevision + value = lv_value ). + MOVE me->excel->zif_excel_book_protection~lockstructure TO lv_value. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_lockstructure + value = lv_value ). + MOVE me->excel->zif_excel_book_protection~lockwindows TO lv_value. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_lockwindows + value = lv_value ). + lo_element_root->append_child( new_child = lo_element ). + ENDIF. + + " bookviews node + lo_element = lo_document->create_simple_element( name = lc_xml_node_bookviews + parent = lo_document ). + " bookview node + lo_sub_element = lo_document->create_simple_element( name = lc_xml_node_workbookview + parent = lo_document ). + lo_sub_element->set_attribute_ns( name = lc_xml_attr_xwindow + value = '120' ). + lo_sub_element->set_attribute_ns( name = lc_xml_attr_ywindow + value = '120' ). + lo_sub_element->set_attribute_ns( name = lc_xml_attr_windowwidth + value = '19035' ). + lo_sub_element->set_attribute_ns( name = lc_xml_attr_windowheight + value = '8445' ). + " Set Active Sheet + lv_active_sheet = excel->get_active_sheet_index( ). + IF lv_active_sheet > 1. + lv_active_sheet = lv_active_sheet - 1. + lv_value = lv_active_sheet. + CONDENSE lv_value. + lo_sub_element->set_attribute_ns( name = lc_xml_attr_activetab + value = lv_value ). + ENDIF. + lo_element->append_child( new_child = lo_sub_element )." bookview node + lo_element_root->append_child( new_child = lo_element )." bookviews node + + " sheets node + lo_element = lo_document->create_simple_element( name = lc_xml_node_sheets + parent = lo_document ). + lo_iterator = excel->get_worksheets_iterator( ). + + " ranges node + lo_element_range = lo_document->create_simple_element( name = lc_xml_node_definednames " issue 163 + + parent = lo_document ). " issue 163 + + + WHILE lo_iterator->if_object_collection_iterator~has_next( ) EQ abap_true. + " sheet node + 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_value = lo_worksheet->get_title( ). + 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_sub_element->set_attribute_ns( name = lc_xml_attr_name + value = lv_value ). + lo_sub_element->set_attribute_ns( name = lc_xml_attr_sheetid + value = lv_syindex ). + IF lo_worksheet->zif_excel_sheet_properties~hidden EQ zif_excel_sheet_properties=>c_hidden. + lo_sub_element->set_attribute_ns( name = lc_xml_attr_state + value = 'hidden' ). + ELSEIF lo_worksheet->zif_excel_sheet_properties~hidden EQ zif_excel_sheet_properties=>c_veryhidden. + lo_sub_element->set_attribute_ns( name = lc_xml_attr_state + value = 'veryHidden' ). + ENDIF. + lo_sub_element->set_attribute_ns( name = lc_xml_attr_id + prefix = lc_r_ns + value = lv_xml_node_ridx_id ). + lo_element->append_child( new_child = lo_sub_element ). " sheet node + + " issue 163 >>> + lo_iterator_range = lo_worksheet->get_ranges_iterator( ). + +*--------------------------------------------------------------------* +* Defined names sheetlocal: Ranges, Repeat rows and columns +*--------------------------------------------------------------------* + WHILE lo_iterator_range->if_object_collection_iterator~has_next( ) EQ abap_true. + " range node + lo_sub_element = lo_document->create_simple_element_ns( name = lc_xml_node_definedname + parent = lo_document ). + lo_range ?= lo_iterator_range->if_object_collection_iterator~get_next( ). + lv_value = lo_range->name. + + lo_sub_element->set_attribute_ns( name = lc_xml_attr_name + value = lv_value ). + +* lo_sub_element->set_attribute_ns( name = lc_xml_attr_localsheetid "del #235 Repeat rows/cols - EXCEL starts couting from zero +* value = lv_xml_node_ridx_id ). "del #235 Repeat rows/cols - and needs absolute referencing to localSheetId + lv_value = lv_syindex - 1. "ins #235 Repeat rows/cols + CONDENSE lv_value NO-GAPS. "ins #235 Repeat rows/cols + lo_sub_element->set_attribute_ns( name = lc_xml_attr_localsheetid + value = lv_value ). + + lv_value = lo_range->get_value( ). + lo_sub_element->set_value( value = lv_value ). + lo_element_range->append_child( new_child = lo_sub_element ). " range node + + ENDWHILE. + " issue 163 <<< + + ENDWHILE. + lo_element_root->append_child( new_child = lo_element )." sheets node + + +*--------------------------------------------------------------------* +* Defined names workbookgolbal: Ranges +*--------------------------------------------------------------------* +* " ranges node +* lo_element = lo_document->create_simple_element( name = lc_xml_node_definednames " issue 163 - +* parent = lo_document ). " issue 163 - + lo_iterator = excel->get_ranges_iterator( ). + + WHILE lo_iterator->if_object_collection_iterator~has_next( ) EQ abap_true. + " range node + lo_sub_element = lo_document->create_simple_element_ns( name = lc_xml_node_definedname + parent = lo_document ). + lo_range ?= lo_iterator->if_object_collection_iterator~get_next( ). + lv_value = lo_range->name. + lo_sub_element->set_attribute_ns( name = lc_xml_attr_name + value = lv_value ). + lv_value = lo_range->get_value( ). + lo_sub_element->set_value( value = lv_value ). + lo_element_range->append_child( new_child = lo_sub_element ). " range node + + ENDWHILE. + +*--------------------------------------------------------------------* +* Defined names - Autofilters ( also sheetlocal ) +*--------------------------------------------------------------------* + lo_autofilters = excel->get_autofilters_reference( ). + IF lo_autofilters->is_empty( ) = abap_false. + lo_iterator = excel->get_worksheets_iterator( ). + WHILE lo_iterator->if_object_collection_iterator~has_next( ) EQ abap_true. + + lo_worksheet ?= lo_iterator->if_object_collection_iterator~get_next( ). + lv_syindex = sy-index - 1 . + l_guid = lo_worksheet->get_guid( ). + lo_autofilter = lo_autofilters->get( i_sheet_guid = l_guid ) . + IF lo_autofilter IS BOUND. + lo_sub_element = lo_document->create_simple_element_ns( name = lc_xml_node_definedname + parent = lo_document ). + lv_value = lo_autofilters->c_autofilter. + lo_sub_element->set_attribute_ns( name = lc_xml_attr_name + value = lv_value ). + lv_value = lv_syindex. + CONDENSE lv_value NO-GAPS. + lo_sub_element->set_attribute_ns( name = lc_xml_attr_localsheetid + value = lv_value ). + lv_value = '1'. " Always hidden + lo_sub_element->set_attribute_ns( name = lc_xml_attr_hidden + value = lv_value ). + lv_value = lo_autofilter->get_filter_reference( ). + lo_sub_element->set_value( value = lv_value ). + lo_element_range->append_child( new_child = lo_sub_element ). " range node + ENDIF. + + ENDWHILE. + ENDIF. + lo_element_root->append_child( new_child = lo_element_range ). " ranges node + + + " calcPr node + lo_element = lo_document->create_simple_element( name = lc_xml_node_calcpr + parent = lo_document ). + lo_element->set_attribute_ns( name = lc_xml_attr_calcid + value = '125725' ). + lo_element_root->append_child( new_child = lo_element ). + +********************************************************************** +* 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( ). + + endmethod. + + + + + method FLAG2BOOL. + + + IF ip_flag EQ abap_true. + ep_boolean = 'true'. + ELSE. + ep_boolean = 'false'. + ENDIF. + endmethod. + + + + + method GET_SHARED_STRING_INDEX. + + + DATA ls_shared_string TYPE zexcel_s_shared_string. + + 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. + + + + + *"* 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_WRITER~WRITE_FILE. + me->excel = io_excel. + ep_file = me->create( ). + endmethod. + + + + method CREATE. + +* .csv format with ; delimiter + + ep_excel = me->CREATE_CSV( ). + + endmethod. + + + + method CREATE_CSV. + + TYPES: BEGIN OF lty_format, + cmpname TYPE SEOCMPNAME, + attvalue TYPE SEOVALUE, + END OF lty_format. + DATA: lt_format TYPE STANDARD TABLE OF lty_format, + ls_format LIKE LINE OF lt_format, + lv_date TYPE DATS, + lv_tmp TYPE string, + lv_time TYPE CHAR08. + + DATA: lo_iterator TYPE REF TO cl_object_collection_iterator, + lo_worksheet TYPE REF TO zcl_excel_worksheet. + + DATA: lt_cell_data TYPE zexcel_t_cell_data_unsorted, + lv_row TYPE sytabix, + lv_col TYPE sytabix, + lv_string TYPE string, + lc_value TYPE string, + lv_attrname TYPE SEOCMPNAME. + + DATA: ls_numfmt TYPE zexcel_s_style_numfmt, + lo_style TYPE REF TO zcl_excel_style. + + FIELD-SYMBOLS: <fs_sheet_content> TYPE zexcel_s_cell_data. + +* --- Retrieve supported cell format + REFRESH lt_format. + SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_format + FROM seocompodf + WHERE clsname = 'ZCL_EXCEL_STYLE_NUMBER_FORMAT' + AND typtype = 1 + AND type = 'ZEXCEL_NUMBER_FORMAT'. + +* --- Retrieve SAP date format + CLEAR ls_format. + SELECT ddtext INTO ls_format-attvalue FROM dd07t WHERE domname = 'XUDATFM' + AND ddlanguage = sy-langu. + ls_format-cmpname = 'DATE'. + CONDENSE ls_format-attvalue. + CONCATENATE '''' ls_format-attvalue '''' INTO ls_format-attvalue. + APPEND ls_format TO lt_format. + ENDSELECT. + + + LOOP AT lt_format INTO ls_format. + TRANSLATE ls_format-attvalue TO UPPER CASE. + MODIFY lt_format FROM ls_format. + ENDLOOP. + + +* STEP 1: Collect strings from the first worksheet + lo_iterator = excel->get_worksheets_iterator( ). + data: current_worksheet_title type ZEXCEL_SHEET_TITLE. + + WHILE lo_iterator->if_object_collection_iterator~has_next( ) EQ abap_true. + lo_worksheet ?= lo_iterator->if_object_collection_iterator~get_next( ). + + IF worksheet_name IS NOT INITIAL. + current_worksheet_title = lo_worksheet->get_title( ). + CHECK current_worksheet_title = worksheet_name. + ELSE. + IF worksheet_index IS INITIAL. + worksheet_index = 1. + ENDIF. + CHECK worksheet_index = sy-index. + ENDIF. + APPEND LINES OF lo_worksheet->sheet_content TO lt_cell_data. + EXIT. " Take first worksheet only + ENDWHILE. + + DELETE lt_cell_data WHERE cell_formula IS NOT INITIAL. " delete formula content + + SORT lt_cell_data BY cell_row + cell_column. + lv_row = 1. + lv_col = 1. + CLEAR lv_string. + LOOP AT lt_cell_data ASSIGNING <fs_sheet_content>. + +* --- Retrieve Cell Style format and data type + CLEAR ls_numfmt. + IF <fs_sheet_content>-data_type IS INITIAL AND <fs_sheet_content>-cell_style IS NOT INITIAL. + 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( ). + CHECK lo_style->get_guid( ) = <fs_sheet_content>-cell_style. + ls_numfmt = lo_style->number_format->get_structure( ). + EXIT. + ENDWHILE. + ENDIF. + IF <fs_sheet_content>-data_type IS INITIAL AND ls_numfmt IS NOT INITIAL. + " determine data-type + CLEAR lv_attrname. + CONCATENATE '''' ls_numfmt-NUMFMT '''' INTO ls_numfmt-NUMFMT. + TRANSLATE ls_numfmt-numfmt TO UPPER CASE. + READ TABLE lt_format INTO ls_format WITH KEY attvalue = ls_numfmt-NUMFMT. + IF sy-subrc = 0. + lv_attrname = ls_format-cmpname. + ENDIF. + + IF lv_attrname IS NOT INITIAL. + FIND FIRST OCCURRENCE OF 'DATETIME' IN lv_attrname. + IF sy-subrc = 0. + <fs_sheet_content>-data_type = 'd'. + ELSE. + FIND FIRST OCCURRENCE OF 'TIME' IN lv_attrname. + IF sy-subrc = 0. + <fs_sheet_content>-data_type = 't'. + ELSE. + FIND FIRST OCCURRENCE OF 'DATE' IN lv_attrname. + IF sy-subrc = 0. + <fs_sheet_content>-data_type = 'd'. + ELSE. + FIND FIRST OCCURRENCE OF 'CURRENCY' IN lv_attrname. + IF sy-subrc = 0. + <fs_sheet_content>-data_type = 'n'. + ELSE. + FIND FIRST OCCURRENCE OF 'NUMBER' IN lv_attrname. + IF sy-subrc = 0. + <fs_sheet_content>-data_type = 'n'. + ELSE. + FIND FIRST OCCURRENCE OF 'PERCENTAGE' IN lv_attrname. + IF sy-subrc = 0. + <fs_sheet_content>-data_type = 'n'. + ENDIF. " Purcentage + ENDIF. " Number + ENDIF. " Currency + ENDIF. " Date + ENDIF. " TIME + ENDIF. " DATETIME + ENDIF. " lv_attrname IS NOT INITIAL. + ENDIF. " <fs_sheet_content>-data_type IS INITIAL AND ls_numfmt IS NOT INITIAL. + +* --- Add empty rows + WHILE lv_row < <fs_sheet_content>-cell_row. +* CONCATENATE lv_string cl_abap_char_utilities=>newline INTO lv_string. +* CONCATENATE lv_string cl_abap_char_utilities=>cr_lf INTO lv_string. + CONCATENATE lv_string zcl_excel_writer_csv=>eol INTO lv_string. + lv_row = lv_row + 1. + lv_col = 1. + ENDWHILE. + +* --- Add empty columns + WHILE lv_col < <fs_sheet_content>-cell_column. +* CONCATENATE lv_string ';' INTO lv_string. + CONCATENATE lv_string zcl_excel_writer_csv=>delimiter INTO lv_string. + lv_col = lv_col + 1. + ENDWHILE. + +* ----- Use format to determine the data type and display format. + CASE <fs_sheet_content>-data_type. +* WHEN 'n' OR 'N'. +* lc_value = zcl_excel_common=>excel_number_to_string( ip_value = <fs_sheet_content>-cell_value ). + + WHEN 'd' OR 'D'. + lc_value = zcl_excel_common=>excel_string_to_date( ip_value = <fs_sheet_content>-cell_value ). + TRY. + lv_date = lc_value. + CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL' + EXPORTING + DATE_INTERNAL = lv_date + IMPORTING + DATE_EXTERNAL = lv_tmp + EXCEPTIONS + DATE_INTERNAL_IS_INVALID = 1 + OTHERS = 2 + . + IF SY-SUBRC = 0. + lc_value = lv_tmp. + ENDIF. + + CATCH CX_SY_CONVERSION_NO_NUMBER. + + ENDTRY. + + WHEN 't' OR 'T'. + lc_value = zcl_excel_common=>excel_string_to_time( ip_value = <fs_sheet_content>-cell_value ). + write lc_value to lv_time USING EDIT MASK '__:__:__'. + lc_value = lv_time. + WHEN OTHERS. + lc_value = <fs_sheet_content>-cell_value. + + ENDCASE. + +* REPLACE ALL OCCURRENCES OF '"' in lc_value with '""'. + CONCATENATE zcl_excel_writer_csv=>enclosure zcl_excel_writer_csv=>enclosure INTO lv_tmp. + CONDENSE lv_tmp. + REPLACE ALL OCCURRENCES OF zcl_excel_writer_csv=>enclosure in lc_value with lv_tmp. + +* FIND FIRST OCCURRENCE OF ';' IN lc_value. + FIND FIRST OCCURRENCE OF zcl_excel_writer_csv=>delimiter IN lc_value. + IF sy-subrc = 0. + CONCATENATE lv_string zcl_excel_writer_csv=>enclosure lc_value zcl_excel_writer_csv=>enclosure INTO lv_string. + ELSE. + CONCATENATE lv_string lc_value INTO lv_string. + ENDIF. + + ENDLOOP. " AT lt_cell_data + + CLEAR ep_content. + + CALL FUNCTION 'SCMS_STRING_TO_XSTRING' + EXPORTING + TEXT = lv_string +* MIMETYPE = ' ' +* ENCODING = + IMPORTING + BUFFER = ep_content + EXCEPTIONS + FAILED = 1 + OTHERS = 2 + . + + endmethod. + + + + method SET_ACTIVE_SHEET_INDEX. + CLEAR WORKSHEET_NAME. + WORKSHEET_INDEX = i_active_worksheet. + endmethod. + + + + method SET_ACTIVE_SHEET_INDEX_BY_NAME. + CLEAR WORKSHEET_INDEX. + WORKSHEET_NAME = i_worksheet_name. + endmethod. + + + + method SET_DELIMITER. + delimiter = ip_value. + endmethod. + + + + method SET_ENCLOSURE. + zcl_excel_writer_csv=>enclosure = ip_value. + endmethod. + + + + method SET_ENDOFLINE. + zcl_excel_writer_csv=>eol = 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 + + + + + + + + + + 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 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 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. + + + + + + + *"* 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. + + + + + + + *"* 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 + 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 + + + + + + + + + + + + + + method ZIF_EXCEL_BOOK_PROPERTIES~INITIALIZE. + DATA: lv_timestamp TYPE timestampl. + + me->zif_excel_book_properties~application = 'Microsoft Excel'. + me->zif_excel_book_properties~appversion = '12.0000'. + + GET TIME STAMP FIELD lv_timestamp. + me->zif_excel_book_properties~created = lv_timestamp. + me->zif_excel_book_properties~creator = sy-uname. + me->zif_excel_book_properties~modified = lv_timestamp. + me->zif_excel_book_properties~lastmodifiedby = sy-uname. + endmethod. + + + method ZIF_EXCEL_BOOK_PROTECTION~INITIALIZE. + me->zif_excel_book_protection~protected = zif_excel_book_protection=>c_unprotected. + me->zif_excel_book_protection~lockrevision = zif_excel_book_protection=>c_unlocked. + me->zif_excel_book_protection~lockstructure = zif_excel_book_protection=>c_unlocked. + me->zif_excel_book_protection~lockwindows = zif_excel_book_protection=>c_unlocked. + CLEAR me->zif_excel_book_protection~workbookpassword. + CLEAR me->zif_excel_book_protection~revisionspassword. + endmethod. + + + method ZIF_EXCEL_BOOK_VBA_PROJECT~SET_CODENAME. + me->zif_excel_book_vba_project~codename = ip_codename. + endmethod. + + + method ZIF_EXCEL_BOOK_VBA_PROJECT~SET_CODENAME_PR. + me->zif_excel_book_vba_project~codename_pr = ip_codename_pr. + endmethod. + + + method ZIF_EXCEL_BOOK_VBA_PROJECT~SET_VBAPROJECT. + me->zif_excel_book_vba_project~vbaproject = ip_vbaproject. + endmethod. + + + + + method ADD_NEW_AUTOFILTER. +* Check for autofilter reference: new or overwrite; only one per sheet + ro_autofilter = autofilters->add( io_sheet = io_sheet ) . + endmethod. + + + + + + method ADD_NEW_DRAWING. + DATA: lv_guid TYPE guid_16. +* Create default blank worksheet + CREATE OBJECT eo_drawing + EXPORTING + ip_type = ip_type + ip_title = ip_title. + + CASE ip_type. + WHEN 'image'. + drawings->add( eo_drawing ). + WHEN 'chart'. + charts->add( eo_drawing ). + ENDCASE. + endmethod. + + + + method ADD_NEW_RANGE. +* Create default blank range + CREATE OBJECT eo_range. + ranges->add( eo_range ). + endmethod. + + + + + method ADD_NEW_STYLE. +* Start of deletion # issue 139 - Dateretention of cellstyles +* CREATE OBJECT eo_style. +* styles->add( eo_style ). +* End of deletion # issue 139 - Dateretention of cellstyles +* Start of insertion # issue 139 - Dateretention of cellstyles +* Create default style + CREATE OBJECT eo_style + EXPORTING + ip_guid = ip_guid. + styles->add( eo_style ). + + DATA: style2 TYPE zexcel_s_stylemapping. +* Copy to new representations + style2 = stylemapping_dynamic_style( eo_style ). + INSERT style2 INTO TABLE t_stylemapping1. + INSERT style2 INTO TABLE t_stylemapping2. +* End of insertion # issue 139 - Dateretention of cellstyles + + endmethod. + + + + + + method ADD_NEW_WORKSHEET. + DATA: lv_guid TYPE guid_16. + +* Create default blank worksheet + CREATE OBJECT eo_worksheet + EXPORTING + ip_excel = me + ip_title = ip_title. + + worksheets->add( eo_worksheet ). + worksheets->active_worksheet = worksheets->size( ). + endmethod. + + + method ADD_STATIC_STYLES. + " # issue 139 +* sp#ƒÂ¤ter hier noch die Worksheets abklappern, welche Styles #ƒÂ#berhaupt noch ben#ƒÂ#tigt werden +* und nur diese dann auch hier zur Verf#ƒÂ#gung stellen +* Da muss ich noch mal nachfragen, ob die beiden ersten Styles, die scheinbar immer mit dem +* EXCEL-Objekt erzeugt werden evtl. immer ben#ƒÂ#tigt werden, egal ob verwendet oder nicht +* Aber als Start fange ich mal an einfach alle static styles der Reihe nach hinzuzuf#ƒÂ#gen + FIELD-SYMBOLS: <style1> LIKE LINE OF t_stylemapping1, + <style2> LIKE LINE OF t_stylemapping2. + DATA: style TYPE REF TO zcl_excel_style. + + LOOP AT me->t_stylemapping1 ASSIGNING <style1> WHERE added_to_iterator IS INITIAL. + READ TABLE me->t_stylemapping2 ASSIGNING <style2> WITH TABLE KEY guid = <style1>-guid. + CHECK sy-subrc = 0. " Should always be true since these tables are being filled parallel + + style = me->add_new_style( <style1>-guid ). + + zcl_excel_common=>recursive_struct_to_class( EXPORTING i_source = <style1>-complete_style + i_sourcex = <style1>-complete_stylex + CHANGING e_target = style ). + + ENDLOOP. + endmethod. + + + method CONSTRUCTOR. + DATA: lo_worksheet TYPE REF TO zcl_excel_worksheet, + lo_style TYPE REF TO zcl_excel_style. + +* Inizialize instance objects + CREATE OBJECT security. + CREATE OBJECT worksheets. + CREATE OBJECT ranges. + CREATE OBJECT styles. + CREATE OBJECT drawings + EXPORTING + ip_type = zcl_excel_drawing=>type_image. + CREATE OBJECT charts + EXPORTING + ip_type = zcl_excel_drawing=>type_chart. + CREATE OBJECT legacy_palette. + CREATE OBJECT autofilters. + + me->zif_excel_book_protection~initialize( ). + me->zif_excel_book_properties~initialize( ). + + me->add_new_worksheet( ). + me->add_new_style( ). " Standard style + lo_style = me->add_new_style( ). " Standard style with fill gray125 + lo_style->fill->filltype = zcl_excel_style_fill=>c_fill_pattern_gray125. + + endmethod. + + + + method GET_ACTIVE_SHEET_INDEX. + r_active_worksheet = me->worksheets->active_worksheet. + endmethod. + + + + method GET_ACTIVE_WORKSHEET. + + eo_worksheet = me->worksheets->get( me->worksheets->active_worksheet ). + + endmethod. + + + + method GET_AUTOFILTERS_REFERENCE. + + ro_autofilters = autofilters. + + endmethod. + + + + method GET_DEFAULT_STYLE. + ep_style = me->default_style. + endmethod. + + + + + method GET_DRAWINGS_ITERATOR. + + CASE ip_type. + WHEN zcl_excel_drawing=>type_image. + eo_iterator = me->drawings->get_iterator( ). + WHEN zcl_excel_drawing=>type_chart. + eo_iterator = me->charts->get_iterator( ). + WHEN OTHERS. + ENDCASE. + + endmethod. + + + + method GET_NEXT_TABLE_ID. + DATA: lo_worksheet TYPE REF TO zcl_excel_worksheet, + lo_iterator TYPE REF TO cl_object_collection_iterator, + lv_tables_count TYPE i. + + lo_iterator = me->get_worksheets_iterator( ). + WHILE lo_iterator->if_object_collection_iterator~has_next( ) EQ abap_true. + lo_worksheet ?= lo_iterator->if_object_collection_iterator~get_next( ). + + lv_tables_count = lo_worksheet->get_tables_size( ). + ADD lv_tables_count TO ep_id. + + ENDWHILE. + + ADD 1 TO ep_id. + + endmethod. + + + + method GET_RANGES_ITERATOR. + + eo_iterator = me->ranges->get_iterator( ). + + endmethod. + + + + + + method GET_STATIC_CELLSTYLE_GUID. +" # issue 139 + DATA: style LIKE LINE OF me->t_stylemapping1. + + READ TABLE me->t_stylemapping1 INTO style + WITH TABLE KEY dynamic_style_guid = style-guid " no dynamic style --> look for initial guid here + complete_style = ip_cstyle_complete + complete_stylex = ip_cstylex_complete. + IF sy-subrc <> 0. + style-complete_style = ip_cstyle_complete. + style-complete_stylex = ip_cstylex_complete. + CALL FUNCTION 'GUID_CREATE' + IMPORTING + ev_guid_16 = style-guid. + INSERT style INTO TABLE me->t_stylemapping1. + INSERT style INTO TABLE me->t_stylemapping2. + + ENDIF. + + ep_guid = style-guid. + endmethod. + + + + method GET_STYLES_ITERATOR. + + eo_iterator = me->styles->get_iterator( ). + + endmethod. + + + + + + method GET_STYLE_INDEX_IN_STYLES. + DATA: index TYPE syindex. + DATA: lo_iterator TYPE REF TO cl_object_collection_iterator, + lo_style TYPE REF TO zcl_excel_style. + + CHECK ip_guid IS NOT INITIAL. + + + lo_iterator = me->get_styles_iterator( ). + WHILE lo_iterator->has_next( ) = 'X'. + ADD 1 TO index. + lo_style ?= lo_iterator->get_next( ). + IF lo_style->get_guid( ) = ip_guid. + ep_index = index. + EXIT. + ENDIF. + ENDWHILE. + + IF ep_index IS INITIAL. + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = 'Index not found'. + else. + SUBTRACT 1 from ep_index. " In excel list starts with "0" + ENDIF. + endmethod. + + + + + + method GET_STYLE_TO_GUID. + " # issue 139 + + READ TABLE me->t_stylemapping2 INTO ep_stylemapping WITH TABLE KEY guid = ip_guid. + IF sy-subrc <> 0. + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = 'GUID not found'. + ENDIF. + + IF ep_stylemapping-dynamic_style_guid IS NOT INITIAL. + zcl_excel_common=>recursive_class_to_struct( EXPORTING i_source = ep_stylemapping-cl_style + CHANGING e_target = ep_stylemapping-complete_style + e_targetx = ep_stylemapping-complete_stylex ). + ENDIF. + + + endmethod. + + + + method GET_WORKSHEETS_ITERATOR. + + eo_iterator = me->worksheets->get_iterator( ). + + endmethod. + + + + method GET_WORKSHEETS_NAME. + + ep_name = me->worksheets->name. + + endmethod. + + + + method GET_WORKSHEETS_SIZE. + + ep_size = me->worksheets->size( ). + + endmethod. + + + + + method GET_WORKSHEET_BY_NAME. + + DATA: lv_index TYPE zexcel_active_worksheet, + l_size TYPE i. + + l_size = get_worksheets_size( ). + + DO l_size TIMES. + lv_index = sy-index. + eo_worksheet = me->worksheets->get( lv_index ). + IF eo_worksheet->get_title( ) = ip_sheet_name. + RETURN. + ENDIF. + ENDDO. + + CLEAR eo_worksheet. + + endmethod. + + + + method SET_ACTIVE_SHEET_INDEX. + me->worksheets->active_worksheet = i_active_worksheet. + endmethod. + + + + method SET_ACTIVE_SHEET_INDEX_BY_NAME. + + DATA: ws_it TYPE REF TO cl_object_collection_iterator, + ws TYPE REF TO zcl_excel_worksheet, + lv_title TYPE ZEXCEL_SHEET_TITLE, + count TYPE i VALUE 1. + + ws_it = me->worksheets->get_iterator( ). + + WHILE ws_it->if_object_collection_iterator~has_next( ) = abap_true. + ws ?= ws_it->if_object_collection_iterator~get_next( ). + lv_title = ws->get_title( ). + IF lv_title = i_worksheet_name. + me->worksheets->active_worksheet = count. + EXIT. + ENDIF. + count = count + 1. + ENDWHILE. + + endmethod. + + + + + method SET_DEFAULT_STYLE. + me->default_style = ip_style. + endmethod. + + + + + method STYLEMAPPING_DYNAMIC_STYLE. +" # issue 139 + eo_style2-dynamic_style_guid = ip_style->get_guid( ). + eo_style2-guid = eo_style2-dynamic_style_guid. + eo_style2-added_to_iterator = abap_true. + eo_style2-cl_style = ip_style. + +* don't care about attributes here, since this data may change +* dynamically + + endmethod. + + + + *"* 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 + *"* 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 + + + + + + + + + + + + + + + + ABAP + + + + + + + + + + + + + + + + + + method ASSERT_DIFFERS. + DATA: ls_seoclass TYPE seoclass. + +" Let see >=7.02 + SELECT SINGLE * INTO ls_seoclass + FROM seoclass + WHERE clsname = 'CL_ABAP_UNIT_ASSERT'. + + IF sy-subrc = 0. + CALL METHOD (ls_seoclass-clsname)=>assert_differs + EXPORTING + exp = exp + act = act + msg = msg + level = level + tol = tol + quit = quit + RECEIVING + assertion_failed = assertion_failed. + ELSE. +" Let see >=7.00 or even lower + SELECT SINGLE * INTO ls_seoclass + FROM seoclass + WHERE clsname = 'CL_AUNIT_ASSERT'. + + IF sy-subrc = 0. + CALL METHOD (ls_seoclass-clsname)=>assert_differs + EXPORTING + exp = exp + act = act + msg = msg + level = level + tol = tol + quit = quit + RECEIVING + assertion_failed = assertion_failed. + ELSE. +* We do nothing for now not supported + ENDIF. + ENDIF. + endmethod. + + + + + + + + + + + method ASSERT_EQUALS. + DATA: ls_seoclass TYPE seoclass. + + " Let see >=7.02 + SELECT SINGLE * INTO ls_seoclass + FROM seoclass + WHERE clsname = 'CL_ABAP_UNIT_ASSERT'. + + IF sy-subrc = 0. + CALL METHOD (ls_seoclass-clsname)=>assert_equals + EXPORTING + exp = exp + act = act + msg = msg + level = level + tol = tol + quit = quit + ignore_hash_sequence = ignore_hash_sequence + RECEIVING + assertion_failed = assertion_failed. + ELSE. + " Let see >=7.00 or even lower + SELECT SINGLE * INTO ls_seoclass + FROM seoclass + WHERE clsname = 'CL_AUNIT_ASSERT'. + + IF sy-subrc = 0. + CALL METHOD (ls_seoclass-clsname)=>assert_equals + EXPORTING + exp = exp + act = act + msg = msg + level = level + tol = tol + quit = quit + ignore_hash_sequence = ignore_hash_sequence + RECEIVING + assertion_failed = assertion_failed. + ELSE. +* We do nothing for now not supported + ENDIF. + ENDIF. + endmethod. + + + + + + + + method CALCULATE_CELL_DISTANCE. + + DATA: lv_reference_row TYPE i, + lv_reference_col_alpha TYPE zexcel_cell_column_alpha, + lv_reference_col TYPE i, + lv_current_row TYPE i, + lv_current_col_alpha TYPE zexcel_cell_column_alpha, + lv_current_col TYPE i. + +*--------------------------------------------------------------------* +* Split reference cell into numerical row/column representation +*--------------------------------------------------------------------* + convert_columnrow2column_a_row( EXPORTING + i_columnrow = iv_reference_cell + IMPORTING + e_column = lv_reference_col_alpha + e_row = lv_reference_row ). + lv_reference_col = convert_column2int( lv_reference_col_alpha ). + +*--------------------------------------------------------------------* +* Split current cell into numerical row/column representation +*--------------------------------------------------------------------* + convert_columnrow2column_a_row( EXPORTING + i_columnrow = iv_current_cell + IMPORTING + e_column = lv_current_col_alpha + e_row = lv_current_row ). + lv_current_col = convert_column2int( lv_current_col_alpha ). + +*--------------------------------------------------------------------* +* Calculate row and column difference +* Positive: Current cell below reference cell +* or Current cell right of reference cell +* Negative: Current cell above reference cell +* or Current cell left of reference cell +*--------------------------------------------------------------------* + ev_row_difference = lv_current_row - lv_reference_row. + ev_col_difference = lv_current_col - lv_reference_col. + + endmethod. + + + + + method CHAR2HEX. + + IF o_conv IS NOT BOUND. + o_conv = cl_abap_conv_out_ce=>create( endian = 'L' + ignore_cerr = abap_true + replacement = '#' ). + ENDIF. + + CALL METHOD o_conv->reset( ). + CALL METHOD o_conv->write( data = i_char ). + r_hex+1 = o_conv->get_buffer( ). " x'65' must be x'0065' + + endmethod. + + + + + + method CONVERT_COLUMN2ALPHA. + + DATA: lv_uccpi TYPE i, + lv_text TYPE sychar02, + lv_module TYPE int4, + lv_column TYPE zexcel_cell_column. + +* Propagate zcx_excel if error occurs " issue #155 - less restrictive typing for ip_column + lv_column = convert_column2int( ip_column ). " issue #155 - less restrictive typing for ip_column + +*--------------------------------------------------------------------* +* Check whether column is in allowed range for EXCEL to handle ( 1-16384 ) +*--------------------------------------------------------------------* + IF lv_column > 16384 + OR lv_column < 1. + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = 'Index out of bounds'. + ENDIF. + +*--------------------------------------------------------------------* +* Build alpha representation of column +*--------------------------------------------------------------------* + WHILE lv_column GT 0. + + lv_module = ( lv_column - 1 ) MOD 26. + lv_uccpi = 65 + lv_module. + + lv_column = ( lv_column - lv_module ) / 26. + + lv_text = cl_abap_conv_in_ce=>uccpi( lv_uccpi ). + CONCATENATE lv_text ep_column INTO ep_column. + + ENDWHILE. + + endmethod. + + + + + + method CONVERT_COLUMN2INT. + +*--------------------------------------------------------------------* +* issue #230 - Pimp my Code +* - Stefan Schmöcker, (done) 2012-12-29 +* - ... +* changes: renaming variables to naming conventions +* removing unused variables +* removing commented out code that is inactive for more then half a year +* message made to support multilinguality +* adding comments to explain what we are trying to achieve +*--------------------------------------------------------------------* +* issue#246 - error converting lower case column names +* - 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 +* adding missing exception if input contains +* illegal characters like german umlauts +*--------------------------------------------------------------------* + + DATA: lv_column TYPE zexcel_cell_column_alpha, + lv_column_c TYPE char10, + lv_column_s TYPE string, + lv_errormessage TYPE string, " Can't pass '...'(abc) to exception-class + lv_modulo TYPE i. + +*--------------------------------------------------------------------* +* This module tries to identify which column a user wants to access +* Numbers as input are just passed back, anything else will be converted +* using EXCEL nomenclatura A = 1, AA = 27, ..., XFD = 16384 +*--------------------------------------------------------------------* + +*--------------------------------------------------------------------* +* Normalize input ( upper case , no gaps ) +*--------------------------------------------------------------------* + lv_column_c = ip_column. +* TRANSLATE lv_column TO UPPER CASE. " Fix #246 + TRANSLATE lv_column_c TO UPPER CASE. " Fix #246 + CONDENSE lv_column_c NO-GAPS. + IF lv_column_c EQ ''. +* lv_errormessage = 'Unable to interpret input as column'(003). +* RAISE EXCEPTION TYPE zcx_excel +* EXPORTING +* error = lv_errormessage. + MESSAGE e800(zabap2xlsx) INTO lv_errormessage. + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + syst_at_raise = syst. + ENDIF. + +*--------------------------------------------------------------------* +* If a number gets passed, just convert it to an integer and return +* the converted value +*--------------------------------------------------------------------* + TRY. + IF lv_column_c CO '1234567890 '. " Fix #164 + ep_column = lv_column_c. " Fix #164 +*--------------------------------------------------------------------* +* Maximum column for EXCEL: XFD = 16384 " if anyone has a reference for this information - please add here instead of this comment +*--------------------------------------------------------------------* + IF ep_column > 16384 OR ep_column < 1. + lv_errormessage = 'Index out of bounds'(004). + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = lv_errormessage. + ENDIF. + EXIT. + ENDIF. + CATCH cx_sy_conversion_no_number. "#EC NO_HANDLER + " Try the character-approach if approach via number has failed + ENDTRY. + +*--------------------------------------------------------------------* +* Raise error if unexpected characters turns up +*--------------------------------------------------------------------* + lv_column_s = lv_column_c. + IF lv_column_s CN sy-abcde. +* lv_errormessage = 'Unable to interpret input as column'(003). +* RAISE EXCEPTION TYPE zcx_excel +* EXPORTING +* error = lv_errormessage. + MESSAGE e800(zabap2xlsx) INTO lv_errormessage. + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + syst_at_raise = syst. + ENDIF. + +*--------------------------------------------------------------------* +* Interpret input as number to base 26 with A=1, ... Z=26 +* Raise error if unexpected character turns up +*--------------------------------------------------------------------* +* 1st character +*--------------------------------------------------------------------* + lv_column = lv_column_c. + lv_modulo = cl_abap_conv_out_ce=>uccpi( lv_column+0(1) ) MOD zcl_excel_common=>c_excel_col_module. + IF lv_modulo < 1 OR lv_modulo > 26. +* lv_errormessage = 'Unable to interpret input as column'(003). +* RAISE EXCEPTION TYPE zcx_excel +* EXPORTING +* error = lv_errormessage. + MESSAGE e800(zabap2xlsx) INTO lv_errormessage. + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + syst_at_raise = syst. + ENDIF. + ep_column = lv_modulo. " Leftmost digit + +*--------------------------------------------------------------------* +* 2nd character if present +*--------------------------------------------------------------------* + CHECK lv_column+1(1) IS NOT INITIAL. " No need to continue if string ended + lv_modulo = cl_abap_conv_out_ce=>uccpi( lv_column+1(1) ) MOD zcl_excel_common=>c_excel_col_module. + IF lv_modulo < 1 OR lv_modulo > 26. +* lv_errormessage = 'Unable to interpret input as column'(003). +* RAISE EXCEPTION TYPE zcx_excel +* EXPORTING +* error = lv_errormessage. + MESSAGE e800(zabap2xlsx) INTO lv_errormessage. + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + syst_at_raise = syst. + ENDIF. + ep_column = 26 * ep_column + lv_modulo. " if second digit is present first digit is for 26^1 + +*--------------------------------------------------------------------* +* 3rd character if present +*--------------------------------------------------------------------* + CHECK lv_column+2(1) IS NOT INITIAL. " No need to continue if string ended + lv_modulo = cl_abap_conv_out_ce=>uccpi( lv_column+2(1) ) MOD zcl_excel_common=>c_excel_col_module. + IF lv_modulo < 1 OR lv_modulo > 26. +* lv_errormessage = 'Unable to interpret input as column'(003). +* RAISE EXCEPTION TYPE zcx_excel +* EXPORTING +* error = lv_errormessage. + MESSAGE e800(zabap2xlsx) INTO lv_errormessage. + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + syst_at_raise = syst. + ENDIF. + ep_column = 26 * ep_column + lv_modulo. " if third digit is present first digit is for 26^2 and second digit for 26^1 + +*--------------------------------------------------------------------* +* Maximum column for EXCEL: XFD = 16384 " if anyone has a reference for this information - please add here instead of this comment +*--------------------------------------------------------------------* + IF ep_column > 16384 OR ep_column < 1. + lv_errormessage = 'Index out of bounds'(004). + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = lv_errormessage. + ENDIF. + + + endmethod. + + + + + + method CONVERT_COLUMNROW2COLUMN_A_ROW. +*--------------------------------------------------------------------* + "issue #256 - replacing char processing with regex +*--------------------------------------------------------------------* +* Stefan Schmöcker, 2013-08-11 +* Allow input to be CLIKE instead of STRING +*--------------------------------------------------------------------* + + DATA: pane_cell_row_a TYPE string, + lv_columnrow type string. + + lv_columnrow = i_columnrow. " Get rid of trailing blanks + + FIND REGEX '^(\D+)(\d+)$' IN lv_columnrow SUBMATCHES e_column + pane_cell_row_a. + e_row = pane_cell_row_a. + + endmethod. + + + + + + + + + + method CONVERT_RANGE2COLUMN_A_ROW. +*--------------------------------------------------------------------* +* issue #230 - Pimp my Code +* - Stefan Schmöcker, (done) 2012-12-07 +* - ... +* changes: renaming variables to naming conventions +* aligning code +* added exceptionclass +* added errorhandling for invalid range +* adding comments to explain what we are trying to achieve +*--------------------------------------------------------------------* +* issue#241 - error when sheetname contains "!" +* - sheetname should be returned unescaped +* - 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 +* changes: i_range changed to clike +* e_sheet changed to clike +*--------------------------------------------------------------------* + + DATA: lv_sheet TYPE string, + lv_range TYPE string, + lv_columnrow_start TYPE string, + lv_columnrow_end TYPE string, + lv_errormessage TYPE string. " Can't pass '...'(abc) to exception-class + + +*--------------------------------------------------------------------* +* Split input range into sheetname and Area +* 4 cases - a) input empty --> nothing to do +* - b) sheetname existing - starts with ' example 'Sheet 1'!$B$6:$D$13 +* - c) sheetname existing - does not start with ' example Sheet1!$B$6:$D$13 +* - d) no sheetname - just area example $B$6:$D$13 +*--------------------------------------------------------------------* +* Initialize output parameters + CLEAR: e_column_start, + e_column_end, + e_row_start, + e_row_end, + e_sheet. + + IF i_range IS INITIAL. " a) input empty --> nothing to do + EXIT. + + ELSEIF i_range(1) = `'`. " b) sheetname existing - starts with ' + FIND REGEX '\![^\!]*$' IN i_range MATCH OFFSET sy-fdpos. " Find last ! + IF sy-subrc = 0. + lv_sheet = i_range(sy-fdpos). + ADD 1 TO sy-fdpos. + lv_range = i_range. + SHIFT lv_range LEFT BY sy-fdpos PLACES. + ELSE. + lv_errormessage = 'Invalid range'(001). + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = lv_errormessage. + ENDIF. + + ELSEIF i_range CS '!'. " c) sheetname existing - does not start with ' + SPLIT i_range AT '!' INTO lv_sheet lv_range. + + ELSE. " d) no sheetname - just area + lv_range = i_range. + ENDIF. + + REPLACE ALL OCCURRENCES OF '$' IN lv_range WITH ''. + SPLIT lv_range AT ':' INTO lv_columnrow_start lv_columnrow_end. + + convert_columnrow2column_a_row( EXPORTING + i_columnrow = lv_columnrow_start + IMPORTING + e_column = e_column_start + e_row = e_row_start ). + convert_columnrow2column_a_row( EXPORTING + i_columnrow = lv_columnrow_end + IMPORTING + e_column = e_column_end + e_row = e_row_end ). + + e_sheet = unescape_string( lv_sheet ). " Return in unescaped form + endmethod. + + + + + method DATE_TO_EXCEL_STRING. + DATA: lv_date_diff TYPE i. + + CHECK ip_value IS NOT INITIAL. + " Needed hack caused by the problem that: + " Excel 2000 incorrectly assumes that the year 1900 is a leap year + " http://support.microsoft.com/kb/214326/en-us + IF ip_value > c_excel_1900_leap_year. + lv_date_diff = ip_value - c_excel_baseline_date + 2. + ELSE. + 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. + + + + + method DESCRIBE_STRUCTURE. + DATA: lt_components TYPE abap_component_tab, + lt_comps TYPE abap_component_tab, + lo_struct TYPE REF TO cl_abap_structdescr, + ls_component TYPE abap_componentdescr, + lo_elemdescr TYPE REF TO cl_abap_elemdescr, + ls_dfies TYPE dfies, + l_position TYPE tabfdpos. + + "for DDIC structure get the info directly + IF io_struct->is_ddic_type( ) = abap_true. + rt_dfies = io_struct->get_ddic_field_list( ). + ELSE. + lt_components = io_struct->get_components( ). + + LOOP AT lt_components INTO ls_component. + structure_case( EXPORTING is_component = ls_component + CHANGING xt_components = lt_comps ) . + ENDLOOP. + LOOP AT lt_comps INTO ls_component. + CLEAR ls_dfies. + IF ls_component-type->kind = cl_abap_typedescr=>kind_elem. "E Elementary Type + ADD 1 TO l_position. + lo_elemdescr ?= ls_component-type. + IF lo_elemdescr->is_ddic_type( ) = abap_true. + ls_dfies = lo_elemdescr->get_ddic_field( ). + ls_dfies-fieldname = ls_component-name. + ls_dfies-position = l_position. + ELSE. + ls_dfies-fieldname = ls_component-name. + ls_dfies-position = l_position. + ls_dfies-inttype = lo_elemdescr->type_kind. + ls_dfies-leng = lo_elemdescr->length. + ls_dfies-outputlen = lo_elemdescr->length. + ls_dfies-decimals = lo_elemdescr->decimals. + ls_dfies-fieldtext = ls_component-name. + ls_dfies-reptext = ls_component-name. + ls_dfies-scrtext_s = ls_component-name. + ls_dfies-scrtext_m = ls_component-name. + ls_dfies-scrtext_l = ls_component-name. + ls_dfies-dynpfld = abap_true. + ENDIF. + INSERT ls_dfies INTO TABLE rt_dfies. + ENDIF. + ENDLOOP. + ENDIF. + endmethod. + + + method DESCRIBE_TABLE. + endmethod. + + + + + + + + method DETERMINE_RESULTING_FORMULA. + + DATA: lv_row_difference TYPE i, + lv_col_difference TYPE i. + +*--------------------------------------------------------------------* +* Calculate distance of reference and current cell +*--------------------------------------------------------------------* + calculate_cell_distance( EXPORTING + iv_reference_cell = iv_reference_cell + iv_current_cell = iv_current_cell + IMPORTING + ev_row_difference = lv_row_difference + ev_col_difference = lv_col_difference ). + +*--------------------------------------------------------------------* +* and shift formula by using the row- and columndistance +*--------------------------------------------------------------------* + ev_resulting_formula = shift_formula( iv_reference_formula = iv_reference_formula + iv_shift_rows = lv_row_difference + iv_shift_cols = lv_col_difference ). + + endmethod. + + + + + method ENCRYPT_PASSWORD. + + DATA lv_curr_offset TYPE i. + DATA lv_curr_char TYPE c LENGTH 1. + DATA lv_curr_hex TYPE zexcel_pwd_hash. + DATA lv_pwd_len TYPE zexcel_pwd_hash. + DATA lv_pwd_hash TYPE zexcel_pwd_hash. + + CONSTANTS: + lv_0x7fff TYPE zexcel_pwd_hash VALUE '7FFF', + lv_0x0001 TYPE zexcel_pwd_hash VALUE '0001', + lv_0xce4b TYPE zexcel_pwd_hash VALUE 'CE4B'. + + DATA lv_pwd TYPE zexcel_aes_password. + + lv_pwd = i_pwd(15). + + lv_pwd_len = STRLEN( lv_pwd ). + lv_curr_offset = lv_pwd_len - 1. + + WHILE lv_curr_offset GE 0. + + lv_curr_char = lv_pwd+lv_curr_offset(1). + lv_curr_hex = char2hex( lv_curr_char ). + + lv_pwd_hash = ( shr14( lv_pwd_hash ) BIT-AND lv_0x0001 ) BIT-OR ( shl01( lv_pwd_hash ) BIT-AND lv_0x7fff ). + + lv_pwd_hash = lv_pwd_hash BIT-XOR lv_curr_hex. + SUBTRACT 1 FROM lv_curr_offset. + ENDWHILE. + + lv_pwd_hash = ( shr14( lv_pwd_hash ) BIT-AND lv_0x0001 ) BIT-OR ( shl01( lv_pwd_hash ) BIT-AND lv_0x7fff ). + lv_pwd_hash = lv_pwd_hash BIT-XOR lv_0xce4b. + lv_pwd_hash = lv_pwd_hash BIT-XOR lv_pwd_len. + + WRITE lv_pwd_hash TO r_encrypted_pwd. + + endmethod. + + + + + method ESCAPE_STRING. +*--------------------------------------------------------------------* +* issue #230 - Pimp my Code +* - 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 +* 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 +* changes: ip_value changed to clike +*--------------------------------------------------------------------* + DATA: lv_value TYPE string. + +*--------------------------------------------------------------------* +* There exist various situations when a space will be used to separate +* different parts of a string. When we have a string consisting spaces +* that will cause errors unless we "escape" the string by putting ' at +* the beginning and at the end of the string. +*--------------------------------------------------------------------* + + +*--------------------------------------------------------------------* +* When allowing clike-input parameters we might encounter trailing +* "real" blanks . These are automatically eliminated when moving +* the input parameter to a string. +* Now any remaining spaces ( white-spaces or normal spaces ) should +* trigger the escaping as well as any ' +*--------------------------------------------------------------------* + lv_value = ip_value. + + + FIND REGEX `\s|'` IN lv_value. " \s finds regular and white spaces + IF sy-subrc = 0. + REPLACE ALL OCCURRENCES OF `'` IN lv_value WITH `''`. + CONCATENATE `'` lv_value `'` INTO lv_value . + ENDIF. + + ep_escaped_value = lv_value. + + endmethod. + + + + + + method EXCEL_STRING_TO_DATE. + DATA: lv_date_int TYPE i. + + TRY. + lv_date_int = ip_value. + ep_value = lv_date_int + c_excel_baseline_date - 2. + " Needed hack caused by the problem that: + " Excel 2000 incorrectly assumes that the year 1900 is a leap year + " http://support.microsoft.com/kb/214326/en-us + IF ep_value < c_excel_1900_leap_year. + ep_value = ep_value + 1. + ENDIF. + CATCH cx_sy_conversion_error. + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = 'Index out of bounds'. + ENDTRY. + endmethod. + + + + + + method EXCEL_STRING_TO_TIME. + DATA: lv_seconds_in_day TYPE i, + lv_day_fraction TYPE f, + lc_seconds_in_day TYPE i VALUE 86400. + + TRY. + + lv_day_fraction = ip_value. + lv_seconds_in_day = lv_day_fraction * lc_seconds_in_day. + + ep_value = lv_seconds_in_day. + + CATCH cx_sy_conversion_error. + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = 'Unable to interpret time'. + ENDTRY. + endmethod. + + + + + + + method FAIL. + DATA: ls_seoclass TYPE seoclass. + + " Let see >=7.02 + SELECT SINGLE * INTO ls_seoclass + FROM seoclass + WHERE clsname = 'CL_ABAP_UNIT_ASSERT'. + + IF sy-subrc = 0. + CALL METHOD (ls_seoclass-clsname)=>fail + EXPORTING + msg = msg + level = level + quit = quit + detail = detail. + ELSE. + " Let see >=7.00 or even lower + SELECT SINGLE * INTO ls_seoclass + FROM seoclass + WHERE clsname = 'CL_AUNIT_ASSERT'. + + IF sy-subrc = 0. + CALL METHOD (ls_seoclass-clsname)=>fail + EXPORTING + msg = msg + level = level + quit = quit + detail = detail. + ELSE. +* We do nothing for now not supported + ENDIF. + ENDIF. + + endmethod. + + + + + method GET_FIELDCATALOG. + DATA: lr_dref_tab TYPE REF TO data, + lo_salv_table TYPE REF TO cl_salv_table, + lo_salv_columns_table TYPE REF TO cl_salv_columns_table, + lt_salv_t_column_ref TYPE salv_t_column_ref, + ls_salv_t_column_ref LIKE LINE OF lt_salv_t_column_ref, + lo_salv_column_table TYPE REF TO cl_salv_column_table. + + FIELD-SYMBOLS: <tab> TYPE STANDARD TABLE. + FIELD-SYMBOLS: <fcat> LIKE LINE OF ep_fieldcatalog. + +* Get copy of IP_TABLE-structure <-- must be changeable to create salv + CREATE DATA lr_dref_tab LIKE ip_table. + ASSIGN lr_dref_tab->* TO <tab>. +* Create salv --> implicitly create fieldcat + TRY. + cl_salv_table=>factory( IMPORTING + r_salv_table = lo_salv_table + CHANGING + t_table = <tab> ). + lo_salv_columns_table = lo_salv_table->get_columns( ). + lt_salv_t_column_ref = lo_salv_columns_table->get( ). + CATCH cx_root. +* maybe some errorhandling here - just haven't made up my mind yet + ENDTRY. + +* Loop through columns and set relevant fields ( fieldname, texts ) + LOOP AT lt_salv_t_column_ref INTO ls_salv_t_column_ref. + + lo_salv_column_table ?= ls_salv_t_column_ref-r_column. + APPEND INITIAL LINE TO ep_fieldcatalog ASSIGNING <fcat>. + <fcat>-position = sy-tabix. + <fcat>-fieldname = ls_salv_t_column_ref-columnname. + <fcat>-scrtext_s = ls_salv_t_column_ref-r_column->get_short_text( ). + <fcat>-scrtext_m = ls_salv_t_column_ref-r_column->get_medium_text( ). + <fcat>-scrtext_l = ls_salv_t_column_ref-r_column->get_long_text( ). + + <fcat>-dynpfld = 'X'. " What in the world would we exclude here? + IF <fcat>-position = 1. " except for the MANDT-field of most tables ( 1st column that is ) + IF lo_salv_column_table->get_ddic_datatype( ) = 'CLNT'. + CLEAR <fcat>-dynpfld. + ENDIF. + ENDIF. + +* For fields that don't a description ( i.e. defined by "field type i," ) +* just use the fieldname as description - that is better than nothing + IF <fcat>-scrtext_s IS INITIAL + AND <fcat>-scrtext_m IS INITIAL + AND <fcat>-scrtext_l IS INITIAL. + CONCATENATE 'Col:' <fcat>-fieldname INTO <fcat>-scrtext_l SEPARATED BY space. + <fcat>-scrtext_m = <fcat>-scrtext_l. + <fcat>-scrtext_s = <fcat>-scrtext_l. + ENDIF. + + ENDLOOP. + + endmethod. + + + + + method NUMBER_TO_EXCEL_STRING. + DATA: lv_value_c TYPE c LENGTH 100. + + WRITE ip_value TO lv_value_c EXPONENT 0 NO-GROUPING NO-SIGN. + REPLACE ALL OCCURRENCES OF ',' IN lv_value_c WITH '.'. + + ep_value = lv_value_c. + CONDENSE ep_value. + + IF ip_value < 0. + CONCATENATE '-' ep_value INTO ep_value. + ELSEIF ip_value EQ 0. + ep_value = '0'. + ENDIF. + endmethod. + + + + + + method RECURSIVE_CLASS_TO_STRUCT. + " # issue 139 +* is working for me - but after looking through this coding I guess +* I'll rewrite this to a version w/o recursion +* This is private an no one using it so far except me, so no need to hurry + DATA: descr TYPE REF TO cl_abap_structdescr, + wa_component LIKE LINE OF descr->components, + attribute_name TYPE fieldname, + flag_class TYPE flag, + o_border TYPE REF TO zcl_excel_style_border. + + FIELD-SYMBOLS: <field> TYPE any, + <fieldx> TYPE any, + <class> TYPE REF TO object, + <attribute> TYPE any. + + + descr ?= cl_abap_structdescr=>describe_by_data( e_target ). + + LOOP AT descr->components INTO wa_component. + +* Assign structure and X-structure + ASSIGN COMPONENT wa_component-name OF STRUCTURE e_target TO <field>. + ASSIGN COMPONENT wa_component-name OF STRUCTURE e_targetx TO <fieldx>. +* At least one field in the structure should be marked - otherwise continue with next field + CLEAR flag_class. +* maybe source is just a structure - try assign component... + ASSIGN COMPONENT wa_component-name OF STRUCTURE i_source TO <attribute>. + IF sy-subrc <> 0. +* not - then it is an attribute of the class - use different assign then + CONCATENATE 'i_source->' wa_component-name INTO attribute_name. + ASSIGN (attribute_name) TO <attribute>. + IF sy-subrc <> 0. + EXIT. + ENDIF. " Should not happen if structure is built properly - otherwise just exit to create no dumps + flag_class = abap_true. + ENDIF. + + CASE wa_component-type_kind. + WHEN cl_abap_structdescr=>typekind_struct1 OR cl_abap_structdescr=>typekind_struct2. " Structure --> use recursio +* IF flag_class = abap_true. +** Only borders will be passed as unbound references. But since we want to set a value we have to create an instance +* ENDIF. + zcl_excel_common=>recursive_class_to_struct( EXPORTING i_source = <attribute> + CHANGING e_target = <field> + e_targetx = <fieldx> ). + WHEN OTHERS. + <field> = <attribute>. + <fieldx> = abap_true. + + ENDCASE. + ENDLOOP. + + endmethod. + + + + + + method RECURSIVE_STRUCT_TO_CLASS. + " # issue 139 +* is working for me - but after looking through this coding I guess +* I'll rewrite this to a version w/o recursion +* This is private an no one using it so far except me, so no need to hurry + DATA: descr TYPE REF TO cl_abap_structdescr, + wa_component LIKE LINE OF descr->components, + attribute_name TYPE fieldname, + flag_class TYPE flag, + o_border TYPE REF TO zcl_excel_style_border. + + FIELD-SYMBOLS: <field> TYPE any, + <fieldx> TYPE any, + <class> TYPE REF TO object, + <attribute> TYPE any, + <attribute_s> TYPE ANY TABLE. + + + descr ?= cl_abap_structdescr=>describe_by_data( i_source ). + + LOOP AT descr->components INTO wa_component. + +* Assign structure and X-structure + ASSIGN COMPONENT wa_component-name OF STRUCTURE i_source TO <field>. + ASSIGN COMPONENT wa_component-name OF STRUCTURE i_sourcex TO <fieldx>. +* At least one field in the structure should be marked - otherwise continue with next field + CHECK <fieldx> CA abap_true. + CLEAR flag_class. +* maybe target is just a structure - try assign component... + ASSIGN COMPONENT wa_component-name OF STRUCTURE e_target TO <attribute>. + IF sy-subrc <> 0. +* not - then it is an attribute of the class - use different assign then + CONCATENATE 'E_TARGET->' wa_component-name INTO attribute_name. + ASSIGN (attribute_name) TO <attribute>. + IF sy-subrc <> 0.EXIT.ENDIF. " Should not happen if structure is built properly - otherwise just exit to create no dumps + flag_class = abap_true. + ENDIF. + + CASE wa_component-type_kind. + WHEN cl_abap_structdescr=>typekind_struct1 OR cl_abap_structdescr=>typekind_struct2. " Structure --> use recursion + IF flag_class = abap_true AND <attribute> IS INITIAL. +* Only borders will be passed as unbound references. But since we want to set a value we have to create an instance + CREATE OBJECT o_border. + <attribute> = o_border. + ENDIF. + zcl_excel_common=>recursive_struct_to_class( EXPORTING i_source = <field> + i_sourcex = <fieldx> + CHANGING e_target = <attribute> ). +* WHEN cl_abap_structdescr=>typekind_struct2. " String +* CHECK <fieldx> = abap_true. " Marked for change +* <attribute_s> = <field>. + WHEN OTHERS. + CHECK <fieldx> = abap_true. " Marked for change + <attribute> = <field>. + + ENDCASE. + ENDLOOP. + + endmethod. + + + + + + + + method SHIFT_FORMULA. + + CONSTANTS: lcv_operators TYPE string VALUE '+-/*^%=<>&, !', + lcv_letters TYPE string VALUE 'ABCDEFGHIJKLMNOPQRSTUVWXYZ$', + lcv_digits TYPE string VALUE '0123456789', + lcv_cell_reference_error TYPE string VALUE '#REF!'. + + DATA: lv_tcnt TYPE i, " Counter variable + lv_tlen TYPE i, " Temp variable length + lv_cnt TYPE i, " Counter variable + lv_cnt2 TYPE i, " Counter variable + lv_offset1 TYPE i, " Character offset + lv_numchars TYPE i, " Number of characters counter + lv_tchar(1) TYPE c, " Temp character + lv_tchar2(1) TYPE c, " Temp character + lv_cur_form(132) TYPE c, " Formula for current cell + lv_ref_cell_addr TYPE string, " Reference cell address + lv_tcol1 TYPE string, " Temp column letter + lv_tcol2 TYPE string, " Temp column letter + lv_tcoln TYPE i, " Temp column number + lv_trow1 TYPE string, " Temp row number + lv_trow2 TYPE string, " Temp row number + lv_flen TYPE i, " Length of reference formula + lv_tlen2 TYPE i, " Temp variable length + lv_substr1 TYPE string, " Substring variable + lv_abscol TYPE string, " Absolute column symbol + lv_absrow TYPE string, " Absolute row symbol + + lv_errormessage TYPE string. + + FIELD-SYMBOLS: <find_my_include> TYPE ANY. + +*--------------------------------------------------------------------* +* When copying a cell in EXCEL to another cell any inherent formulas +* 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 +*--------------------------------------------------------------------* + +*--------------------------------------------------------------------* +* No distance --> Reference = resulting cell/formula +*--------------------------------------------------------------------* + IF iv_shift_cols = 0 + AND iv_shift_rows = 0. + ev_resulting_formula = iv_reference_formula. + EXIT. " done + ENDIF. + + + lv_flen = STRLEN( iv_reference_formula ). + lv_numchars = 1. + +*--------------------------------------------------------------------* +* §1 Parse reference formula character by character +*--------------------------------------------------------------------* + DO lv_flen TIMES. + + CLEAR: lv_tchar, + lv_substr1, + lv_ref_cell_addr. + lv_cnt2 = lv_cnt + 1. + IF lv_cnt2 > lv_flen. + EXIT. " Done + ENDIF. + +*--------------------------------------------------------------------* +* Here we have the current character in the formula +*--------------------------------------------------------------------* + lv_tchar = iv_reference_formula+lv_cnt(1). + +*--------------------------------------------------------------------* +* Operators or opening parenthesis will separate possible cellreferences +*--------------------------------------------------------------------* + IF ( lv_tchar CA lcv_operators + OR lv_tchar CA '(' ) + AND lv_cnt2 = 1. + lv_substr1 = iv_reference_formula+lv_offset1(1). + CONCATENATE lv_cur_form lv_substr1 INTO lv_cur_form. + lv_cnt = lv_cnt + 1. + lv_offset1 = lv_cnt. + lv_numchars = 1. + CONTINUE. " --> next character in formula can be analyzed + ENDIF. + +*--------------------------------------------------------------------* +* Quoted literal text holds no cell reference --> advance to end of text +*--------------------------------------------------------------------* + IF lv_tchar EQ '"'. + lv_cnt = lv_cnt + 1. + lv_numchars = lv_numchars + 1. + lv_tchar = iv_reference_formula+lv_cnt(1). + WHILE lv_tchar NE '"'. + + lv_cnt = lv_cnt + 1. + lv_numchars = lv_numchars + 1. + lv_tchar = iv_reference_formula+lv_cnt(1). + + ENDWHILE. + lv_cnt2 = lv_cnt + 1. + lv_substr1 = iv_reference_formula+lv_offset1(lv_numchars). + CONCATENATE lv_cur_form lv_substr1 INTO lv_cur_form. + lv_cnt = lv_cnt + 1. + IF lv_cnt = lv_flen. + EXIT. + ENDIF. + lv_offset1 = lv_cnt. + lv_numchars = 1. + lv_tchar = iv_reference_formula+lv_cnt(1). + lv_cnt2 = lv_cnt + 1. + CONTINUE. " --> next character in formula can be analyzed + ENDIF. + + +*--------------------------------------------------------------------* +* Operators or parenthesis or last character in formula will separate possible cellreferences +*--------------------------------------------------------------------* + IF lv_tchar CA lcv_operators + OR lv_tchar CA '():' + OR lv_cnt2 = lv_flen. + IF lv_cnt > 0. + lv_substr1 = iv_reference_formula+lv_offset1(lv_numchars). +*--------------------------------------------------------------------* +* Check for text concatenation and functions +*--------------------------------------------------------------------* + IF ( lv_tchar CA lcv_operators AND lv_tchar EQ lv_substr1 ) OR lv_tchar EQ '('. + CONCATENATE lv_cur_form lv_substr1 INTO lv_cur_form. + lv_cnt = lv_cnt + 1. + lv_offset1 = lv_cnt. + lv_cnt2 = lv_cnt + 1. + lv_numchars = 1. + CONTINUE. " --> next character in formula can be analyzed + ENDIF. + + lv_tlen = lv_cnt2 - lv_offset1. +*--------------------------------------------------------------------* +* Exclude mathematical operators and closing parentheses +*--------------------------------------------------------------------* + IF lv_tchar CA lcv_operators + OR lv_tchar CA ':)'. + IF lv_cnt2 = lv_flen + AND lv_numchars = 1. + CONCATENATE lv_cur_form lv_substr1 INTO lv_cur_form. + lv_cnt = lv_cnt + 1. + lv_offset1 = lv_cnt. + lv_cnt2 = lv_cnt + 1. + lv_numchars = 1. + CONTINUE. " --> next character in formula can be analyzed + ELSE. + lv_tlen = lv_tlen - 1. + ENDIF. + ENDIF. +*--------------------------------------------------------------------* +* Capture reference cell address +*--------------------------------------------------------------------* + TRY. + MOVE: iv_reference_formula+lv_offset1(lv_tlen) TO lv_ref_cell_addr. "Ref cell address + CATCH cx_root. + lv_errormessage = 'Internal error in Class ZCL_EXCEL_COMMON Method SHIFT_FORMULA Spot 1 '. " Change to messageclass if possible + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = lv_errormessage. + ENDTRY. + +*--------------------------------------------------------------------* +* Split cell address into characters and numbers +*--------------------------------------------------------------------* + CLEAR: lv_tlen, + lv_tcnt, + lv_tcol1, + lv_trow1. + lv_tlen = STRLEN( lv_ref_cell_addr ). + IF lv_tlen <> 0. + CLEAR: lv_tcnt. + DO lv_tlen TIMES. + CLEAR: lv_tchar2. + lv_tchar2 = lv_ref_cell_addr+lv_tcnt(1). + IF lv_tchar2 CA lcv_letters. + CONCATENATE lv_tcol1 lv_tchar2 INTO lv_tcol1. + ELSEIF lv_tchar2 CA lcv_digits. + CONCATENATE lv_trow1 lv_tchar2 INTO lv_trow1. + ENDIF. + lv_tcnt = lv_tcnt + 1. + ENDDO. + ENDIF. +*--------------------------------------------------------------------* +* Check for invalid cell address +*--------------------------------------------------------------------* + IF lv_tcol1 IS INITIAL OR lv_trow1 IS INITIAL. + CONCATENATE lv_cur_form lv_substr1 INTO lv_cur_form. + lv_cnt = lv_cnt + 1. + lv_offset1 = lv_cnt. + lv_cnt2 = lv_cnt + 1. + lv_numchars = 1. + CONTINUE. + ENDIF. +*--------------------------------------------------------------------* +* Check for range names +*--------------------------------------------------------------------* + CLEAR: lv_tlen. + lv_tlen = STRLEN( lv_tcol1 ). + IF lv_tlen GT 3. + CONCATENATE lv_cur_form lv_substr1 INTO lv_cur_form. + lv_cnt = lv_cnt + 1. + lv_offset1 = lv_cnt. + lv_cnt2 = lv_cnt + 1. + lv_numchars = 1. + CONTINUE. + ENDIF. +*--------------------------------------------------------------------* +* Check for valid row +*--------------------------------------------------------------------* + IF lv_trow1 GT 1048576. + CONCATENATE lv_cur_form lv_substr1 INTO lv_cur_form. + lv_cnt = lv_cnt + 1. + lv_offset1 = lv_cnt. + lv_cnt2 = lv_cnt + 1. + lv_numchars = 1. + CONTINUE. + ENDIF. +*--------------------------------------------------------------------* +* Check for absolute column or row reference +*--------------------------------------------------------------------* + CLEAR: lv_tcol2, + lv_trow2, + lv_abscol, + lv_absrow. + lv_tlen2 = STRLEN( lv_tcol1 ) - 1. + IF lv_tcol1 IS NOT INITIAL. + lv_abscol = lv_tcol1(1). + ENDIF. + IF lv_tlen2 GE 0. + lv_absrow = lv_tcol1+lv_tlen2(1). + ENDIF. + IF lv_abscol EQ '$' AND lv_absrow EQ '$'. + lv_tlen2 = lv_tlen2 - 1. + IF lv_tlen2 > 0. + lv_tcol1 = lv_tcol1+1(lv_tlen2). + ENDIF. + lv_tlen2 = lv_tlen2 + 1. + ELSEIF lv_abscol EQ '$'. + lv_tcol1 = lv_tcol1+1(lv_tlen2). + ELSEIF lv_absrow EQ '$'. + lv_tcol1 = lv_tcol1(lv_tlen2). + ENDIF. +*--------------------------------------------------------------------* +* Check for valid column +*--------------------------------------------------------------------* + TRY. + lv_tcoln = zcl_excel_common=>convert_column2int( lv_tcol1 ) + iv_shift_cols. + CATCH zcx_excel. + CONCATENATE lv_cur_form lv_substr1 INTO lv_cur_form. + lv_cnt = lv_cnt + 1. + lv_offset1 = lv_cnt. + lv_cnt2 = lv_cnt + 1. + lv_numchars = 1. + CONTINUE. + ENDTRY. +*--------------------------------------------------------------------* +* Check whether there is a referencing problem +*--------------------------------------------------------------------* + lv_trow2 = lv_trow1 + iv_shift_rows. + IF ( lv_tcoln < 1 AND lv_abscol <> '$' ) " Maybe we should add here max-column and max row-tests as well. + OR ( lv_trow2 < 1 AND lv_absrow <> '$' ). " Check how EXCEL behaves in this case +*--------------------------------------------------------------------* +* Referencing problem encountered --> set error +*--------------------------------------------------------------------* + CONCATENATE lv_cur_form lcv_cell_reference_error INTO lv_cur_form. + ELSE. +*--------------------------------------------------------------------* +* No referencing problems --> adjust row and column +*--------------------------------------------------------------------* + +*--------------------------------------------------------------------* +* Adjust column +*--------------------------------------------------------------------* + IF lv_abscol EQ '$'. + CONCATENATE lv_cur_form lv_abscol lv_tcol1 INTO lv_cur_form. + ELSEIF iv_shift_cols EQ 0. + CONCATENATE lv_cur_form lv_tcol1 INTO lv_cur_form. + ELSE. + TRY. + lv_tcol2 = zcl_excel_common=>convert_column2alpha( lv_tcoln ). + CONCATENATE lv_cur_form lv_tcol2 INTO lv_cur_form. + CATCH zcx_excel. + CONCATENATE lv_cur_form lv_substr1 INTO lv_cur_form. + lv_cnt = lv_cnt + 1. + lv_offset1 = lv_cnt. + lv_cnt2 = lv_cnt + 1. + lv_numchars = 1. + CONTINUE. + ENDTRY. + ENDIF. +*--------------------------------------------------------------------* +* Adjust row +*--------------------------------------------------------------------* + IF lv_absrow EQ '$'. + CONCATENATE lv_cur_form lv_absrow lv_trow1 INTO lv_cur_form. + ELSEIF iv_shift_rows = 0. + CONCATENATE lv_cur_form lv_trow1 INTO lv_cur_form. +* elseif lv_trow2 < 1. +* CONCATENATE lv_cur_form lc_cell_reference_error INTO lv_cur_form. + ELSE. + CONCATENATE lv_cur_form lv_trow2 INTO lv_cur_form. + ENDIF. + ENDIF. + + lv_numchars = 0. + IF lv_tchar CA lcv_operators + OR lv_tchar CA ':)'. + CONCATENATE lv_cur_form lv_tchar INTO lv_cur_form. + ENDIF. + lv_offset1 = lv_cnt2. + ENDIF. + ENDIF. + lv_numchars = lv_numchars + 1. + lv_cnt = lv_cnt + 1. + lv_cnt2 = lv_cnt + 1. + + ENDDO. + + + +*--------------------------------------------------------------------* +* Return resulting formula +*--------------------------------------------------------------------* + IF lv_cur_form IS NOT INITIAL. + MOVE lv_cur_form TO ev_resulting_formula. + ENDIF. + + endmethod. + + + + + method SHL01. + + DATA: + lv_bit TYPE i, + lv_curr_pos TYPE i VALUE 2, + lv_prev_pos TYPE i VALUE 1. + + DO 15 TIMES. + GET BIT lv_curr_pos OF i_pwd_hash INTO lv_bit. + SET BIT lv_prev_pos OF r_pwd_hash TO lv_bit. + ADD 1 TO lv_curr_pos. + ADD 1 TO lv_prev_pos. + ENDDO. + SET BIT 16 OF r_pwd_hash TO 0. + + endmethod. + + + + + method SHR14. + + DATA: + lv_bit TYPE i, + lv_curr_pos TYPE i, + lv_next_pos TYPE i. + + r_pwd_hash = i_pwd_hash. + + DO 14 TIMES. + lv_curr_pos = 15. + lv_next_pos = 16. + + DO 15 TIMES. + GET BIT lv_curr_pos OF r_pwd_hash INTO lv_bit. + SET BIT lv_next_pos OF r_pwd_hash TO lv_bit. + SUBTRACT 1 FROM lv_curr_pos. + SUBTRACT 1 FROM lv_next_pos. + ENDDO. + SET BIT 1 OF r_pwd_hash TO 0. + ENDDO. + + endmethod. + + + + + + + method SPLIT_FILE. + + DATA: lt_hlp TYPE TABLE OF text255, + ls_hlp TYPE text255. + + DATA: lf_ext(10) TYPE c, + lf_dot_ext(10) TYPE c. + DATA: lf_str TYPE text255, + lf_anz TYPE i, + lf_len TYPE i. +** --------------------------------------------------------------------- + + CLEAR: lt_hlp, + ep_file, + ep_extension, + ep_dotextension. + +** Split the whole file at '.' + SPLIT ip_file AT '.' INTO TABLE lt_hlp. + +** get the extenstion from the last line of table + DESCRIBE TABLE lt_hlp LINES lf_anz. + IF lf_anz <= 1. + ep_file = ip_file. + EXIT. + ENDIF. + + READ TABLE lt_hlp INTO ls_hlp INDEX lf_anz. + ep_extension = ls_hlp. + lf_ext = ls_hlp. + IF NOT lf_ext IS INITIAL. + CONCATENATE '.' lf_ext INTO lf_dot_ext. + ENDIF. + ep_dotextension = lf_dot_ext. + +** get only the filename + lf_len = strlen( ip_file ) - strlen( lf_dot_ext ). + IF lf_len > 0. + ep_file = ip_file(lf_len). + ENDIF. + + endmethod. + + + + + method STRUCTURE_CASE. + DATA: lt_comp_str TYPE abap_component_tab. + + CASE is_component-type->kind. + WHEN cl_abap_typedescr=>kind_elem. "E Elementary Type + INSERT is_component INTO TABLE xt_components. + WHEN cl_abap_typedescr=>kind_table. "T Table + INSERT is_component INTO TABLE xt_components. + WHEN cl_abap_typedescr=>kind_struct. "S Structure + lt_comp_str = structure_recursive( is_component = is_component ). + INSERT LINES OF lt_comp_str INTO TABLE xt_components. + 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. + + + + + method STRUCTURE_RECURSIVE. + DATA: lo_struct TYPE REF TO cl_abap_structdescr, + lt_components TYPE abap_component_tab, + ls_components TYPE abap_componentdescr. + + REFRESH rt_components. + + lo_struct ?= is_component-type. + lt_components = lo_struct->get_components( ). + + LOOP AT lt_components INTO ls_components. + structure_case( EXPORTING is_component = ls_components + CHANGING xt_components = rt_components ) . + ENDLOOP. + + endmethod. + + + + + method TIME_TO_EXCEL_STRING. + DATA: lv_seconds_in_day TYPE i, + lv_day_fraction TYPE f, + lc_time_baseline TYPE t VALUE '000000', + lc_seconds_in_day TYPE i VALUE 86400. + + 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. + + + + + + method UNESCAPE_STRING. + + CONSTANTS lcv_regex TYPE string VALUE `^'[^']` & `|` & " Beginning single ' OR + `[^']'$` & `|` & " Trailing single ' OR + `[^']'[^']`. " Single ' somewhere in between + + + DATA: lv_errormessage TYPE string. " Can't pass '...'(abc) to exception-class + +*--------------------------------------------------------------------* +* This method is used to extract the "real" string from an escaped string. +* An escaped string can be identified by a beginning ' which must be +* accompanied by a trailing ' +* All '' in between beginning and trailing ' are treated as single ' +*--------------------------------------------------------------------* + +*--------------------------------------------------------------------* +* When allowing clike-input parameters we might encounter trailing +* "real" blanks . These are automatically eliminated when moving +* the input parameter to a string. +*--------------------------------------------------------------------* + ev_unescaped_string = iv_escaped. " Pass through if not escaped + + CHECK ev_unescaped_string IS NOT INITIAL. " Nothing to do if empty + CHECK ev_unescaped_string(1) = `'`. " Nothing to do if not escaped + +*--------------------------------------------------------------------* +* Remove leading and trailing ' +*--------------------------------------------------------------------* + REPLACE REGEX `^'(.*)'$` IN ev_unescaped_string WITH '$1'. + IF sy-subrc <> 0. + lv_errormessage = 'Input not properly escaped - &'(002). + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = lv_errormessage. + ENDIF. + +*--------------------------------------------------------------------* +* Any remaining single ' should not be here +*--------------------------------------------------------------------* + FIND REGEX lcv_regex IN ev_unescaped_string. + IF sy-subrc = 0. + lv_errormessage = 'Input not properly escaped - &'(002). + RAISE EXCEPTION TYPE zcx_excel + EXPORTING + error = lv_errormessage. + ENDIF. + +*--------------------------------------------------------------------* +* Replace '' with ' +*--------------------------------------------------------------------* + REPLACE ALL OCCURRENCES OF `''` IN ev_unescaped_string WITH `'`. + + + 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 +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_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 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_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 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. + + + + *"* 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. + + + + *"* 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 + + + *"* 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. + + + + + + + + *"* 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 CONSTRUCTOR. + "Load default values + me->pagemargins-b = '0.75'. + me->pagemargins-l = '0.7'. + me->pagemargins-r = '0.7'. + me->pagemargins-t = '0.75'. + me->pagemargins-header = '0.3'. + me->pagemargins-footer = '0.3'. + endmethod. + + + + + + + + + + + + + + + + + + + + method CREATE_SERIE. + DATA ls_serie TYPE s_series. + + DATA: lv_start_row_c TYPE char7, + lv_stop_row_c TYPE char7. + + + IF ip_lbl IS NOT SUPPLIED. + lv_stop_row_c = ip_lbl_to_row. + SHIFT lv_stop_row_c RIGHT DELETING TRAILING space. + SHIFT lv_stop_row_c LEFT DELETING LEADING space. + lv_start_row_c = ip_lbl_from_row. + SHIFT lv_start_row_c RIGHT DELETING TRAILING space. + SHIFT lv_start_row_c LEFT DELETING LEADING space. + ls_serie-lbl = ip_sheet. + ls_serie-lbl = zcl_excel_common=>escape_string( ip_value = ls_serie-lbl ). + CONCATENATE ls_serie-lbl '!$' ip_lbl_from_col '$' lv_start_row_c ':$' ip_lbl_to_col '$' lv_stop_row_c INTO ls_serie-lbl. + CLEAR: lv_start_row_c, lv_stop_row_c. + ELSE. + ls_serie-lbl = ip_lbl. + ENDIF. + IF ip_ref IS NOT SUPPLIED. + lv_stop_row_c = ip_ref_to_row. + SHIFT lv_stop_row_c RIGHT DELETING TRAILING space. + SHIFT lv_stop_row_c LEFT DELETING LEADING space. + lv_start_row_c = ip_ref_from_row. + SHIFT lv_start_row_c RIGHT DELETING TRAILING space. + SHIFT lv_start_row_c LEFT DELETING LEADING space. + ls_serie-ref = ip_sheet. + ls_serie-ref = zcl_excel_common=>escape_string( ip_value = ls_serie-ref ). + CONCATENATE ls_serie-ref '!$' ip_ref_from_col '$' lv_start_row_c ':$' ip_ref_to_col '$' lv_stop_row_c INTO ls_serie-ref. + CLEAR: lv_start_row_c, lv_stop_row_c. + ELSE. + ls_serie-ref = ip_ref. + ENDIF. + ls_serie-idx = ip_idx. + ls_serie-order = ip_order. + ls_serie-invertifnegative = ip_invertifnegative. + ls_serie-symbol = ip_symbol. + ls_serie-smooth = ip_smooth. + ls_serie-sername = ip_sername. + APPEND ls_serie TO me->series. + SORT me->series BY order ASCENDING. + endmethod. + + + + method SET_PRINT_LBL. + me->print_label = ip_value. + endmethod. + + + + 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. + + + + + + *"* 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 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + + + + + + + + + + + + + + + method SET_SHOW_CAT_NAME. + ns_showcatnameval = ip_value. + endmethod. + + + + method SET_SHOW_LEADER_LINES. + ns_showleaderlinesval = 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 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. + + + + *"* 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. + + + + *"* 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. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL3 +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_excel3. + +TYPE-POOLS: abap. + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + column_dimension TYPE REF TO zcl_excel_worksheet_columndime. + +DATA: ls_table_settings TYPE zexcel_s_table_settings. + + +DATA: lv_title TYPE zexcel_sheet_title, + lt_carr TYPE TABLE OF scarr, + row TYPE zexcel_cell_row VALUE 2, + lo_range TYPE REF TO zcl_excel_range. +DATA: lo_data_validation TYPE REF TO zcl_excel_data_validation. +FIELD-SYMBOLS: <carr> LIKE LINE OF lt_carr. + +CONSTANTS: c_airlines TYPE string VALUE 'Airlines'. + + +CONSTANTS: gc_save_file_name TYPE string VALUE '03_iTab.xlsx'. +INCLUDE zdemo_excel_outputopt_incl. + +PARAMETERS: p_empty TYPE flag. + +START-OF-SELECTION. + " Creates active sheet + CREATE OBJECT lo_excel. + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( ip_title = 'Internal table'). + + DATA lt_test TYPE TABLE OF sflight. + + IF p_empty <> abap_true. + SELECT * FROM sflight INTO TABLE lt_test. "#EC CI_NOWHERE + ENDIF. + + ls_table_settings-table_style = zcl_excel_table=>builtinstyle_medium2. + ls_table_settings-show_row_stripes = abap_true. + + lo_worksheet->bind_table( ip_table = lt_test + is_table_settings = ls_table_settings ). + + lo_worksheet->freeze_panes( ip_num_rows = 3 ). "freeze column headers when scrolling + + column_dimension = lo_worksheet->get_column_dimension( ip_column = 'E' ). "make date field a bit wider + column_dimension->set_width( ip_width = 11 ). + " Add another table for data validations + lo_worksheet = lo_excel->add_new_worksheet( ). + lv_title = 'Data Validation'. + lo_worksheet->set_title( lv_title ). + lo_worksheet->set_cell( ip_row = 1 ip_column = 'A' ip_value = c_airlines ). + SELECT * FROM scarr INTO TABLE lt_carr. "#EC CI_NOWHERE + LOOP AT lt_carr ASSIGNING <carr>. + lo_worksheet->set_cell( ip_row = row ip_column = 'A' ip_value = <carr>-carrid ). + row = row + 1. + ENDLOOP. + row = row - 1. + lo_range = lo_excel->add_new_range( ). + lo_range->name = c_airlines. + lo_range->set_value( ip_sheet_name = lv_title + ip_start_column = 'A' + ip_start_row = 2 + ip_stop_column = 'A' + ip_stop_row = row ). + " Set Data Validation + lo_excel->set_active_sheet_index( 1 ). + lo_worksheet = lo_excel->get_active_worksheet( ). + + lo_data_validation = lo_worksheet->add_new_data_validation( ). + lo_data_validation->type = zcl_excel_data_validation=>c_type_list. + lo_data_validation->formula1 = c_airlines. + lo_data_validation->cell_row = 4. + lo_data_validation->cell_column = 'C'. + +*** Create output + lcl_output=>output( lo_excel ). + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL1 +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_excel30. + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + lo_hyperlink TYPE REF TO zcl_excel_hyperlink, + column_dimension TYPE REF TO zcl_excel_worksheet_columndime. + + +DATA: lv_value TYPE string, + lv_count TYPE i VALUE 10, + lv_packed TYPE p LENGTH 16 DECIMALS 1 VALUE '1234567890.5'. + +CONSTANTS: lc_typekind_string TYPE abap_typekind VALUE cl_abap_typedescr=>typekind_string, + lc_typekind_packed TYPE abap_typekind VALUE cl_abap_typedescr=>typekind_packed, + lc_typekind_num TYPE abap_typekind VALUE cl_abap_typedescr=>typekind_num, + lc_typekind_date TYPE abap_typekind VALUE cl_abap_typedescr=>typekind_date. + +CONSTANTS: gc_save_file_name TYPE string VALUE '30_CellDataTypes.xlsx'. +INCLUDE zdemo_excel_outputopt_incl. + + +START-OF-SELECTION. + + " Creates active sheet + CREATE OBJECT lo_excel. + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( ip_title = 'Cell data types' ). + lo_worksheet->set_cell( ip_column = 'A' ip_row = 1 ip_value = 'Number as String' + ip_abap_type = lc_typekind_string ). + lo_worksheet->set_cell( ip_column = 'A' ip_row = 2 ip_value = '11' + ip_abap_type = lc_typekind_string ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 1 ip_value = 'String' + ip_abap_type = lc_typekind_string ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = 'Negative Value' + ip_abap_type = lc_typekind_string ). + lo_worksheet->set_cell( ip_column = 'C' ip_row = 1 ip_value = 'Packed' + ip_abap_type = lc_typekind_string ). + lo_worksheet->set_cell( ip_column = 'C' ip_row = 2 ip_value = '50000.01-' + ip_abap_type = lc_typekind_packed ). + lo_worksheet->set_cell( ip_column = 'D' ip_row = 1 ip_value = 'Number with Percentage' + ip_abap_type = lc_typekind_string ). + lo_worksheet->set_cell( ip_column = 'D' ip_row = 2 ip_value = '0 %' + ip_abap_type = lc_typekind_num ). + lo_worksheet->set_cell( ip_column = 'E' ip_row = 1 ip_value = 'Date' + ip_abap_type = lc_typekind_string ). + lo_worksheet->set_cell( ip_column = 'E' ip_row = 2 ip_value = '20110831' + ip_abap_type = lc_typekind_date ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 3 ip_value = 'Positive Value' + ip_abap_type = lc_typekind_string ). + lo_worksheet->set_cell( ip_column = 'C' ip_row = 3 ip_value = '5000.02' + ip_abap_type = lc_typekind_packed ). + lo_worksheet->set_cell( ip_column = 'D' ip_row = 3 ip_value = '50 %' + ip_abap_type = lc_typekind_num ). + + WHILE lv_count <= 15. + lv_value = lv_count. + CONCATENATE 'Positive Value with' lv_value 'Digits' INTO lv_value SEPARATED BY space. + lo_worksheet->set_cell( ip_column = 'B' ip_row = lv_count ip_value = lv_value + ip_abap_type = lc_typekind_string ). + lo_worksheet->set_cell( ip_column = 'C' ip_row = lv_count ip_value = lv_packed + ip_abap_type = lc_typekind_packed ). + CONCATENATE 'Positive Value with' lv_value 'Digits formated as string' INTO lv_value SEPARATED BY space. + lo_worksheet->set_cell( ip_column = 'D' ip_row = lv_count ip_value = lv_value + ip_abap_type = lc_typekind_string ). + lo_worksheet->set_cell( ip_column = 'E' ip_row = lv_count ip_value = lv_packed + ip_abap_type = lc_typekind_string ). + lv_packed = lv_packed * 10. + lv_count = lv_count + 1. + ENDWHILE. + + column_dimension = lo_worksheet->get_column_dimension( ip_column = 'A' ). + column_dimension->set_auto_size( abap_true ). + column_dimension = lo_worksheet->get_column_dimension( ip_column = 'B' ). + column_dimension->set_auto_size( abap_true ). + column_dimension = lo_worksheet->get_column_dimension( ip_column = 'C' ). + column_dimension->set_auto_size( abap_true ). + column_dimension = lo_worksheet->get_column_dimension( ip_column = 'D' ). + column_dimension->set_auto_size( abap_true ). + column_dimension = lo_worksheet->get_column_dimension( ip_column = 'E' ). + column_dimension->set_auto_size( abap_true ). + + + + +*** Create output + lcl_output=>output( lo_excel ). + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL1 +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_excel31. + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + lo_hyperlink TYPE REF TO zcl_excel_hyperlink, + column_dimension TYPE REF TO zcl_excel_worksheet_columndime. + + +DATA: fieldval TYPE text80, + row TYPE i, + style_column_a TYPE REF TO zcl_excel_style, + style_column_a_guid TYPE zexcel_cell_style, + style_column_c TYPE REF TO zcl_excel_style, + style_column_c_guid TYPE zexcel_cell_style. + +CONSTANTS: gc_save_file_name TYPE string VALUE '31_AutosizeWithDifferentFontSizes.xlsx'. +INCLUDE zdemo_excel_outputopt_incl. + + +START-OF-SELECTION. + + " Creates active sheet + CREATE OBJECT lo_excel. + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( ip_title = 'Sheet1' ). + + style_column_a = lo_excel->add_new_style( ). + style_column_a->font->size = 32 . " quite large + style_column_a_guid = style_column_a->get_guid( ). + + style_column_c = lo_excel->add_new_style( ). + style_column_c->font->size = 16 . " not so large + style_column_c_guid = style_column_c->get_guid( ). + + + DO 20 TIMES. + row = sy-index. + CLEAR fieldval. + DO sy-index TIMES. + CONCATENATE fieldval 'X' INTO fieldval. + ENDDO. + lo_worksheet->set_cell( ip_column = 'A' ip_row = row ip_value = fieldval ip_style = style_column_a_guid ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = row ip_value = fieldval ). + lo_worksheet->set_cell( ip_column = 'C' ip_row = row ip_value = fieldval ip_style = style_column_c_guid ). + ENDDO. + + column_dimension = lo_worksheet->get_column_dimension( 'A' ). + column_dimension->set_auto_size( ip_auto_size = abap_true ). + column_dimension = lo_worksheet->get_column_dimension( 'B' ). + column_dimension->set_auto_size( ip_auto_size = abap_true ). + column_dimension = lo_worksheet->get_column_dimension( 'C' ). + column_dimension->set_auto_size( ip_auto_size = abap_true ). + + + + +*** Create output + lcl_output=>output( lo_excel ). + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + *--------------------------------------------------------------------* +* REPORT ZDEMO_EXCEL32 +* Demo for export options from ALV GRID: +* export data from ALV (CL_GUI_ALV_GRID) object or cl_salv_table object +* to Excel. +*--------------------------------------------------------------------* +REPORT zdemo_excel32. + +*----------------------------------------------------------------------* +* CLASS lcl_handle_events DEFINITION +*----------------------------------------------------------------------* +* +*----------------------------------------------------------------------* +CLASS lcl_handle_events DEFINITION. + PUBLIC SECTION. + METHODS: + on_user_command FOR EVENT added_function OF cl_salv_events + IMPORTING e_salv_function. +ENDCLASS. "lcl_handle_events DEFINITION + +*----------------------------------------------------------------------* +* CLASS lcl_handle_events IMPLEMENTATION +*----------------------------------------------------------------------* +* +*----------------------------------------------------------------------* +CLASS lcl_handle_events IMPLEMENTATION. + METHOD on_user_command. + PERFORM user_command." using e_salv_function text-i08. + ENDMETHOD. "on_user_command +ENDCLASS. "lcl_handle_events IMPLEMENTATION + +*--------------------------------------------------------------------* +* DATA DECLARATION +*--------------------------------------------------------------------* + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + lo_salv TYPE REF TO cl_salv_table, + gr_events TYPE REF TO lcl_handle_events, + lr_events TYPE REF TO cl_salv_events_table, + gt_sbook TYPE TABLE OF sbook. + +DATA: l_path TYPE string, " local dir + lv_workdir TYPE string, + lv_file_separator TYPE c. + +CONSTANTS: + lv_default_file_name TYPE string VALUE '32_Export_ALV.xlsx', + lv_default_file_name2 TYPE string VALUE '32_Export_Convert.xlsx'. +*--------------------------------------------------------------------* +*START-OF-SELECTION +*--------------------------------------------------------------------* + +START-OF-SELECTION. + +* get data +* ------------------------------------------ + + SELECT * + INTO TABLE gt_sbook[] + FROM sbook "#EC CI_NOWHERE + UP TO 100 ROWS. + +* Display ALV +* ------------------------------------------ + + TRY. + cl_salv_table=>factory( + EXPORTING + list_display = abap_false + IMPORTING + r_salv_table = lo_salv + CHANGING + t_table = gt_sbook[] ). + CATCH cx_salv_msg . + ENDTRY. + + TRY. + lo_salv->set_screen_status( + EXPORTING + report = sy-repid + pfstatus = 'ALV_STATUS' + set_functions = lo_salv->c_functions_all ). + CATCH cx_salv_msg . + ENDTRY. + + lr_events = lo_salv->get_event( ). + CREATE OBJECT gr_events. + SET HANDLER gr_events->on_user_command FOR lr_events. + + lo_salv->display( ). + + +*&---------------------------------------------------------------------* +*& Form USER_COMMAND +*&---------------------------------------------------------------------* +* ALV user command +*--------------------------------------------------------------------* +FORM user_command . + +* get save file path + cl_gui_frontend_services=>get_sapgui_workdir( CHANGING sapworkdir = l_path ). + cl_gui_cfw=>flush( ). + cl_gui_frontend_services=>directory_browse( + EXPORTING initial_folder = l_path + CHANGING selected_folder = l_path ). + + IF l_path IS INITIAL. + cl_gui_frontend_services=>get_sapgui_workdir( + CHANGING sapworkdir = lv_workdir ). + l_path = lv_workdir. + ENDIF. + + cl_gui_frontend_services=>get_file_separator( + CHANGING file_separator = lv_file_separator ). + + + +* export file to save file path + CASE sy-ucomm. + WHEN 'EXCELBIND'. + CONCATENATE l_path lv_file_separator lv_default_file_name + INTO l_path. + PERFORM export_to_excel_bind. + + WHEN 'EXCELCONV'. + + CONCATENATE l_path lv_file_separator lv_default_file_name2 + INTO l_path. + PERFORM export_to_excel_conv. + + ENDCASE. +ENDFORM. " USER_COMMAND +*--------------------------------------------------------------------* +* FORM EXPORT_TO_EXCEL_CONV +*--------------------------------------------------------------------* +* This subroutine is principal demo session +*--------------------------------------------------------------------* +FORM export_to_excel_conv. + DATA: lo_converter TYPE REF TO zcl_excel_converter. + + CREATE OBJECT lo_converter. +*TRY. + lo_converter->convert( + EXPORTING + io_alv = lo_salv + it_table = gt_sbook + i_row_int = 2 + i_column_int = 2 +* i_table = +* i_style_table = +* io_worksheet = +* CHANGING +* co_excel = + ). +* CATCH zcx_excel . +*ENDTRY. + lo_converter->write_file( i_path = l_path ). + +ENDFORM. "EXPORT_TO_EXCEL_CONV + +*--------------------------------------------------------------------* +* FORM EXPORT_TO_EXCEL_BIND +*--------------------------------------------------------------------* +* This subroutine is principal demo session +*--------------------------------------------------------------------* +FORM export_to_excel_bind. +* create zcl_excel_worksheet object + CREATE OBJECT lo_excel. + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( ip_title = 'Sheet1' ). + +* write to excel using method Bin_object +*try. + lo_worksheet->bind_alv( + io_alv = lo_salv + it_table = gt_sbook + i_top = 2 + i_left = 1 + ). +* catch zcx_excel . +*endtry. + + + PERFORM write_file. + +ENDFORM. "EXPORT_TO_EXCEL_BIND +*&---------------------------------------------------------------------* +*& Form WRITE_FILE +*&---------------------------------------------------------------------* +* text +*----------------------------------------------------------------------* +* --> p1 text +* <-- p2 text +*----------------------------------------------------------------------* +FORM write_file . + DATA: lt_file TYPE solix_tab, + l_bytecount TYPE i, + l_file TYPE xstring. + + DATA: lo_excel_writer TYPE REF TO zif_excel_writer. + + DATA: ls_seoclass TYPE seoclass. + + CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007. + l_file = lo_excel_writer->write_file( lo_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 = l_file + RECEIVING + et_solix = lt_file. + + l_bytecount = XSTRLEN( l_file ). + ELSE. + " Convert to binary + CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' + EXPORTING + buffer = l_file + IMPORTING + output_length = l_bytecount + TABLES + binary_tab = lt_file. + ENDIF. + + cl_gui_frontend_services=>gui_download( EXPORTING bin_filesize = l_bytecount + filename = l_path + filetype = 'BIN' + CHANGING data_tab = lt_file ). + +ENDFORM. " WRITE_FILE + + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL3 +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_excel33. + +TYPE-POOLS: abap. + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + lo_converter TYPE REF TO zcl_excel_converter, + lo_autofilter TYPE REF TO zcl_excel_autofilter. + +DATA lt_test TYPE TABLE OF t005t. + +DATA: l_cell_value TYPE zexcel_cell_value, + ls_area TYPE zexcel_s_autofilter_area. + +CONSTANTS: c_airlines TYPE string VALUE 'Airlines'. + +CONSTANTS: gc_save_file_name TYPE string VALUE '33_autofilter.xlsx'. +INCLUDE zdemo_excel_outputopt_incl. + + +START-OF-SELECTION. + + " Creates active sheet + CREATE OBJECT lo_excel. + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( ip_title = 'Internal table'). + + SELECT * UP TO 2 ROWS FROM t005t INTO TABLE lt_test. "#EC CI_NOWHERE + + CREATE OBJECT lo_converter. + + lo_converter->convert( EXPORTING + it_table = lt_test + i_row_int = 1 + i_column_int = 1 + io_worksheet = lo_worksheet + CHANGING + co_excel = lo_excel ) . + + lo_autofilter = lo_excel->add_new_autofilter( io_sheet = lo_worksheet ) . + + ls_area-row_start = 1. + ls_area-col_start = 1. + ls_area-row_end = lo_worksheet->get_highest_row( ). + ls_area-col_end = lo_worksheet->get_highest_column( ). + + lo_autofilter->set_filter_area( is_area = ls_area ). + + lo_worksheet->get_cell( EXPORTING + ip_column = 'C' + ip_row = 2 + IMPORTING + ep_value = l_cell_value ). + lo_autofilter->set_value( i_column = 3 + i_value = l_cell_value ). + + +*** Create output + lcl_output=>output( lo_excel ). + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL2 +*& Test Styles for ABAP2XLSX +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_excel34. + +CONSTANTS: width TYPE f VALUE '10.14'. +CONSTANTS: height TYPE f VALUE '57.75'. + +DATA: current_row TYPE i, + col TYPE i, + col_alpha TYPE zexcel_cell_column_alpha, + row TYPE i, + row_board TYPE i, + colorflag TYPE i, + color TYPE zexcel_style_color_argb, + + column_dimension TYPE REF TO zcl_excel_worksheet_columndime, + row_dimension TYPE REF TO zcl_excel_worksheet_rowdimensi, + + writing1 TYPE string, + writing2 TYPE string. + + + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_worksheet TYPE REF TO zcl_excel_worksheet. + +CONSTANTS: gc_save_file_name TYPE string VALUE '34_Static Styles_Chess.xlsx'. +INCLUDE zdemo_excel_outputopt_incl. + + +START-OF-SELECTION. + " Creates active sheet + CREATE OBJECT lo_excel. + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( ip_title = 'Spassky_vs_Bronstein' ). + +* Header + current_row = 1. + + ADD 1 TO current_row. + lo_worksheet->set_cell( ip_row = current_row ip_column = 'B' ip_value = 'White' ). + lo_worksheet->set_cell( ip_row = current_row ip_column = 'C' ip_value = 'Spassky, Boris V -- wins in turn 23' ). + + ADD 1 TO current_row. + lo_worksheet->set_cell( ip_row = current_row ip_column = 'B' ip_value = 'Black' ). + lo_worksheet->set_cell( ip_row = current_row ip_column = 'C' ip_value = 'Bronstein, David I' ). + + ADD 1 TO current_row. +* Set size of column + Writing above chessboard + DO 8 TIMES. + + writing1 = zcl_excel_common=>convert_column2alpha( sy-index ). + writing2 = sy-index . + row = current_row + sy-index. + + col = sy-index + 1. + col_alpha = zcl_excel_common=>convert_column2alpha( col ). + +* Set size of column + column_dimension = lo_worksheet->get_column_dimension( col_alpha ). + column_dimension->set_width( width ). + +* Set size of row + row_dimension = lo_worksheet->get_row_dimension( row ). + row_dimension->set_row_height( height ). + +* Set writing on chessboard + lo_worksheet->set_cell( ip_row = row + ip_column = 'A' + ip_value = writing2 ). + lo_worksheet->change_cell_style( ip_column = 'A' + ip_row = row + ip_alignment_vertical = zcl_excel_style_alignment=>c_vertical_center ). + lo_worksheet->set_cell( ip_row = row + ip_column = 'J' + ip_value = writing2 ). + lo_worksheet->change_cell_style( ip_column = 'J' + ip_row = row + ip_alignment_vertical = zcl_excel_style_alignment=>c_vertical_center ). + + row = current_row + 9. + lo_worksheet->set_cell( ip_row = current_row + ip_column = col_alpha + ip_value = writing1 ). + lo_worksheet->change_cell_style( ip_column = col_alpha + ip_row = current_row + ip_alignment_horizontal = zcl_excel_style_alignment=>c_horizontal_center ). + lo_worksheet->set_cell( ip_row = row + ip_column = col_alpha + ip_value = writing1 ). + lo_worksheet->change_cell_style( ip_column = col_alpha + ip_row = row + ip_alignment_horizontal = zcl_excel_style_alignment=>c_horizontal_center ). + ENDDO. + column_dimension = lo_worksheet->get_column_dimension( 'A' ). + column_dimension->set_auto_size( abap_true ). + column_dimension = lo_worksheet->get_column_dimension( 'J' ). + column_dimension->set_auto_size( abap_true ). + +* Set win-position + CONSTANTS: c_pawn TYPE string VALUE 'Pawn'. + CONSTANTS: c_rook TYPE string VALUE 'Rook'. + CONSTANTS: c_knight TYPE string VALUE 'Knight'. + CONSTANTS: c_bishop TYPE string VALUE 'Bishop'. + CONSTANTS: c_queen TYPE string VALUE 'Queen'. + CONSTANTS: c_king TYPE string VALUE 'King'. + + row = current_row + 1. + lo_worksheet->set_cell( ip_row = row ip_column = 'B' ip_value = c_rook ). + lo_worksheet->set_cell( ip_row = row ip_column = 'F' ip_value = c_rook ). + lo_worksheet->set_cell( ip_row = row ip_column = 'G' ip_value = c_knight ). + row = current_row + 2. + lo_worksheet->set_cell( ip_row = row ip_column = 'B' ip_value = c_pawn ). + lo_worksheet->set_cell( ip_row = row ip_column = 'C' ip_value = c_pawn ). + lo_worksheet->set_cell( ip_row = row ip_column = 'D' ip_value = c_pawn ). + lo_worksheet->set_cell( ip_row = row ip_column = 'F' ip_value = c_queen ). + lo_worksheet->set_cell( ip_row = row ip_column = 'H' ip_value = c_pawn ). + lo_worksheet->set_cell( ip_row = row ip_column = 'I' ip_value = c_king ). + row = current_row + 3. + lo_worksheet->set_cell( ip_row = row ip_column = 'I' ip_value = c_pawn ). + row = current_row + 4. + lo_worksheet->set_cell( ip_row = row ip_column = 'D' ip_value = c_pawn ). + lo_worksheet->set_cell( ip_row = row ip_column = 'F' ip_value = c_knight ). + row = current_row + 5. + lo_worksheet->set_cell( ip_row = row ip_column = 'E' ip_value = c_pawn ). + lo_worksheet->set_cell( ip_row = row ip_column = 'F' ip_value = c_queen ). + row = current_row + 6. + lo_worksheet->set_cell( ip_row = row ip_column = 'C' ip_value = c_bishop ). + row = current_row + 7. + lo_worksheet->set_cell( ip_row = row ip_column = 'B' ip_value = c_pawn ). + lo_worksheet->set_cell( ip_row = row ip_column = 'C' ip_value = c_pawn ). + lo_worksheet->set_cell( ip_row = row ip_column = 'H' ip_value = c_pawn ). + lo_worksheet->set_cell( ip_row = row ip_column = 'I' ip_value = c_pawn ). + row = current_row + 8. + lo_worksheet->set_cell( ip_row = row ip_column = 'G' ip_value = c_rook ). + lo_worksheet->set_cell( ip_row = row ip_column = 'H' ip_value = c_king ). + +* Set Chessboard + DO 8 TIMES. + IF sy-index <= 3. " Black + color = zcl_excel_style_color=>c_black. + ELSE. + color = zcl_excel_style_color=>c_white. + ENDIF. + row_board = sy-index. + row = current_row + sy-index. + DO 8 TIMES. + col = sy-index + 1. + col_alpha = zcl_excel_common=>convert_column2alpha( col ). + TRY. +* Borders around outer limits + IF row_board = 1. + lo_worksheet->change_cell_style( ip_column = col_alpha + ip_row = row + ip_borders_top_style = zcl_excel_style_border=>c_border_thick + ip_borders_top_color_rgb = zcl_excel_style_color=>c_black ). + ENDIF. + IF row_board = 8. + lo_worksheet->change_cell_style( ip_column = col_alpha + ip_row = row + ip_borders_down_style = zcl_excel_style_border=>c_border_thick + ip_borders_down_color_rgb = zcl_excel_style_color=>c_black ). + ENDIF. + IF col = 2. + lo_worksheet->change_cell_style( ip_column = col_alpha + ip_row = row + ip_borders_left_style = zcl_excel_style_border=>c_border_thick + ip_borders_left_color_rgb = zcl_excel_style_color=>c_black ). + ENDIF. + IF col = 9. + lo_worksheet->change_cell_style( ip_column = col_alpha + ip_row = row + ip_borders_right_style = zcl_excel_style_border=>c_border_thick + ip_borders_right_color_rgb = zcl_excel_style_color=>c_black ). + ENDIF. +* Style for writing + lo_worksheet->change_cell_style( ip_column = col_alpha + ip_row = row + ip_font_color_rgb = color + ip_font_bold = 'X' + ip_font_size = 16 + ip_alignment_horizontal = zcl_excel_style_alignment=>c_horizontal_center + ip_alignment_vertical = zcl_excel_style_alignment=>c_vertical_center + ip_fill_filltype = zcl_excel_style_fill=>c_fill_solid ). +* Color of field + colorflag = ( row + col ) MOD 2. + IF colorflag = 0. + lo_worksheet->change_cell_style( ip_column = col_alpha + ip_row = row + ip_fill_fgcolor_rgb = 'FFB5866A' ). + ELSE. + lo_worksheet->change_cell_style( ip_column = col_alpha + ip_row = row + ip_fill_fgcolor_rgb = 'FFF5DEBF' ). + ENDIF. + + + + CATCH zcx_excel . + ENDTRY. + + ENDDO. + ENDDO. + + +*** Create output + lcl_output=>output( lo_excel ). + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL2 +*& Test Styles for ABAP2XLSX +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_excel35. + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_excel_writer TYPE REF TO zif_excel_writer, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + lo_style_bold TYPE REF TO zcl_excel_style, + lo_style_underline TYPE REF TO zcl_excel_style, + lo_style_filled TYPE REF TO zcl_excel_style, + lo_style_border TYPE REF TO zcl_excel_style, + lo_style_button TYPE REF TO zcl_excel_style, + lo_border_dark TYPE REF TO zcl_excel_style_border, + lo_border_light TYPE REF TO zcl_excel_style_border. + +DATA: lv_style_bold_guid TYPE zexcel_cell_style, + lv_style_underline_guid TYPE zexcel_cell_style, + lv_style_filled_guid TYPE zexcel_cell_style, + lv_style_filled_green_guid TYPE zexcel_cell_style, + lv_style_border_guid TYPE zexcel_cell_style, + lv_style_button_guid TYPE zexcel_cell_style, + lv_style_filled_turquoise_guid TYPE zexcel_cell_style. + +DATA: lv_file TYPE xstring, + lv_bytecount TYPE i, + lt_file_tab TYPE solix_tab. + +DATA: lv_full_path TYPE string, + lv_workdir TYPE string, + lv_file_separator TYPE c. + +CONSTANTS: lv_default_file_name TYPE string VALUE '35_Static_Styles.xlsx'. + +PARAMETERS: p_path TYPE zexcel_export_dir. + +AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path. + lv_workdir = p_path. + cl_gui_frontend_services=>directory_browse( EXPORTING initial_folder = lv_workdir + CHANGING selected_folder = lv_workdir ). + p_path = lv_workdir. + +INITIALIZATION. + cl_gui_frontend_services=>GET_DESKTOP_DIRECTORY( CHANGING DESKTOP_DIRECTORY = lv_workdir ). + cl_gui_cfw=>flush( ). + p_path = lv_workdir. + + sy-title = 'ZDEMO_EXCEL2;Issue 139: Change cellstyle retroactivly'. + +START-OF-SELECTION. + + IF p_path IS INITIAL. + p_path = lv_workdir. + ENDIF. + cl_gui_frontend_services=>get_file_separator( CHANGING file_separator = lv_file_separator ). + CONCATENATE p_path lv_file_separator lv_default_file_name INTO lv_full_path. + + " Creates active sheet + CREATE OBJECT lo_excel. + + " Create border object + CREATE OBJECT lo_border_dark. + lo_border_dark->border_color-rgb = zcl_excel_style_color=>c_black. + lo_border_dark->border_style = zcl_excel_style_border=>c_border_thin. + CREATE OBJECT lo_border_light. + lo_border_light->border_color-rgb = zcl_excel_style_color=>c_gray. + lo_border_light->border_style = zcl_excel_style_border=>c_border_thin. + " Create a bold / italic style + lo_style_bold = lo_excel->add_new_style( ). + lo_style_bold->font->bold = abap_true. + lo_style_bold->font->italic = abap_true. + lo_style_bold->font->name = zcl_excel_style_font=>c_name_arial. + lo_style_bold->font->scheme = zcl_excel_style_font=>c_scheme_none. + lo_style_bold->font->color-rgb = zcl_excel_style_color=>c_red. + lv_style_bold_guid = lo_style_bold->get_guid( ). + " Create an underline double style + lo_style_underline = lo_excel->add_new_style( ). + lo_style_underline->font->underline = abap_true. + lo_style_underline->font->underline_mode = zcl_excel_style_font=>c_underline_double. + lo_style_underline->font->name = zcl_excel_style_font=>c_name_roman. + lo_style_underline->font->scheme = zcl_excel_style_font=>c_scheme_none. + lo_style_underline->font->family = zcl_excel_style_font=>c_family_roman. + lv_style_underline_guid = lo_style_underline->get_guid( ). + " Create filled style yellow + lo_style_filled = lo_excel->add_new_style( ). + lo_style_filled->fill->filltype = zcl_excel_style_fill=>c_fill_solid. + lo_style_filled->fill->fgcolor-theme = zcl_excel_style_color=>c_theme_accent6. + lv_style_filled_guid = lo_style_filled->get_guid( ). + " Create border with button effects + lo_style_button = lo_excel->add_new_style( ). + lo_style_button->borders->right = lo_border_dark. + lo_style_button->borders->down = lo_border_dark. + lo_style_button->borders->left = lo_border_light. + lo_style_button->borders->top = lo_border_light. + lv_style_button_guid = lo_style_button->get_guid( ). + "Create style with border + lo_style_border = lo_excel->add_new_style( ). + lo_style_border->borders->allborders = lo_border_dark. + lo_style_border->borders->diagonal = lo_border_dark. + lo_style_border->borders->diagonal_mode = zcl_excel_style_borders=>c_diagonal_both. + lv_style_border_guid = lo_style_border->get_guid( ). + " Create filled style green + lo_style_filled = lo_excel->add_new_style( ). + lo_style_filled->fill->filltype = zcl_excel_style_fill=>c_fill_solid. + lo_style_filled->fill->fgcolor-rgb = zcl_excel_style_color=>c_green. + lo_style_filled->font->name = zcl_excel_style_font=>c_name_cambria. + lo_style_filled->font->scheme = zcl_excel_style_font=>c_scheme_major. + lv_style_filled_green_guid = lo_style_filled->get_guid( ). + + " Create filled style turquoise using legacy excel ver <= 2003 palette. (https://code.sdn.sap.com/spaces/abap2xlsx/tickets/92) + lo_style_filled = lo_excel->add_new_style( ). + lo_excel->legacy_palette->set_color( "replace built-in color from palette with out custom RGB turquoise + ip_index = 16 + ip_color = '0040E0D0' ). + + lo_style_filled->fill->filltype = zcl_excel_style_fill=>c_fill_solid. + lo_style_filled->fill->fgcolor-indexed = 16. + lv_style_filled_turquoise_guid = lo_style_filled->get_guid( ). + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( ip_title = 'Styles' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = 'Hello world' ). + lo_worksheet->set_cell( ip_column = 'C' ip_row = 3 ip_value = 'Bold text' ip_style = lv_style_bold_guid ). + lo_worksheet->set_cell( ip_column = 'D' ip_row = 4 ip_value = 'Underlined text' ip_style = lv_style_underline_guid ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 5 ip_value = 'Filled text' ip_style = lv_style_filled_guid ). + lo_worksheet->set_cell( ip_column = 'C' ip_row = 6 ip_value = 'Borders' ip_style = lv_style_border_guid ). + lo_worksheet->set_cell( ip_column = 'D' ip_row = 7 ip_value = 'I''m not a button :)' ip_style = lv_style_button_guid ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 9 ip_value = 'Modified color for Excel 2003' ip_style = lv_style_filled_turquoise_guid ). + " Fill the cell and apply one style + lo_worksheet->set_cell( ip_column = 'B' ip_row = 6 ip_value = 'Filled text' ip_style = lv_style_filled_guid ). + " Change the style + lo_worksheet->set_cell_style( ip_column = 'B' ip_row = 6 ip_style = lv_style_filled_green_guid ). + " Add Style to an empty cell to test Fix for Issue + "#44 Exception ZCX_EXCEL thrown when style is set for an empty cell + " https://code.sdn.sap.com/spaces/abap2xlsx/tickets/44-exception-zcx_excel-thrown-when-style-is-set-for-an-empty-cell + lo_worksheet->set_cell_style( ip_column = 'E' ip_row = 6 ip_style = lv_style_filled_green_guid ). + + +* Demonstrate how to retroactivly change the cellstyle +*Filled text and underlinded text + lo_worksheet->change_cell_style( ip_column = 'B' + ip_row = 5 + ip_font_bold = abap_true + ip_font_italic = abap_true ). + + lo_worksheet->change_cell_style( ip_column = 'D' + ip_row = 4 + ip_font_bold = abap_true + ip_font_italic = abap_true ). + + CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007. + lv_file = lo_excel_writer->write_file( lo_excel ). + + " Convert to binary + CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' + EXPORTING + buffer = lv_file + IMPORTING + output_length = lv_bytecount + TABLES + binary_tab = lt_file_tab. +* " This method is only available on AS ABAP > 6.40 +* lt_file_tab = cl_bcs_convert=>xstring_to_solix( iv_xstring = lv_file ). +* lv_bytecount = xstrlen( lv_file ). + + " Save the file + cl_gui_frontend_services=>gui_download( EXPORTING bin_filesize = lv_bytecount + filename = lv_full_path + filetype = 'BIN' + CHANGING data_tab = lt_file_tab ). + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL36 +REPORT zdemo_excel36. + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + column_dimension TYPE REF TO zcl_excel_worksheet_columndime, + col TYPE i. + +DATA: lo_style_arial20 TYPE REF TO zcl_excel_style, + lo_style_times11 TYPE REF TO zcl_excel_style, + lo_style_cambria8red TYPE REF TO zcl_excel_style. + +DATA: lv_style_arial20_guid TYPE zexcel_cell_style, + lv_style_times11_guid TYPE zexcel_cell_style, + lv_style_cambria8red_guid TYPE zexcel_cell_style. + + +CONSTANTS: gc_save_file_name TYPE string VALUE '36_DefaultStyles.xlsx'. +INCLUDE zdemo_excel_outputopt_incl. + +START-OF-SELECTION. + + " Creates active sheet + CREATE OBJECT lo_excel. + + " Create a bold / italic style + lo_style_arial20 = lo_excel->add_new_style( ). + lo_style_arial20->font->name = zcl_excel_style_font=>c_name_arial. + lo_style_arial20->font->scheme = zcl_excel_style_font=>c_scheme_none. + lo_style_arial20->font->size = 20. + lv_style_arial20_guid = lo_style_arial20->get_guid( ). + + lo_style_times11 = lo_excel->add_new_style( ). + lo_style_times11->font->name = zcl_excel_style_font=>c_name_roman. + lo_style_times11->font->scheme = zcl_excel_style_font=>c_scheme_none. + lo_style_times11->font->size = 11. + lv_style_times11_guid = lo_style_times11->get_guid( ). + + lo_style_cambria8red = lo_excel->add_new_style( ). + lo_style_cambria8red->font->name = zcl_excel_style_font=>c_name_cambria. + lo_style_cambria8red->font->scheme = zcl_excel_style_font=>c_scheme_none. + lo_style_cambria8red->font->size = 8. + lo_style_cambria8red->font->color-rgb = zcl_excel_style_color=>c_red. + lv_style_cambria8red_guid = lo_style_cambria8red->get_guid( ). + + lo_excel->set_default_style( lv_style_arial20_guid ). " Default for all new worksheets + +* 1st sheet - do not change anything --> defaultstyle from lo_excel should apply + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( 'Style for complete document' ). + lo_worksheet->set_cell( ip_column = 2 ip_row = 4 ip_value = 'All cells in this sheet are set to font Arial, fontsize 20' ). + lo_worksheet->set_cell( ip_column = 2 ip_row = 5 ip_value = 'because no separate style was passed for this sheet' ). + lo_worksheet->set_cell( ip_column = 2 ip_row = 6 ip_value = 'but a default style was set for the complete instance of zcl_excel' ). + lo_worksheet->set_cell( ip_column = 2 ip_row = 1 ip_value = space ). " Missing feature "set active cell - use this to simulate that + + +* 2nd sheet - defaultstyle for this sheet set explicitly ( set to Times New Roman 11 ) + lo_worksheet = lo_excel->add_new_worksheet( ). + lo_worksheet->set_title( 'Style for this sheet' ). + lo_worksheet->zif_excel_sheet_properties~set_style( lv_style_times11_guid ). + + lo_worksheet->set_cell( ip_column = 2 ip_row = 4 ip_value = 'All cells in this sheet are set to font Times New Roman, fontsize 11' ). + lo_worksheet->set_cell( ip_column = 2 ip_row = 5 ip_value = 'because this style was passed for this sheet' ). + lo_worksheet->set_cell( ip_column = 2 ip_row = 6 ip_value = 'thus the default style from zcl_excel does not apply to this sheet' ). + lo_worksheet->set_cell( ip_column = 2 ip_row = 1 ip_value = space ). " Missing feature "set active cell - use this to simulate that + + +* 3rd sheet - defaultstyle for columns ( set to Times New Roman 11 ) + lo_worksheet = lo_excel->add_new_worksheet( ). + lo_worksheet->set_title( 'Style for 3 columns' ). + column_dimension = lo_worksheet->get_column_dimension( 'B' ). + column_dimension->set_column_style_by_guid( ip_style_guid = lv_style_times11_guid ). + column_dimension = lo_worksheet->get_column_dimension( 'C' ). + column_dimension->set_column_style_by_guid( ip_style_guid = lv_style_times11_guid ). + column_dimension = lo_worksheet->get_column_dimension( 'F' ). + column_dimension->set_column_style_by_guid( ip_style_guid = lv_style_times11_guid ). + + lo_worksheet->set_cell( ip_column = 2 ip_row = 4 ip_value = 'The columns B,C and F are set to Times New Roman' ). + lo_worksheet->set_cell( ip_column = 2 ip_row = 10 ip_value = 'All other cells in this sheet are set to font Arial, fontsize 20' ). + lo_worksheet->set_cell( ip_column = 2 ip_row = 11 ip_value = 'because no separate style was passed for this sheet' ). + lo_worksheet->set_cell( ip_column = 2 ip_row = 12 ip_value = 'but a default style was set for the complete instance of zcl_excel' ). + + lo_worksheet->set_cell( ip_column = 8 ip_row = 1 ip_value = 'Of course' ip_style = lv_style_cambria8red_guid ). + lo_worksheet->set_cell( ip_column = 8 ip_row = 2 ip_value = 'setting a specific style to a cell' ip_style = lv_style_cambria8red_guid ). + lo_worksheet->set_cell( ip_column = 8 ip_row = 3 ip_value = 'takes precedence over all defaults' ip_style = lv_style_cambria8red_guid ). + lo_worksheet->set_cell( ip_column = 8 ip_row = 4 ip_value = 'Here: Cambria 8 in red' ip_style = lv_style_cambria8red_guid ). + + +* Set entry into each of the first 10 columns + DO 20 TIMES. + col = sy-index. + CASE col. + WHEN 2 " B + OR 3 " C + OR 6." F + lo_worksheet->set_cell( ip_column = col ip_row = 6 ip_value = 'Times 11' ). + WHEN OTHERS. + lo_worksheet->set_cell( ip_column = col ip_row = 6 ip_value = 'Arial 20' ). + ENDCASE. + ENDDO. + + lo_worksheet->set_cell( ip_column = 2 ip_row = 1 ip_value = space ). " Missing feature "set active cell - use this to simulate that + + + + lo_excel->set_active_sheet_index( 1 ). + + +*** Create output + lcl_output=>output( lo_excel ). + + + + + + + + + + + + + REPORT zdemo_excel37. + +DATA: excel TYPE REF TO zcl_excel, + reader TYPE REF TO zif_excel_reader, + go_error TYPE REF TO cx_root, + gv_message type string. + + +CONSTANTS: gc_save_file_name TYPE string VALUE '37-passthrough.xlsx'. + +SELECTION-SCREEN BEGIN OF BLOCK blx WITH FRAME. +PARAMETERS: p_upfile TYPE string DEFAULT 'c:\temp\whatever.xlsx' LOWER CASE. +SELECTION-SCREEN END OF BLOCK blx. + +INCLUDE zdemo_excel_outputopt_incl. + +AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_upfile. + PERFORM f4_p_upfile CHANGING p_upfile. + + +START-OF-SELECTION. + + TRY. + CREATE OBJECT reader TYPE zcl_excel_reader_2007. +* CREATE OBJECT reader TYPE zcl_excel_reader_xlsm. + excel = reader->load_file( p_upfile ). + + "Use template for charts + excel->use_template = abap_true. +*--------------------------------------------------------------------* +* CL_ABAP_ZIP may have problems reading LibreOffice generated files +* You may have to use alternate ZIP-Class - see comments in issue #234 in abap2xlsx at developers network +* excel = reader->load_file( i_filename = p_upfile +* iv_use_alternate_zip = 'ZCL_EXCEL_ABAP_ZIP' ). +*--------------------------------------------------------------------* + +*** Create output + lcl_output=>output( excel ). + CATCH cx_root INTO go_error. + MESSAGE 'Error reading excelfile' TYPE 'I'. + gv_message = go_error->get_text( ). + IF gv_message IS NOT INITIAL. + MESSAGE gv_message TYPE 'I'. + ENDIF. + ENDTRY. + + +*&---------------------------------------------------------------------* +*& Form F4_P_UPFILE +*&---------------------------------------------------------------------* +FORM f4_p_upfile CHANGING p_upfile TYPE string. + + DATA: lv_repid TYPE syrepid, + lt_fields TYPE dynpread_tabtype, + ls_field LIKE LINE OF lt_fields, + lt_files TYPE filetable. + + lv_repid = sy-repid. + + CALL FUNCTION 'DYNP_VALUES_READ' + EXPORTING + dyname = lv_repid + dynumb = '1000' + request = 'A' + TABLES + dynpfields = lt_fields + EXCEPTIONS + invalid_abapworkarea = 01 + invalid_dynprofield = 02 + invalid_dynproname = 03 + invalid_dynpronummer = 04 + invalid_request = 05 + no_fielddescription = 06 + undefind_error = 07. + READ TABLE lt_fields INTO ls_field WITH KEY fieldname = 'P_UPFILE'. + p_upfile = ls_field-fieldvalue. + + cl_gui_frontend_services=>file_open_dialog( EXPORTING + default_filename = p_upfile + file_filter = zcl_excel_common=>c_xlsx_file_filter + CHANGING + file_table = lt_files + rc = sy-tabix + EXCEPTIONS + OTHERS = 1 ). + READ TABLE lt_files INDEX 1 INTO p_upfile. + +ENDFORM. " F4_P_UPFILE + + + + + + + + + REPORT. + + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + lo_column_dimension TYPE REF TO zcl_excel_worksheet_columndime, + lo_drawing TYPE REF TO zcl_excel_drawing. + +TYPES: BEGIN OF gty_icon, +* name TYPE icon_name, "Fix #228 + name TYPE iconname, "Fix #228 + objid TYPE w3objid, + END OF gty_icon, + gtyt_icon TYPE STANDARD TABLE OF gty_icon WITH NON-UNIQUE DEFAULT KEY. + +DATA: lt_icon TYPE gtyt_icon, + lv_row TYPE sytabix, + ls_wwwdatatab TYPE wwwdatatab, + lt_mimedata TYPE STANDARD TABLE OF w3mime WITH NON-UNIQUE DEFAULT KEY, + lv_xstring TYPE xstring. + +FIELD-SYMBOLS: <icon> LIKE LINE OF lt_icon, + <mimedata> LIKE LINE OF lt_mimedata. + +CONSTANTS: gc_save_file_name TYPE string VALUE '38_SAP-Icons.xlsx'. +INCLUDE zdemo_excel_outputopt_incl. + + +TABLES: icon. +SELECT-OPTIONS: s_icon FOR icon-name DEFAULT 'ICON_LED_*' OPTION CP. + +START-OF-SELECTION. + " Creates active sheet + CREATE OBJECT lo_excel. + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( ip_title = 'Demo Icons' ). + lo_column_dimension = lo_worksheet->get_column_dimension( ip_column = 'A' ). + lo_column_dimension->set_auto_size( 'X' ). + lo_column_dimension = lo_worksheet->get_column_dimension( ip_column = 'B' ). + lo_column_dimension->set_auto_size( 'X' ). + +* Get all icons + SELECT name + INTO TABLE lt_icon + FROM icon + WHERE name IN s_icon + ORDER BY name. + LOOP AT lt_icon ASSIGNING <icon>. + + lv_row = sy-tabix. +*--------------------------------------------------------------------* +* Set name of icon +*--------------------------------------------------------------------* + lo_worksheet->set_cell( ip_row = lv_row + ip_column = 'A' + ip_value = <icon>-name ). +*--------------------------------------------------------------------* +* Check whether the mime-repository holds some icondata for us +*--------------------------------------------------------------------* + +* Get key + SELECT SINGLE objid + INTO <icon>-objid + FROM wwwdata + WHERE text = <icon>-name. + CHECK sy-subrc = 0. " :o( + lo_worksheet->set_cell( ip_row = lv_row + ip_column = 'B' + ip_value = <icon>-objid ). + +* Load mimedata + CLEAR lt_mimedata. + CLEAR ls_wwwdatatab. + ls_wwwdatatab-relid = 'MI' . + ls_wwwdatatab-objid = <icon>-objid. + CALL FUNCTION 'WWWDATA_IMPORT' + EXPORTING + key = ls_wwwdatatab + TABLES + mime = lt_mimedata + EXCEPTIONS + wrong_object_type = 1 + import_error = 2 + OTHERS = 3. + CHECK sy-subrc = 0. " :o( + + lo_drawing = lo_excel->add_new_drawing( ). + lo_drawing->set_position( ip_from_row = lv_row + ip_from_col = 'C' ). + CLEAR lv_xstring. + LOOP AT lt_mimedata ASSIGNING <mimedata>. + CONCATENATE lv_xstring <mimedata>-line INTO lv_xstring IN BYTE MODE. + ENDLOOP. + + lo_drawing->set_media( ip_media = lv_xstring + ip_media_type = zcl_excel_drawing=>c_media_type_jpg + ip_width = 16 + ip_height = 14 ). + lo_worksheet->add_drawing( lo_drawing ). + + ENDLOOP. + +*** Create output + lcl_output=>output( lo_excel ). + + + + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL16 +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_excel39. + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + lo_drawing TYPE REF TO zcl_excel_drawing. + +DATA lv_value TYPE i. + +DATA: ls_io TYPE skwf_io. + +DATA: ls_upper TYPE zexcel_drawing_location, + ls_lower TYPE zexcel_drawing_location. + +DATA lo_bar1 TYPE REF TO zcl_excel_graph_bars. +DATA lo_bar2 TYPE REF TO zcl_excel_graph_bars. +DATA lo_pie TYPE REF TO zcl_excel_graph_pie. +DATA lo_line TYPE REF TO zcl_excel_graph_line. + +CONSTANTS: gc_save_file_name TYPE string VALUE '39_Charts.xlsx'. +INCLUDE zdemo_excel_outputopt_incl. + +START-OF-SELECTION. + + " Create a pie chart and series + CREATE OBJECT lo_pie. + + CALL METHOD lo_pie->create_serie + EXPORTING + ip_order = 0 + ip_sheet = 'Values' + ip_lbl_from_col = 'B' + ip_lbl_from_row = '1' + ip_lbl_to_col = 'B' + ip_lbl_to_row = '3' + ip_ref_from_col = 'A' + ip_ref_from_row = '1' + ip_ref_to_col = 'A' + ip_ref_to_row = '3' + ip_sername = 'My serie 1'. + + " Set style + lo_pie->set_style( zcl_excel_graph=>c_style_15 ). + + " Create a bar chart, series and axes + CREATE OBJECT lo_bar1. + + CALL METHOD lo_bar1->create_serie + EXPORTING + ip_order = 0 + ip_invertifnegative = zcl_excel_graph_bars=>c_invertifnegative_no + ip_lbl = 'Values!$D$1:$D$3' + ip_ref = 'Values!$C$1:$C$3' + ip_sername = 'My serie 1'. + + CALL METHOD lo_bar1->create_serie + EXPORTING + ip_order = 1 + ip_invertifnegative = zcl_excel_graph_bars=>c_invertifnegative_no + ip_lbl = 'Values!$B$1:$B$3' + ip_ref = 'Values!$A$1:$A$3' + ip_sername = 'My serie 2'. + + CALL METHOD lo_bar1->create_ax + EXPORTING +* ip_axid = + ip_type = zcl_excel_graph_bars=>c_catax +* ip_orientation = +* ip_delete = +* ip_axpos = +* ip_formatcode = +* ip_sourcelinked = +* ip_majortickmark = +* ip_minortickmark = +* ip_ticklblpos = +* ip_crossax = +* ip_crosses = +* ip_auto = +* ip_lblalgn = +* ip_lbloffset = +* ip_nomultilvllbl = +* ip_crossbetween = + . + + CALL METHOD lo_bar1->create_ax + EXPORTING +* ip_axid = + ip_type = zcl_excel_graph_bars=>c_valax +* ip_orientation = +* ip_delete = +* ip_axpos = +* ip_formatcode = +* ip_sourcelinked = +* ip_majortickmark = +* ip_minortickmark = +* ip_ticklblpos = +* ip_crossax = +* ip_crosses = +* ip_auto = +* ip_lblalgn = +* ip_lbloffset = +* ip_nomultilvllbl = +* ip_crossbetween = + . + + " Set style + lo_bar1->set_style( zcl_excel_graph=>c_style_default ). + + " Set label to none + lo_bar1->set_print_lbl( zcl_excel_graph_bars=>c_show_false ). + + " Create a bar chart, series and axes + CREATE OBJECT lo_bar2. + + CALL METHOD lo_bar2->create_serie + EXPORTING + ip_order = 0 + ip_invertifnegative = zcl_excel_graph_bars=>c_invertifnegative_yes + ip_lbl = 'Values!$D$1:$D$3' + ip_ref = 'Values!$C$1:$C$3' + ip_sername = 'My serie 1'. + + CALL METHOD lo_bar2->create_ax + EXPORTING +* ip_axid = + ip_type = zcl_excel_graph_bars=>c_catax +* ip_orientation = +* ip_delete = +* ip_axpos = +* ip_formatcode = +* ip_sourcelinked = +* ip_majortickmark = +* ip_minortickmark = +* ip_ticklblpos = +* ip_crossax = +* ip_crosses = +* ip_auto = +* ip_lblalgn = +* ip_lbloffset = +* ip_nomultilvllbl = +* ip_crossbetween = + . + + CALL METHOD lo_bar2->create_ax + EXPORTING +* ip_axid = + ip_type = zcl_excel_graph_bars=>c_valax +* ip_orientation = +* ip_delete = +* ip_axpos = +* ip_formatcode = +* ip_sourcelinked = +* ip_majortickmark = +* ip_minortickmark = +* ip_ticklblpos = +* ip_crossax = +* ip_crosses = +* ip_auto = +* ip_lblalgn = +* ip_lbloffset = +* ip_nomultilvllbl = +* ip_crossbetween = + . + + " Set layout + lo_bar2->set_show_legend_key( zcl_excel_graph_bars=>c_show_true ). + lo_bar2->set_show_values( zcl_excel_graph_bars=>c_show_true ). + lo_bar2->set_show_cat_name( zcl_excel_graph_bars=>c_show_true ). + lo_bar2->set_show_ser_name( zcl_excel_graph_bars=>c_show_true ). + lo_bar2->set_show_percent( zcl_excel_graph_bars=>c_show_true ). + lo_bar2->set_varycolor( zcl_excel_graph_bars=>c_show_true ). + + " Create a line chart, series and axes + CREATE OBJECT lo_line. + + CALL METHOD lo_line->create_serie + EXPORTING + ip_order = 0 + ip_symbol = zcl_excel_graph_line=>c_symbol_auto + ip_smooth = zcl_excel_graph_line=>c_show_false + ip_lbl = 'Values!$D$1:$D$3' + ip_ref = 'Values!$C$1:$C$3' + ip_sername = 'My serie 1'. + + CALL METHOD lo_line->create_serie + EXPORTING + ip_order = 1 + ip_symbol = zcl_excel_graph_line=>c_symbol_none + ip_smooth = zcl_excel_graph_line=>c_show_false + ip_lbl = 'Values!$B$1:$B$3' + ip_ref = 'Values!$A$1:$A$3' + ip_sername = 'My serie 2'. + + CALL METHOD lo_line->create_serie + EXPORTING + ip_order = 2 + ip_symbol = zcl_excel_graph_line=>c_symbol_auto + ip_smooth = zcl_excel_graph_line=>c_show_false + ip_lbl = 'Values!$F$1:$F$3' + ip_ref = 'Values!$E$1:$E$3' + ip_sername = 'My serie 3'. + + CALL METHOD lo_line->create_ax + EXPORTING +* ip_axid = + ip_type = zcl_excel_graph_line=>c_catax +* ip_orientation = +* ip_delete = +* ip_axpos = +* ip_majortickmark = +* ip_minortickmark = +* ip_ticklblpos = +* ip_crossax = +* ip_crosses = +* ip_auto = +* ip_lblalgn = +* ip_lbloffset = +* ip_nomultilvllbl = +* ip_crossbetween = + . + + CALL METHOD lo_line->create_ax + EXPORTING +* ip_axid = + ip_type = zcl_excel_graph_line=>c_valax +* ip_orientation = +* ip_delete = +* ip_axpos = +* ip_formatcode = +* ip_sourcelinked = +* ip_majortickmark = +* ip_minortickmark = +* ip_ticklblpos = +* ip_crossax = +* ip_crosses = +* ip_auto = +* ip_lblalgn = +* ip_lbloffset = +* ip_nomultilvllbl = +* ip_crossbetween = + . + + + + + + + + " Creates active sheet + CREATE OBJECT lo_excel. + + " Get active sheet (Pie sheet) + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( 'PieChart' ). + + " Create global drawing, set type as pie chart, assign chart, set position and media type + lo_drawing = lo_worksheet->excel->add_new_drawing( + ip_type = zcl_excel_drawing=>type_chart + ip_title = 'CHART PIE' ). + lo_drawing->graph = lo_pie. + lo_drawing->graph_type = zcl_excel_drawing=>c_graph_pie. + + "Set chart position (anchor 2 cells) + ls_lower-row = 30. + ls_lower-col = 20. + lo_drawing->set_position2( + EXPORTING + ip_from = ls_upper + ip_to = ls_lower ). + + lo_drawing->set_media( + EXPORTING + ip_media_type = zcl_excel_drawing=>c_media_type_xml ). + + lo_worksheet->add_drawing( lo_drawing ). + + " BarChart1 sheet + + lo_worksheet = lo_excel->add_new_worksheet( ). + lo_worksheet->set_title( ip_title = 'BarChart1' ). + + " Create global drawing, set type as bar chart, assign chart, set position and media type + lo_drawing = lo_worksheet->excel->add_new_drawing( + ip_type = zcl_excel_drawing=>type_chart + ip_title = 'CHART BARS WITH 2 SERIES' ). + lo_drawing->graph = lo_bar1. + lo_drawing->graph_type = zcl_excel_drawing=>c_graph_bars. + + "Set chart position (anchor 2 cells) + ls_upper-row = 0. + ls_upper-col = 11. + ls_lower-row = 22. + ls_lower-col = 21. + lo_drawing->set_position2( + EXPORTING + ip_from = ls_upper + ip_to = ls_lower ). + + lo_drawing->set_media( + EXPORTING + ip_media_type = zcl_excel_drawing=>c_media_type_xml ). + + lo_worksheet->add_drawing( lo_drawing ). + + " BarChart2 sheet + + lo_worksheet = lo_excel->add_new_worksheet( ). + lo_worksheet->set_title( ip_title = 'BarChart2' ). + + " Create global drawing, set type as bar chart, assign chart, set position and media type + lo_drawing = lo_worksheet->excel->add_new_drawing( + ip_type = zcl_excel_drawing=>type_chart + ip_title = 'CHART BARS WITH 1 SERIE' ). + lo_drawing->graph = lo_bar2. + lo_drawing->graph_type = zcl_excel_drawing=>c_graph_bars. + + "Set chart position (anchor 2 cells) + ls_upper-row = 0. + ls_upper-col = 0. + ls_lower-row = 30. + ls_lower-col = 20. + lo_drawing->set_position2( + EXPORTING + ip_from = ls_upper + ip_to = ls_lower ). + + lo_drawing->set_media( + EXPORTING + ip_media_type = zcl_excel_drawing=>c_media_type_xml ). + + lo_worksheet->add_drawing( lo_drawing ). + + " LineChart sheet + + lo_worksheet = lo_excel->add_new_worksheet( ). + lo_worksheet->set_title( ip_title = 'LineChart' ). + + " Create global drawing, set type as line chart, assign chart, set position and media type + lo_drawing = lo_worksheet->excel->add_new_drawing( + ip_type = zcl_excel_drawing=>type_chart + ip_title = 'CHART LINES' ). + lo_drawing->graph = lo_line. + lo_drawing->graph_type = zcl_excel_drawing=>c_graph_line. + + "Set chart position (anchor 2 cells) + ls_upper-row = 0. + ls_upper-col = 0. + ls_lower-row = 30. + ls_lower-col = 20. + lo_drawing->set_position2( + EXPORTING + ip_from = ls_upper + ip_to = ls_lower ). + + lo_drawing->set_media( + EXPORTING + ip_media_type = zcl_excel_drawing=>c_media_type_xml ). + + lo_worksheet->add_drawing( lo_drawing ). + + " Values sheet + lo_worksheet = lo_excel->add_new_worksheet( ). + lo_worksheet->set_title( ip_title = 'Values' ). + + " Set values for chart + lv_value = 1. + lo_worksheet->set_cell( ip_column = 'A' ip_row = 1 ip_value = lv_value ). + lv_value = 2. + lo_worksheet->set_cell( ip_column = 'A' ip_row = 2 ip_value = lv_value ). + lv_value = 3. + lo_worksheet->set_cell( ip_column = 'A' ip_row = 3 ip_value = lv_value ). + + " Set labels for chart + lo_worksheet->set_cell( ip_column = 'B' ip_row = 1 ip_value = 'One' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = 'Two' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 3 ip_value = 'Three' ). + + " Set values for chart + lv_value = 3. + lo_worksheet->set_cell( ip_column = 'C' ip_row = 1 ip_value = lv_value ). + lv_value = 2. + lo_worksheet->set_cell( ip_column = 'C' ip_row = 2 ip_value = lv_value ). + lv_value = -1. + lo_worksheet->set_cell( ip_column = 'C' ip_row = 3 ip_value = lv_value ). + + " Set labels for chart + lo_worksheet->set_cell( ip_column = 'D' ip_row = 3 ip_value = 'One (Minus)' ). + lo_worksheet->set_cell( ip_column = 'D' ip_row = 2 ip_value = 'Two' ). + lo_worksheet->set_cell( ip_column = 'D' ip_row = 1 ip_value = 'Three' ). + + " Set values for chart + lv_value = 3. + lo_worksheet->set_cell( ip_column = 'E' ip_row = 1 ip_value = lv_value ). + lv_value = 1. + lo_worksheet->set_cell( ip_column = 'E' ip_row = 2 ip_value = lv_value ). + lv_value = 2. + lo_worksheet->set_cell( ip_column = 'E' ip_row = 3 ip_value = lv_value ). + + " Set labels for chart + lo_worksheet->set_cell( ip_column = 'F' ip_row = 3 ip_value = 'Two' ). + lo_worksheet->set_cell( ip_column = 'F' ip_row = 2 ip_value = 'One' ). + lo_worksheet->set_cell( ip_column = 'F' ip_row = 1 ip_value = 'Three' ). + + +*** Create output + lcl_output=>output( lo_excel ). + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL4 +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_excel4. + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + + lo_hyperlink TYPE REF TO zcl_excel_hyperlink, + + lv_tabcolor TYPE zexcel_s_tabcolor, + + ls_header TYPE zexcel_s_worksheet_head_foot, + ls_footer TYPE zexcel_s_worksheet_head_foot. + +CONSTANTS: gc_save_file_name TYPE string VALUE '04_Sheets.xlsx'. +INCLUDE zdemo_excel_outputopt_incl. + + +START-OF-SELECTION. + + " Creates active sheet + CREATE OBJECT lo_excel. + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( ip_title = 'Sheet1' ). + lo_worksheet->zif_excel_sheet_properties~selected = zif_excel_sheet_properties=>c_selected. + lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = 'This is the first sheet' ). +* Set color to tab with sheetname - Red + lv_tabcolor-rgb = zcl_excel_style_color=>create_new_argb( ip_red = 'FF' + ip_green = '00' + ip_blu = '00' ). + lo_worksheet->set_tabcolor( lv_tabcolor ). + + lo_hyperlink = zcl_excel_hyperlink=>create_internal_link( iv_location = 'Sheet2!B2' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 3 ip_value = 'This is link to second sheet' ip_hyperlink = lo_hyperlink ). + + " Page printing settings + lo_worksheet->sheet_setup->set_page_margins( ip_header = '1' ip_footer = '1' ip_unit = 'cm' ). + lo_worksheet->sheet_setup->black_and_white = 'X'. + lo_worksheet->sheet_setup->fit_to_page = 'X'. " you should turn this on to activate fit_to_height and fit_to_width + lo_worksheet->sheet_setup->fit_to_height = 0. " used only if ip_fit_to_page = 'X' + lo_worksheet->sheet_setup->fit_to_width = 2. " used only if ip_fit_to_page = 'X' + lo_worksheet->sheet_setup->orientation = zcl_excel_sheet_setup=>c_orientation_landscape. + lo_worksheet->sheet_setup->page_order = zcl_excel_sheet_setup=>c_ord_downthenover. + lo_worksheet->sheet_setup->paper_size = zcl_excel_sheet_setup=>c_papersize_a4. + lo_worksheet->sheet_setup->scale = 80. " used only if ip_fit_to_page = SPACE + + " Header and Footer + ls_header-right_value = 'print date &D'. + ls_header-right_font-size = 8. + ls_header-right_font-name = zcl_excel_style_font=>c_name_arial. + + ls_footer-left_value = '&Z&F'. "Path / Filename + ls_footer-left_font = ls_header-right_font. + ls_footer-right_value = 'page &P of &N'. "page x of y + ls_footer-right_font = ls_header-right_font. + + lo_worksheet->sheet_setup->set_header_footer( ip_odd_header = ls_header + ip_odd_footer = ls_footer ). + + + lo_worksheet = lo_excel->add_new_worksheet( ). + lo_worksheet->set_title( ip_title = 'Sheet2' ). +* Set color to tab with sheetname - Green + lv_tabcolor-rgb = zcl_excel_style_color=>create_new_argb( ip_red = '00' + ip_green = 'FF' + ip_blu = '00' ). + lo_worksheet->set_tabcolor( lv_tabcolor ). + lo_worksheet->zif_excel_sheet_properties~selected = zif_excel_sheet_properties=>c_selected. + lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = 'This is the second sheet' ). + lo_hyperlink = zcl_excel_hyperlink=>create_internal_link( iv_location = 'Sheet1!B2' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 3 ip_value = 'This is link to first sheet' ip_hyperlink = lo_hyperlink ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 4 ip_value = 'Sheet3 is hidden' ). + + lo_worksheet->sheet_setup->set_header_footer( ip_odd_header = ls_header + ip_odd_footer = ls_footer ). + + lo_worksheet = lo_excel->add_new_worksheet( ). + lo_worksheet->set_title( ip_title = 'Sheet3' ). +* Set color to tab with sheetname - Blue + lv_tabcolor-rgb = zcl_excel_style_color=>create_new_argb( ip_red = '00' + ip_green = '00' + ip_blu = 'FF' ). + lo_worksheet->set_tabcolor( lv_tabcolor ). + lo_worksheet->zif_excel_sheet_properties~hidden = zif_excel_sheet_properties=>c_hidden. + + lo_worksheet->sheet_setup->set_header_footer( ip_odd_header = ls_header + ip_odd_footer = ls_footer ). + + lo_worksheet = lo_excel->add_new_worksheet( ). + lo_worksheet->set_title( ip_title = 'Sheet4' ). +* Set color to tab with sheetname - other color + lv_tabcolor-rgb = zcl_excel_style_color=>create_new_argb( ip_red = '00' + ip_green = 'FF' + ip_blu = 'FF' ). + lo_worksheet->set_tabcolor( lv_tabcolor ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = 'Cell B3 has value 0' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 3 ip_value = 0 ). + lo_worksheet->zif_excel_sheet_properties~show_zeros = zif_excel_sheet_properties=>c_hidezero. + + lo_worksheet->sheet_setup->set_header_footer( ip_odd_header = ls_header + ip_odd_footer = ls_footer ). + + lo_excel->set_active_sheet_index_by_name( 'Sheet1' ). + + +*** Create output + lcl_output=>output( lo_excel ). + + + + + + + + + REPORT. + + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_worksheet TYPE REF TO zcl_excel_worksheet. + +DATA: lv_row TYPE zexcel_cell_row, + lv_col TYPE i, + lv_row_char TYPE char10, + lv_value TYPE string, + ls_fontcolor TYPE zexcel_style_color_argb. + +CONSTANTS: gc_save_file_name TYPE string VALUE '40_Printsettings.xlsx'. +INCLUDE zdemo_excel_outputopt_incl. + + + +START-OF-SELECTION. + " Creates active sheet + CREATE OBJECT lo_excel. + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( ip_title = 'Demo Printsettings' ). + +*--------------------------------------------------------------------* +* Prepare sheet with trivial data +* - first 4 columns will have fontocolor set +* - first 3 rows will have fontcolor set +* These marked cells will be used for repeatable rows/columns on printpages +*--------------------------------------------------------------------* + DO 100 TIMES. " Rows + + lv_row = sy-index . + WRITE lv_row TO lv_row_char. + + DO 20 TIMES. + + lv_col = sy-index - 1. + CONCATENATE sy-abcde+lv_col(1) lv_row_char INTO lv_value. + lv_col = sy-index. + lo_worksheet->set_cell( ip_row = lv_row + ip_column = lv_col + ip_value = lv_value ). + + TRY. + IF lv_row <= 3. + lo_worksheet->change_cell_style( ip_column = lv_col + ip_row = lv_row + ip_fill_filltype = zcl_excel_style_fill=>c_fill_solid + ip_fill_fgcolor_rgb = zcl_excel_style_color=>c_yellow ). + ENDIF. + IF lv_col <= 4. + lo_worksheet->change_cell_style( ip_column = lv_col + ip_row = lv_row + ip_font_color_rgb = zcl_excel_style_color=>c_red ). + ENDIF. + CATCH zcx_excel . + ENDTRY. + + ENDDO. + + + + ENDDO. + + +*--------------------------------------------------------------------* +* Printsettings +*--------------------------------------------------------------------* + TRY. + lo_worksheet->zif_excel_sheet_printsettings~set_print_repeat_columns( iv_columns_from = 'A' + iv_columns_to = 'D' ). + lo_worksheet->zif_excel_sheet_printsettings~set_print_repeat_rows( iv_rows_from = 1 + iv_rows_to = 3 ). + CATCH zcx_excel . + ENDTRY. + + + + +*** Create output + lcl_output=>output( lo_excel ). + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL5 +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_excel5. + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + lo_style_conditional TYPE REF TO zcl_excel_style_conditional. + +DATA: ls_iconset TYPE zexcel_conditional_iconset. + + + +CONSTANTS: gc_save_file_name TYPE string VALUE '05_Conditional.xlsx'. +INCLUDE zdemo_excel_outputopt_incl. + + +START-OF-SELECTION. + + CREATE OBJECT lo_excel. + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + + lo_style_conditional = lo_worksheet->add_new_conditional_style( ). + lo_style_conditional->rule = zcl_excel_style_conditional=>c_rule_iconset. + lo_style_conditional->priority = 1. + + + ls_iconset-iconset = zcl_excel_style_conditional=>c_iconset_3trafficlights2. + 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 = '33'. + ls_iconset-cfvo3_type = zcl_excel_style_conditional=>c_cfvo_type_percent. + ls_iconset-cfvo3_value = '66'. + ls_iconset-showvalue = zcl_excel_style_conditional=>c_showvalue_true. + + lo_style_conditional->mode_iconset = ls_iconset. + lo_style_conditional->set_range( ip_start_column = 'C' + ip_start_row = 4 + ip_stop_column = 'C' + ip_stop_row = 8 ). + + + lo_worksheet->set_cell( ip_row = 4 ip_column = 'C' ip_value = 100 ). + lo_worksheet->set_cell( ip_row = 5 ip_column = 'C' ip_value = 1000 ). + lo_worksheet->set_cell( ip_row = 6 ip_column = 'C' ip_value = 150 ). + lo_worksheet->set_cell( ip_row = 7 ip_column = 'C' ip_value = 10 ). + lo_worksheet->set_cell( ip_row = 8 ip_column = 'C' ip_value = 500 ). + + + lo_style_conditional = lo_worksheet->add_new_conditional_style( ). + lo_style_conditional->rule = zcl_excel_style_conditional=>c_rule_iconset. + lo_style_conditional->priority = 1. + ls_iconset-iconset = zcl_excel_style_conditional=>c_iconset_3trafficlights2. + ls_iconset-showvalue = zcl_excel_style_conditional=>c_showvalue_false. + lo_style_conditional->mode_iconset = ls_iconset. + lo_style_conditional->set_range( ip_start_column = 'E' + ip_start_row = 4 + ip_stop_column = 'E' + ip_stop_row = 8 ). + + + lo_worksheet->set_cell( ip_row = 4 ip_column = 'E' ip_value = 100 ). + lo_worksheet->set_cell( ip_row = 5 ip_column = 'E' ip_value = 1000 ). + lo_worksheet->set_cell( ip_row = 6 ip_column = 'E' ip_value = 150 ). + lo_worksheet->set_cell( ip_row = 7 ip_column = 'E' ip_value = 10 ). + lo_worksheet->set_cell( ip_row = 8 ip_column = 'E' ip_value = 500 ). + + + +*** Create output + lcl_output=>output( lo_excel ). + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL6 +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_excel6. + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + lv_row TYPE syindex, + lv_formula TYPE string. + + +CONSTANTS: gc_save_file_name TYPE string VALUE '06_Formulas.xlsx'. +INCLUDE zdemo_excel_outputopt_incl. + + +START-OF-SELECTION. + + CREATE OBJECT lo_excel. + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + +*--------------------------------------------------------------------* +* Get some testdata +*--------------------------------------------------------------------* + lo_worksheet->set_cell( ip_row = 4 ip_column = 'C' ip_value = 100 ). + lo_worksheet->set_cell( ip_row = 5 ip_column = 'C' ip_value = 1000 ). + lo_worksheet->set_cell( ip_row = 6 ip_column = 'C' ip_value = 150 ). + lo_worksheet->set_cell( ip_row = 7 ip_column = 'C' ip_value = -10 ). + lo_worksheet->set_cell( ip_row = 8 ip_column = 'C' ip_value = 500 ). + + +*--------------------------------------------------------------------* +* Demonstrate using formulas +*--------------------------------------------------------------------* + lo_worksheet->set_cell( ip_row = 9 ip_column = 'C' ip_formula = 'SUM(C4:C8)' ). + + +*--------------------------------------------------------------------* +* Demonstrate standard EXCEL-behaviour when copying a formula to another cell +* by calculating the resulting formula to put into another cell +*--------------------------------------------------------------------* + DO 10 TIMES. + + lv_formula = zcl_excel_common=>shift_formula( iv_reference_formula = 'SUM(C4:C8)' + iv_shift_cols = 0 " Offset in Columns - here we copy in same column --> 0 + iv_shift_rows = sy-index ). " Offset in Row - here we copy downward --> sy-index + lv_row = 9 + sy-index. " Absolute row = sy-index rows below reference cell + lo_worksheet->set_cell( ip_row = lv_row ip_column = 'C' ip_formula = lv_formula ). + + ENDDO. + +*--------------------------------------------------------------------* +*** Create output +*--------------------------------------------------------------------* + lcl_output=>output( lo_excel ). + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL7 +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_excel7. + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + lo_style_conditional TYPE REF TO zcl_excel_style_conditional. + +DATA: ls_iconset3 TYPE zexcel_conditional_iconset, + ls_iconset4 TYPE zexcel_conditional_iconset, + ls_iconset5 TYPE zexcel_conditional_iconset. + +CONSTANTS: gc_save_file_name TYPE string VALUE '07_ConditionalAll.xlsx'. +INCLUDE zdemo_excel_outputopt_incl. + + +START-OF-SELECTION. + + CREATE OBJECT lo_excel. + + ls_iconset3-cfvo1_type = zcl_excel_style_conditional=>c_cfvo_type_percent. + ls_iconset3-cfvo1_value = '0'. + ls_iconset3-cfvo2_type = zcl_excel_style_conditional=>c_cfvo_type_percent. + ls_iconset3-cfvo2_value = '33'. + ls_iconset3-cfvo3_type = zcl_excel_style_conditional=>c_cfvo_type_percent. + ls_iconset3-cfvo3_value = '66'. + ls_iconset3-showvalue = zcl_excel_style_conditional=>c_showvalue_true. + + ls_iconset4-cfvo1_type = zcl_excel_style_conditional=>c_cfvo_type_percent. + ls_iconset4-cfvo1_value = '0'. + ls_iconset4-cfvo2_type = zcl_excel_style_conditional=>c_cfvo_type_percent. + ls_iconset4-cfvo2_value = '25'. + ls_iconset4-cfvo3_type = zcl_excel_style_conditional=>c_cfvo_type_percent. + ls_iconset4-cfvo3_value = '50'. + ls_iconset4-cfvo4_type = zcl_excel_style_conditional=>c_cfvo_type_percent. + ls_iconset4-cfvo4_value = '75'. + ls_iconset4-showvalue = zcl_excel_style_conditional=>c_showvalue_true. + + ls_iconset5-cfvo1_type = zcl_excel_style_conditional=>c_cfvo_type_percent. + ls_iconset5-cfvo1_value = '0'. + ls_iconset5-cfvo2_type = zcl_excel_style_conditional=>c_cfvo_type_percent. + ls_iconset5-cfvo2_value = '20'. + ls_iconset5-cfvo3_type = zcl_excel_style_conditional=>c_cfvo_type_percent. + ls_iconset5-cfvo3_value = '40'. + ls_iconset5-cfvo4_type = zcl_excel_style_conditional=>c_cfvo_type_percent. + ls_iconset5-cfvo4_value = '60'. + ls_iconset5-cfvo5_type = zcl_excel_style_conditional=>c_cfvo_type_percent. + ls_iconset5-cfvo5_value = '80'. + ls_iconset5-showvalue = zcl_excel_style_conditional=>c_showvalue_true. + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + + lo_style_conditional = lo_worksheet->add_new_conditional_style( ). + lo_style_conditional->rule = zcl_excel_style_conditional=>c_rule_iconset. + lo_style_conditional->priority = 1. + + ls_iconset3-iconset = zcl_excel_style_conditional=>c_iconset_3arrows. + + lo_style_conditional->mode_iconset = ls_iconset3. + lo_style_conditional->set_range( ip_start_column = 'B' + ip_start_row = 5 + ip_stop_column = 'B' + ip_stop_row = 9 ). + + lo_worksheet->set_cell( ip_row = 4 ip_column = 'B' ip_value = 'C_ICONSET_3ARROWS' ). + lo_worksheet->set_cell( ip_row = 5 ip_column = 'B' ip_value = 10 ). + lo_worksheet->set_cell( ip_row = 6 ip_column = 'B' ip_value = 20 ). + lo_worksheet->set_cell( ip_row = 7 ip_column = 'B' ip_value = 30 ). + lo_worksheet->set_cell( ip_row = 8 ip_column = 'B' ip_value = 40 ). + lo_worksheet->set_cell( ip_row = 9 ip_column = 'B' ip_value = 50 ). + + lo_style_conditional = lo_worksheet->add_new_conditional_style( ). + lo_style_conditional->rule = zcl_excel_style_conditional=>c_rule_iconset. + lo_style_conditional->priority = 1. + ls_iconset3-iconset = zcl_excel_style_conditional=>c_iconset_3arrowsgray. + lo_style_conditional->mode_iconset = ls_iconset3. + lo_style_conditional->set_range( ip_start_column = 'C' + ip_start_row = 5 + ip_stop_column = 'C' + ip_stop_row = 9 ). + + lo_worksheet->set_cell( ip_row = 4 ip_column = 'C' ip_value = 'C_ICONSET_3ARROWSGRAY' ). + lo_worksheet->set_cell( ip_row = 5 ip_column = 'C' ip_value = 10 ). + lo_worksheet->set_cell( ip_row = 6 ip_column = 'C' ip_value = 20 ). + lo_worksheet->set_cell( ip_row = 7 ip_column = 'C' ip_value = 30 ). + lo_worksheet->set_cell( ip_row = 8 ip_column = 'C' ip_value = 40 ). + lo_worksheet->set_cell( ip_row = 9 ip_column = 'C' ip_value = 50 ). + lo_style_conditional = lo_worksheet->add_new_conditional_style( ). + lo_style_conditional->rule = zcl_excel_style_conditional=>c_rule_iconset. + lo_style_conditional->priority = 1. + ls_iconset3-iconset = zcl_excel_style_conditional=>c_iconset_3flags. + lo_style_conditional->mode_iconset = ls_iconset3. + lo_style_conditional->set_range( ip_start_column = 'D' + ip_start_row = 5 + ip_stop_column = 'D' + ip_stop_row = 9 ). + + lo_worksheet->set_cell( ip_row = 4 ip_column = 'D' ip_value = 'C_ICONSET_3FLAGS' ). + lo_worksheet->set_cell( ip_row = 5 ip_column = 'D' ip_value = 10 ). + lo_worksheet->set_cell( ip_row = 6 ip_column = 'D' ip_value = 20 ). + lo_worksheet->set_cell( ip_row = 7 ip_column = 'D' ip_value = 30 ). + lo_worksheet->set_cell( ip_row = 8 ip_column = 'D' ip_value = 40 ). + lo_worksheet->set_cell( ip_row = 9 ip_column = 'D' ip_value = 50 ). + + lo_style_conditional = lo_worksheet->add_new_conditional_style( ). + lo_style_conditional->rule = zcl_excel_style_conditional=>c_rule_iconset. + lo_style_conditional->priority = 1. + ls_iconset3-iconset = zcl_excel_style_conditional=>c_iconset_3trafficlights. + lo_style_conditional->mode_iconset = ls_iconset3. + lo_style_conditional->set_range( ip_start_column = 'E' + ip_start_row = 5 + ip_stop_column = 'E' + ip_stop_row = 9 ). + + lo_worksheet->set_cell( ip_row = 4 ip_column = 'E' ip_value = 'C_ICONSET_3TRAFFICLIGHTS' ). + lo_worksheet->set_cell( ip_row = 5 ip_column = 'E' ip_value = 10 ). + lo_worksheet->set_cell( ip_row = 6 ip_column = 'E' ip_value = 20 ). + lo_worksheet->set_cell( ip_row = 7 ip_column = 'E' ip_value = 30 ). + lo_worksheet->set_cell( ip_row = 8 ip_column = 'E' ip_value = 40 ). + lo_worksheet->set_cell( ip_row = 9 ip_column = 'E' ip_value = 50 ). + + lo_style_conditional = lo_worksheet->add_new_conditional_style( ). + lo_style_conditional->rule = zcl_excel_style_conditional=>c_rule_iconset. + lo_style_conditional->priority = 1. + ls_iconset3-iconset = zcl_excel_style_conditional=>c_iconset_3trafficlights2. + lo_style_conditional->mode_iconset = ls_iconset3. + lo_style_conditional->set_range( ip_start_column = 'F' + ip_start_row = 5 + ip_stop_column = 'F' + ip_stop_row = 9 ). + + lo_worksheet->set_cell( ip_row = 4 ip_column = 'F' ip_value = 'C_ICONSET_3TRAFFICLIGHTS2' ). + lo_worksheet->set_cell( ip_row = 5 ip_column = 'F' ip_value = 10 ). + lo_worksheet->set_cell( ip_row = 6 ip_column = 'F' ip_value = 20 ). + lo_worksheet->set_cell( ip_row = 7 ip_column = 'F' ip_value = 30 ). + lo_worksheet->set_cell( ip_row = 8 ip_column = 'F' ip_value = 40 ). + lo_worksheet->set_cell( ip_row = 9 ip_column = 'F' ip_value = 50 ). + + lo_style_conditional = lo_worksheet->add_new_conditional_style( ). + lo_style_conditional->rule = zcl_excel_style_conditional=>c_rule_iconset. + lo_style_conditional->priority = 1. + ls_iconset3-iconset = zcl_excel_style_conditional=>c_iconset_3signs. + lo_style_conditional->mode_iconset = ls_iconset3. + lo_style_conditional->set_range( ip_start_column = 'G' + ip_start_row = 5 + ip_stop_column = 'G' + ip_stop_row = 9 ). + + lo_worksheet->set_cell( ip_row = 4 ip_column = 'G' ip_value = 'C_ICONSET_3SIGNS' ). + lo_worksheet->set_cell( ip_row = 5 ip_column = 'G' ip_value = 10 ). + lo_worksheet->set_cell( ip_row = 6 ip_column = 'G' ip_value = 20 ). + lo_worksheet->set_cell( ip_row = 7 ip_column = 'G' ip_value = 30 ). + lo_worksheet->set_cell( ip_row = 8 ip_column = 'G' ip_value = 40 ). + lo_worksheet->set_cell( ip_row = 9 ip_column = 'G' ip_value = 50 ). + + lo_style_conditional = lo_worksheet->add_new_conditional_style( ). + lo_style_conditional->rule = zcl_excel_style_conditional=>c_rule_iconset. + lo_style_conditional->priority = 1. + ls_iconset3-iconset = zcl_excel_style_conditional=>c_iconset_3symbols. + lo_style_conditional->mode_iconset = ls_iconset3. + lo_style_conditional->set_range( ip_start_column = 'H' + ip_start_row = 5 + ip_stop_column = 'H' + ip_stop_row = 9 ). + + lo_worksheet->set_cell( ip_row = 4 ip_column = 'H' ip_value = 'C_ICONSET_3SYMBOLS' ). + lo_worksheet->set_cell( ip_row = 5 ip_column = 'H' ip_value = 10 ). + lo_worksheet->set_cell( ip_row = 6 ip_column = 'H' ip_value = 20 ). + lo_worksheet->set_cell( ip_row = 7 ip_column = 'H' ip_value = 30 ). + lo_worksheet->set_cell( ip_row = 8 ip_column = 'H' ip_value = 40 ). + lo_worksheet->set_cell( ip_row = 9 ip_column = 'H' ip_value = 50 ). + + lo_style_conditional = lo_worksheet->add_new_conditional_style( ). + lo_style_conditional->rule = zcl_excel_style_conditional=>c_rule_iconset. + lo_style_conditional->priority = 1. + ls_iconset3-iconset = zcl_excel_style_conditional=>c_iconset_3symbols2. + lo_style_conditional->mode_iconset = ls_iconset3. + lo_style_conditional->set_range( ip_start_column = 'I' + ip_start_row = 5 + ip_stop_column = 'I' + ip_stop_row = 9 ). + + lo_worksheet->set_cell( ip_row = 4 ip_column = 'I' ip_value = 'C_ICONSET_3SYMBOLS2' ). + lo_worksheet->set_cell( ip_row = 5 ip_column = 'I' ip_value = 10 ). + lo_worksheet->set_cell( ip_row = 6 ip_column = 'I' ip_value = 20 ). + lo_worksheet->set_cell( ip_row = 7 ip_column = 'I' ip_value = 30 ). + lo_worksheet->set_cell( ip_row = 8 ip_column = 'I' ip_value = 40 ). + lo_worksheet->set_cell( ip_row = 9 ip_column = 'I' ip_value = 50 ). + + lo_style_conditional = lo_worksheet->add_new_conditional_style( ). + lo_style_conditional->rule = zcl_excel_style_conditional=>c_rule_iconset. + lo_style_conditional->priority = 1. + ls_iconset4-iconset = zcl_excel_style_conditional=>c_iconset_4arrows. + lo_style_conditional->mode_iconset = ls_iconset4. + lo_style_conditional->set_range( ip_start_column = 'B' + ip_start_row = 12 + ip_stop_column = 'B' + ip_stop_row = 16 ). + + lo_worksheet->set_cell( ip_row = 11 ip_column = 'B' ip_value = 'C_ICONSET_4ARROWS' ). + lo_worksheet->set_cell( ip_row = 12 ip_column = 'B' ip_value = 10 ). + lo_worksheet->set_cell( ip_row = 13 ip_column = 'B' ip_value = 20 ). + lo_worksheet->set_cell( ip_row = 14 ip_column = 'B' ip_value = 30 ). + lo_worksheet->set_cell( ip_row = 15 ip_column = 'B' ip_value = 40 ). + lo_worksheet->set_cell( ip_row = 16 ip_column = 'B' ip_value = 50 ). + + lo_style_conditional = lo_worksheet->add_new_conditional_style( ). + lo_style_conditional->rule = zcl_excel_style_conditional=>c_rule_iconset. + lo_style_conditional->priority = 1. + ls_iconset4-iconset = zcl_excel_style_conditional=>c_iconset_4arrowsgray. + lo_style_conditional->mode_iconset = ls_iconset4. + lo_style_conditional->set_range( ip_start_column = 'C' + ip_start_row = 12 + ip_stop_column = 'C' + ip_stop_row = 16 ). + + lo_worksheet->set_cell( ip_row = 11 ip_column = 'C' ip_value = 'C_ICONSET_4ARROWSGRAY' ). + lo_worksheet->set_cell( ip_row = 12 ip_column = 'C' ip_value = 10 ). + lo_worksheet->set_cell( ip_row = 13 ip_column = 'C' ip_value = 20 ). + lo_worksheet->set_cell( ip_row = 14 ip_column = 'C' ip_value = 30 ). + lo_worksheet->set_cell( ip_row = 15 ip_column = 'C' ip_value = 40 ). + lo_worksheet->set_cell( ip_row = 16 ip_column = 'C' ip_value = 50 ). + + lo_style_conditional = lo_worksheet->add_new_conditional_style( ). + lo_style_conditional->rule = zcl_excel_style_conditional=>c_rule_iconset. + lo_style_conditional->priority = 1. + ls_iconset4-iconset = zcl_excel_style_conditional=>c_iconset_4redtoblack. + lo_style_conditional->mode_iconset = ls_iconset4. + lo_style_conditional->set_range( ip_start_column = 'D' + ip_start_row = 12 + ip_stop_column = 'D' + ip_stop_row = 16 ). + + lo_worksheet->set_cell( ip_row = 11 ip_column = 'D' ip_value = 'C_ICONSET_4REDTOBLACK' ). + lo_worksheet->set_cell( ip_row = 12 ip_column = 'D' ip_value = 10 ). + lo_worksheet->set_cell( ip_row = 13 ip_column = 'D' ip_value = 20 ). + lo_worksheet->set_cell( ip_row = 14 ip_column = 'D' ip_value = 30 ). + lo_worksheet->set_cell( ip_row = 15 ip_column = 'D' ip_value = 40 ). + lo_worksheet->set_cell( ip_row = 16 ip_column = 'D' ip_value = 50 ). + + lo_style_conditional = lo_worksheet->add_new_conditional_style( ). + lo_style_conditional->rule = zcl_excel_style_conditional=>c_rule_iconset. + lo_style_conditional->priority = 1. + ls_iconset4-iconset = zcl_excel_style_conditional=>c_iconset_4rating. + lo_style_conditional->mode_iconset = ls_iconset4. + lo_style_conditional->set_range( ip_start_column = 'E' + ip_start_row = 12 + ip_stop_column = 'E' + ip_stop_row = 16 ). + + lo_worksheet->set_cell( ip_row = 11 ip_column = 'E' ip_value = 'C_ICONSET_4RATING' ). + lo_worksheet->set_cell( ip_row = 12 ip_column = 'E' ip_value = 10 ). + lo_worksheet->set_cell( ip_row = 13 ip_column = 'E' ip_value = 20 ). + lo_worksheet->set_cell( ip_row = 14 ip_column = 'E' ip_value = 30 ). + lo_worksheet->set_cell( ip_row = 15 ip_column = 'E' ip_value = 40 ). + lo_worksheet->set_cell( ip_row = 16 ip_column = 'E' ip_value = 50 ). + + lo_style_conditional = lo_worksheet->add_new_conditional_style( ). + lo_style_conditional->rule = zcl_excel_style_conditional=>c_rule_iconset. + lo_style_conditional->priority = 1. + ls_iconset4-iconset = zcl_excel_style_conditional=>c_iconset_4trafficlights. + lo_style_conditional->mode_iconset = ls_iconset4. + lo_style_conditional->set_range( ip_start_column = 'F' + ip_start_row = 12 + ip_stop_column = 'F' + ip_stop_row = 16 ). + + lo_worksheet->set_cell( ip_row = 11 ip_column = 'F' ip_value = 'C_ICONSET_4TRAFFICLIGHTS' ). + lo_worksheet->set_cell( ip_row = 12 ip_column = 'F' ip_value = 10 ). + lo_worksheet->set_cell( ip_row = 13 ip_column = 'F' ip_value = 20 ). + lo_worksheet->set_cell( ip_row = 14 ip_column = 'F' ip_value = 30 ). + lo_worksheet->set_cell( ip_row = 15 ip_column = 'F' ip_value = 40 ). + lo_worksheet->set_cell( ip_row = 16 ip_column = 'F' ip_value = 50 ). + + lo_style_conditional = lo_worksheet->add_new_conditional_style( ). + lo_style_conditional->rule = zcl_excel_style_conditional=>c_rule_iconset. + lo_style_conditional->priority = 1. + ls_iconset5-iconset = zcl_excel_style_conditional=>c_iconset_5arrows. + lo_style_conditional->mode_iconset = ls_iconset5. + lo_style_conditional->set_range( ip_start_column = 'B' + ip_start_row = 19 + ip_stop_column = 'B' + ip_stop_row = 23 ). + + lo_worksheet->set_cell( ip_row = 18 ip_column = 'B' ip_value = 'C_ICONSET_5ARROWS' ). + lo_worksheet->set_cell( ip_row = 19 ip_column = 'B' ip_value = 10 ). + lo_worksheet->set_cell( ip_row = 20 ip_column = 'B' ip_value = 20 ). + lo_worksheet->set_cell( ip_row = 21 ip_column = 'B' ip_value = 30 ). + lo_worksheet->set_cell( ip_row = 22 ip_column = 'B' ip_value = 40 ). + lo_worksheet->set_cell( ip_row = 23 ip_column = 'B' ip_value = 50 ). + + lo_style_conditional = lo_worksheet->add_new_conditional_style( ). + lo_style_conditional->rule = zcl_excel_style_conditional=>c_rule_iconset. + lo_style_conditional->priority = 1. + ls_iconset5-iconset = zcl_excel_style_conditional=>c_iconset_5arrowsgray. + lo_style_conditional->mode_iconset = ls_iconset5. + lo_style_conditional->set_range( ip_start_column = 'C' + ip_start_row = 19 + ip_stop_column = 'C' + ip_stop_row = 23 ). + + lo_worksheet->set_cell( ip_row = 18 ip_column = 'C' ip_value = 'C_ICONSET_5ARROWSGRAY' ). + lo_worksheet->set_cell( ip_row = 19 ip_column = 'C' ip_value = 10 ). + lo_worksheet->set_cell( ip_row = 20 ip_column = 'C' ip_value = 20 ). + lo_worksheet->set_cell( ip_row = 21 ip_column = 'C' ip_value = 30 ). + lo_worksheet->set_cell( ip_row = 22 ip_column = 'C' ip_value = 40 ). + lo_worksheet->set_cell( ip_row = 23 ip_column = 'C' ip_value = 50 ). + + lo_style_conditional = lo_worksheet->add_new_conditional_style( ). + lo_style_conditional->rule = zcl_excel_style_conditional=>c_rule_iconset. + lo_style_conditional->priority = 1. + ls_iconset5-iconset = zcl_excel_style_conditional=>c_iconset_5rating. + lo_style_conditional->mode_iconset = ls_iconset5. + lo_style_conditional->set_range( ip_start_column = 'D' + ip_start_row = 19 + ip_stop_column = 'D' + ip_stop_row = 23 ). + + lo_worksheet->set_cell( ip_row = 18 ip_column = 'D' ip_value = 'C_ICONSET_5RATING' ). + lo_worksheet->set_cell( ip_row = 19 ip_column = 'D' ip_value = 10 ). + lo_worksheet->set_cell( ip_row = 20 ip_column = 'D' ip_value = 20 ). + lo_worksheet->set_cell( ip_row = 21 ip_column = 'D' ip_value = 30 ). + lo_worksheet->set_cell( ip_row = 22 ip_column = 'D' ip_value = 40 ). + lo_worksheet->set_cell( ip_row = 23 ip_column = 'D' ip_value = 50 ). + + lo_style_conditional = lo_worksheet->add_new_conditional_style( ). + lo_style_conditional->rule = zcl_excel_style_conditional=>c_rule_iconset. + lo_style_conditional->priority = 1. + ls_iconset5-iconset = zcl_excel_style_conditional=>c_iconset_5quarters. + lo_style_conditional->mode_iconset = ls_iconset5. + lo_style_conditional->set_range( ip_start_column = 'E' + ip_start_row = 19 + ip_stop_column = 'E' + ip_stop_row = 23 ). + + lo_worksheet->set_cell( ip_row = 18 ip_column = 'E' ip_value = 'C_ICONSET_5QUARTERS' ). + lo_worksheet->set_cell( ip_row = 19 ip_column = 'E' ip_value = 10 ). + lo_worksheet->set_cell( ip_row = 20 ip_column = 'E' ip_value = 20 ). + lo_worksheet->set_cell( ip_row = 21 ip_column = 'E' ip_value = 30 ). + lo_worksheet->set_cell( ip_row = 22 ip_column = 'E' ip_value = 40 ). + lo_worksheet->set_cell( ip_row = 23 ip_column = 'E' ip_value = 50 ). + + +*** Create output + lcl_output=>output( lo_excel ). + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL8 +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_excel8. + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + lo_range TYPE REF TO zcl_excel_range. + +DATA: lv_title TYPE zexcel_sheet_title. + +CONSTANTS: gc_save_file_name TYPE string VALUE '08_Range.xlsx'. +INCLUDE zdemo_excel_outputopt_incl. + + +START-OF-SELECTION. + + CREATE OBJECT lo_excel. + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + lv_title = 'Sheet1'. + lo_worksheet->set_title( lv_title ). + lo_range = lo_excel->add_new_range( ). + lo_range->name = 'range'. + lo_range->set_value( ip_sheet_name = lv_title + ip_start_column = 'C' + ip_start_row = 4 + ip_stop_column = 'C' + ip_stop_row = 8 ). + + + lo_worksheet->set_cell( ip_row = 4 ip_column = 'C' ip_value = 'Apple' ). + lo_worksheet->set_cell( ip_row = 5 ip_column = 'C' ip_value = 'Banana' ). + lo_worksheet->set_cell( ip_row = 6 ip_column = 'C' ip_value = 'Blueberry' ). + lo_worksheet->set_cell( ip_row = 7 ip_column = 'C' ip_value = 'Ananas' ). + lo_worksheet->set_cell( ip_row = 8 ip_column = 'C' ip_value = 'Grapes' ). + + " Define another Range with a name longer than 40 characters that + " tests the fix of issue #168 ranges namescan be only up to 20 chars + + lo_range = lo_excel->add_new_range( ). + lo_range->name = 'A_range_with_a_name_that_is_longer_than_20_characters'. + lo_range->set_value( ip_sheet_name = lv_title + ip_start_column = 'D' + ip_start_row = 4 + ip_stop_column = 'D' + ip_stop_row = 5 ). + lo_worksheet->set_cell( ip_row = 4 ip_column = 'D' ip_value = 'Range Value 1' ). + lo_worksheet->set_cell( ip_row = 5 ip_column = 'D' ip_value = 'Range Value 2' ). + + " issue #163 + " Define another Range with sheet visibility + lo_range = lo_worksheet->add_new_range( ). + lo_range->name = 'A_range_with_sheet_visibility'. + lo_range->set_value( ip_sheet_name = lv_title + ip_start_column = 'E' + ip_start_row = 4 + ip_stop_column = 'E' + ip_stop_row = 5 ). + lo_worksheet->set_cell( ip_row = 4 ip_column = 'E' ip_value = 'Range Value 3' ). + lo_worksheet->set_cell( ip_row = 5 ip_column = 'E' ip_value = 'Range Value 4' ). + " issue #163 + +*** Create output + lcl_output=>output( lo_excel ). + + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL9 +*& +*&---------------------------------------------------------------------* +*& abap2xlsx Demo: Data validations +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_excel9. + +CONSTANTS: c_fruits TYPE string VALUE 'Fruits', + c_vegetables TYPE string VALUE 'Vegetables', + c_meat TYPE string VALUE 'Meat', + c_fish TYPE string VALUE 'Fish'. + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + lo_range TYPE REF TO zcl_excel_range, + lo_data_validation TYPE REF TO zcl_excel_data_validation. + +DATA: row TYPE zexcel_cell_row. + + +DATA: lv_title TYPE zexcel_sheet_title. + + +CONSTANTS: gc_save_file_name TYPE string VALUE '09_DataValidation.xlsx'. +INCLUDE zdemo_excel_outputopt_incl. + +PARAMETERS: p_sbook TYPE flag. + + +START-OF-SELECTION. + + " Creates active sheet + CREATE OBJECT lo_excel. + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + lv_title = 'Data Validation'. + lo_worksheet->set_title( lv_title ). + " Set values for dropdown + lo_worksheet->set_cell( ip_row = 2 ip_column = 'A' ip_value = c_fish ). + lo_worksheet->set_cell( ip_row = 4 ip_column = 'A' ip_value = 'Anchovy' ). + lo_worksheet->set_cell( ip_row = 5 ip_column = 'A' ip_value = 'Carp' ). + lo_worksheet->set_cell( ip_row = 6 ip_column = 'A' ip_value = 'Catfish' ). + lo_worksheet->set_cell( ip_row = 7 ip_column = 'A' ip_value = 'Cod' ). + lo_worksheet->set_cell( ip_row = 8 ip_column = 'A' ip_value = 'Eel' ). + lo_worksheet->set_cell( ip_row = 9 ip_column = 'A' ip_value = 'Haddock' ). + + lo_range = lo_excel->add_new_range( ). + lo_range->name = c_fish. + lo_range->set_value( ip_sheet_name = lv_title + ip_start_column = 'A' + ip_start_row = 4 + ip_stop_column = 'A' + ip_stop_row = 9 ). + + lo_worksheet->set_cell( ip_row = 2 ip_column = 'B' ip_value = c_meat ). + lo_worksheet->set_cell( ip_row = 4 ip_column = 'B' ip_value = 'Pork' ). + lo_worksheet->set_cell( ip_row = 5 ip_column = 'B' ip_value = 'Beef' ). + lo_worksheet->set_cell( ip_row = 6 ip_column = 'B' ip_value = 'Chicken' ). + lo_worksheet->set_cell( ip_row = 7 ip_column = 'B' ip_value = 'Turkey' ). + + lo_range = lo_excel->add_new_range( ). + lo_range->name = c_meat. + lo_range->set_value( ip_sheet_name = lv_title + ip_start_column = 'B' + ip_start_row = 4 + ip_stop_column = 'B' + ip_stop_row = 7 ). + + lo_worksheet->set_cell( ip_row = 2 ip_column = 'C' ip_value = c_fruits ). + lo_worksheet->set_cell( ip_row = 4 ip_column = 'C' ip_value = 'Apple' ). + lo_worksheet->set_cell( ip_row = 5 ip_column = 'C' ip_value = 'Banana' ). + lo_worksheet->set_cell( ip_row = 6 ip_column = 'C' ip_value = 'Blueberry' ). + lo_worksheet->set_cell( ip_row = 7 ip_column = 'C' ip_value = 'Ananas' ). + lo_worksheet->set_cell( ip_row = 8 ip_column = 'C' ip_value = 'Grapes' ). + + lo_range = lo_excel->add_new_range( ). + lo_range->name = c_fruits. + lo_range->set_value( ip_sheet_name = lv_title + ip_start_column = 'C' + ip_start_row = 4 + ip_stop_column = 'C' + ip_stop_row = 8 ). + + lo_worksheet->set_cell( ip_row = 2 ip_column = 'D' ip_value = c_vegetables ). + lo_worksheet->set_cell( ip_row = 4 ip_column = 'D' ip_value = 'Cucumber' ). + lo_worksheet->set_cell( ip_row = 5 ip_column = 'D' ip_value = 'Sweet pepper ' ). + lo_worksheet->set_cell( ip_row = 6 ip_column = 'D' ip_value = 'Lettuce' ). + + lo_range = lo_excel->add_new_range( ). + lo_range->name = c_vegetables. + lo_range->set_value( ip_sheet_name = lv_title + ip_start_column = 'D' + ip_start_row = 4 + ip_stop_column = 'D' + ip_stop_row = 6 ). + + lo_worksheet = lo_excel->add_new_worksheet( ). + lv_title = 'Table with Data Validation'. + lo_worksheet->set_title( lv_title ). + + " Maximum Text length + lo_worksheet->set_cell( ip_row = 1 ip_column = 'A' ip_value = 'Validate Maximum Text length of <= 10 in Cell A2:' ). + lo_worksheet->set_cell( ip_row = 2 ip_column = 'A' ip_value = 'abcdefghij' ). + lo_data_validation = lo_worksheet->add_new_data_validation( ). + lo_data_validation->type = zcl_excel_data_validation=>c_type_textlength. + lo_data_validation->operator = zcl_excel_data_validation=>c_operator_lessthanorequal. + lo_data_validation->formula1 = 10. + lo_data_validation->cell_row = 2. + lo_data_validation->cell_column = 'A'. + + " Integer Value between 1 and 10 + lo_worksheet->set_cell( ip_row = 4 ip_column = 'A' ip_value = 'Validate Integer Value between 1 and 10 in Cell A5:' ). + lo_worksheet->set_cell( ip_row = 5 ip_column = 'A' ip_value = '5' ). + lo_data_validation = lo_worksheet->add_new_data_validation( ). + lo_data_validation->type = zcl_excel_data_validation=>c_type_whole. + lo_data_validation->operator = zcl_excel_data_validation=>c_operator_between. + lo_data_validation->formula1 = 1. + lo_data_validation->formula2 = 10. + lo_data_validation->prompttitle = 'Range'. + lo_data_validation->prompt = 'Enter a value between 1 and 10'. + lo_data_validation->errortitle = 'Error'. + lo_data_validation->error = 'You have entered a wrong value. Please use only numbers between 1 and 10.'. + lo_data_validation->cell_row = 5. + lo_data_validation->cell_column = 'A'. + + " Evaluation by Formula from issue #161 + lo_worksheet->set_cell( ip_row = 7 ip_column = 'A' ip_value = 'Validate if B8 contains a "-":' ). + lo_worksheet->set_cell( ip_row = 8 ip_column = 'A' ip_value = 'Text' ). + lo_worksheet->set_cell( ip_row = 8 ip_column = 'B' ip_value = '-' ). + lo_data_validation = lo_worksheet->add_new_data_validation( ). + lo_data_validation->type = zcl_excel_data_validation=>c_type_custom. + lo_data_validation->formula1 = '"IF(B8<>"""";INDIRECT(LEFT(B8;SEARCH(""-"";B8;1)));EMPTY)"'. + lo_data_validation->cell_row = 8. + lo_data_validation->cell_column = 'A'. + + " There was an error when data validation was combined with cell merges this should test that: + lo_worksheet->set_cell( ip_row = 10 ip_column = 'A' ip_value = 'Demo for data validation with a dropdown list' ). + lo_worksheet->set_merge( ip_row = 10 ip_column_start = 'A' ip_column_end = 'F' ). + + " Headlines + lo_worksheet->set_cell( ip_row = 11 ip_column = 'A' ip_value = c_fruits ). + lo_worksheet->set_cell( ip_row = 11 ip_column = 'B' ip_value = c_vegetables ). + + row = 12. + WHILE row < 20. " Starting with 14500 the data validation is dropped 14000 are still ok + " 1st validation + lo_data_validation = lo_worksheet->add_new_data_validation( ). + lo_data_validation->type = zcl_excel_data_validation=>c_type_list. + lo_data_validation->formula1 = c_fruits. + lo_data_validation->cell_row = row. + lo_data_validation->cell_column = 'A'. + lo_worksheet->set_cell( ip_row = row ip_column = 'A' ip_value = 'Select a value' ). + " 2nd + lo_data_validation = lo_worksheet->add_new_data_validation( ). + lo_data_validation->type = zcl_excel_data_validation=>c_type_list. + lo_data_validation->formula1 = c_vegetables. + lo_data_validation->cell_row = row. + lo_data_validation->cell_column = 'B'. + lo_worksheet->set_cell( ip_row = row ip_column = 'B' ip_value = 'Select a value' ). + " 3rd + lo_data_validation = lo_worksheet->add_new_data_validation( ). + lo_data_validation->type = zcl_excel_data_validation=>c_type_list. + lo_data_validation->formula1 = c_meat. + lo_data_validation->cell_row = row. + lo_data_validation->cell_column = 'C'. + lo_worksheet->set_cell( ip_row = row ip_column = 'C' ip_value = 'Select a value' ). + " 4th + lo_data_validation = lo_worksheet->add_new_data_validation( ). + lo_data_validation->type = zcl_excel_data_validation=>c_type_list. + lo_data_validation->formula1 = c_fish. + lo_data_validation->cell_row = row. + lo_data_validation->cell_column = 'D'. + lo_worksheet->set_cell( ip_row = row ip_column = 'D' ip_value = 'Select a value' ). + " Increment row + row = row + 1. + ENDWHILE. + + IF p_sbook = abap_true. + DATA: bookings type TABLE OF sbook. + + lo_worksheet = lo_excel->add_new_worksheet( ). + lv_title = 'SBOOK'. + lo_worksheet->set_title( lv_title ). + + SELECT * from sbook INTO TABLE bookings UP TO 4000 ROWS. + + lo_worksheet->bind_table( + EXPORTING + ip_table = bookings +* it_field_catalog = " Table binding field catalog +* is_table_settings = " Excel table binding settings +* IMPORTING +* es_table_settings = " Excel table binding settings + ). + ENDIF. + + +*** Create output + lcl_output=>output( lo_excel ). + + + + + + + + *&---------------------------------------------------------------------* +*& Include ZDEMO_EXCEL_OUTPUTOPT_INCL +*&---------------------------------------------------------------------* +CLASS lcl_output DEFINITION CREATE PRIVATE. + PUBLIC SECTION. + CLASS-METHODS: output IMPORTING cl_excel TYPE REF TO zcl_excel, + f4_path RETURNING value(selected_folder) TYPE string, + parametertexts. + + PRIVATE SECTION. + METHODS: download_frontend, + download_backend, + display_online, + send_email. + + DATA: xdata TYPE xstring, " Will be used for sending as email + t_rawdata TYPE solix_tab, " Will be used for downloading or open directly + bytecount TYPE i. " Will be used for downloading or open directly +ENDCLASS. "lcl_output DEFINITION + + +SELECTION-SCREEN BEGIN OF BLOCK bl1 WITH FRAME TITLE txt_bl1. +PARAMETERS: rb_down RADIOBUTTON GROUP rb1 DEFAULT 'X' USER-COMMAND space. + +PARAMETERS: rb_back RADIOBUTTON GROUP rb1. + +PARAMETERS: rb_show RADIOBUTTON GROUP rb1. + +PARAMETERS: rb_send RADIOBUTTON GROUP rb1. + +PARAMETERS: p_path TYPE string LOWER CASE MODIF ID pat. +PARAMETERS: p_email TYPE string LOWER CASE MODIF ID ema. +PARAMETERS: p_backfn TYPE text40 NO-DISPLAY. +SELECTION-SCREEN END OF BLOCK bl1. + + +AT SELECTION-SCREEN OUTPUT. + LOOP AT SCREEN. + + IF rb_down IS INITIAL AND screen-group1 = 'PAT'. + screen-input = 0. + screen-invisible = 1. + ENDIF. + + IF rb_send IS INITIAL AND screen-group1 = 'EMA'. + screen-input = 0. + screen-invisible = 1. + ENDIF. + + MODIFY SCREEN. + + ENDLOOP. + +INITIALIZATION. + IF sy-batch IS INITIAL. + cl_gui_frontend_services=>get_sapgui_workdir( CHANGING sapworkdir = p_path ). + cl_gui_cfw=>flush( ). + ENDIF. + lcl_output=>parametertexts( ). " If started in language w/o textelements translated set defaults + sy-title = gc_save_file_name. + txt_bl1 = 'Output options'(bl1). + p_backfn = gc_save_file_name. " Use as default if nothing else is supplied by submit + +AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path. + p_path = lcl_output=>f4_path( ). + + +*----------------------------------------------------------------------* +* CLASS lcl_output IMPLEMENTATION +*----------------------------------------------------------------------* +CLASS lcl_output IMPLEMENTATION. + METHOD output. + + DATA: cl_output TYPE REF TO lcl_output, + cl_writer TYPE REF TO zif_excel_writer. + + CREATE OBJECT cl_output. + CREATE OBJECT cl_writer TYPE zcl_excel_writer_2007. + cl_output->xdata = cl_writer->write_file( cl_excel ). + +* After 6.40 via cl_bcs_convert + cl_output->t_rawdata = cl_bcs_convert=>xstring_to_solix( iv_xstring = cl_output->xdata ). + cl_output->bytecount = xstrlen( cl_output->xdata ). + +* before 6.40 +* CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' +* EXPORTING +* buffer = cl_output->xdata +* IMPORTING +* output_length = cl_output->bytecount +* TABLES +* binary_tab = cl_output->t_rawdata. + + CASE 'X'. + WHEN rb_down. + IF sy-batch IS INITIAL. + cl_output->download_frontend( ). + ELSE. + MESSAGE e001(00) WITH 'Frontenddownload impossible in background processing'. + ENDIF. + + WHEN rb_back. + cl_output->download_backend( ). + + WHEN rb_show. + IF sy-batch IS INITIAL. + cl_output->display_online( ). + ELSE. + MESSAGE e001(00) WITH 'Online display absurd in background processing'. + ENDIF. + + WHEN rb_send. + cl_output->send_email( ). + + ENDCASE. + ENDMETHOD. "output + + METHOD f4_path. + DATA: new_path TYPE string, + repid TYPE syrepid, + dynnr TYPE sydynnr, + lt_dynpfields TYPE TABLE OF dynpread, + ls_dynpfields LIKE LINE OF lt_dynpfields. + +* Get current value + dynnr = sy-dynnr. + repid = sy-repid. + ls_dynpfields-fieldname = 'P_PATH'. + APPEND ls_dynpfields TO lt_dynpfields. + + CALL FUNCTION 'DYNP_VALUES_READ' + EXPORTING + dyname = repid + dynumb = dynnr + TABLES + dynpfields = lt_dynpfields + EXCEPTIONS + invalid_abapworkarea = 1 + invalid_dynprofield = 2 + invalid_dynproname = 3 + invalid_dynpronummer = 4 + invalid_request = 5 + no_fielddescription = 6 + invalid_parameter = 7 + undefind_error = 8 + double_conversion = 9 + stepl_not_found = 10 + OTHERS = 11. + IF sy-subrc <> 0. + MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno + WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. + EXIT. + ENDIF. + + READ TABLE lt_dynpfields INTO ls_dynpfields INDEX 1. + + new_path = ls_dynpfields-fieldvalue. + selected_folder = new_path. + + cl_gui_frontend_services=>directory_browse( + EXPORTING + window_title = 'Select path to download EXCEL-file' + initial_folder = new_path + CHANGING + selected_folder = new_path + EXCEPTIONS + cntl_error = 1 + error_no_gui = 2 + not_supported_by_gui = 3 + OTHERS = 4 + ). + cl_gui_cfw=>flush( ). + CHECK new_path IS NOT INITIAL. + selected_folder = new_path. + + ENDMETHOD. "f4_path + + METHOD parametertexts. +* If started in language w/o textelements translated set defaults +* Furthermore I don't have to change the selectiontexts of all demoreports. + DEFINE default_parametertext. + if %_&1_%_app_%-text = '&1' or + %_&1_%_app_%-text is initial. + %_&1_%_app_%-text = &2. + endif. + END-OF-DEFINITION. + + default_parametertext: rb_down 'Save to frontend', + rb_back 'Save to backend', + rb_show 'Direct display', + rb_send 'Send via email', + + p_path 'Frontend-path to download to', + p_email 'Email to send xlsx to'. + + ENDMETHOD. "parametertexts + + METHOD: download_frontend. + DATA: filename TYPE string. +* I don't like p_path here - but for this include it's ok + filename = p_path. +* Add trailing "\" or "/" + IF filename CA '/'. + REPLACE REGEX '([^/])\s*$' IN filename WITH '$1/' . + ELSE. + REPLACE REGEX '([^\\])\s*$' IN filename WITH '$1\\'. + ENDIF. + + CONCATENATE filename gc_save_file_name INTO filename. +* Get trailing blank + cl_gui_frontend_services=>gui_download( EXPORTING bin_filesize = bytecount + filename = filename + filetype = 'BIN' + CHANGING data_tab = t_rawdata ). + ENDMETHOD. "download_frontend + + METHOD download_backend. + DATA: bytes_remain TYPE i. + FIELD-SYMBOLS: <rawdata> LIKE LINE OF t_rawdata. + + OPEN DATASET p_backfn FOR OUTPUT IN BINARY MODE. + CHECK sy-subrc = 0. + + bytes_remain = bytecount. + + LOOP AT t_rawdata ASSIGNING <rawdata>. + + AT LAST. + CHECK bytes_remain >= 0. + TRANSFER <rawdata> TO p_backfn LENGTH bytes_remain. + EXIT. + ENDAT. + + TRANSFER <rawdata> TO p_backfn. + SUBTRACT 255 FROM bytes_remain. " Solix hat Länge 255 + + ENDLOOP. + + CLOSE DATASET p_backfn. + + + + + IF sy-calld = 'X'. " no need to display anything if download was selected and report was called for demo purposes + LEAVE PROGRAM. + ELSE. + MESSAGE 'Data transferred to default backend directory' TYPE 'I'. + ENDIF. + ENDMETHOD. "download_backend + + METHOD display_online. + 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,"OIContainerCtrl + cl_document TYPE REF TO i_oi_document_proxy. "Office Dokument + + 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 = cl_gui_container=>screen0 + 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 + + cl_document->open_document_from_table( EXPORTING document_size = bytecount + document_table = t_rawdata + open_inplace = 'X' ). + + WRITE: '.'. " To create an output. That way screen0 will exist + ENDMETHOD. "display_online + + METHOD send_email. +* Needed to send emails + DATA: bcs_exception TYPE REF TO cx_bcs, + errortext TYPE string, + cl_send_request TYPE REF TO cl_bcs, + cl_document TYPE REF TO cl_document_bcs, + cl_recipient TYPE REF TO if_recipient_bcs, + cl_sender TYPE REF TO cl_cam_address_bcs, + t_attachment_header TYPE soli_tab, + wa_attachment_header LIKE LINE OF t_attachment_header, + attachment_subject TYPE sood-objdes, + + sood_bytecount TYPE sood-objlen, + mail_title TYPE so_obj_des, + t_mailtext TYPE soli_tab, + wa_mailtext LIKE LINE OF t_mailtext, + send_to TYPE adr6-smtp_addr, + sent TYPE os_boolean. + + + mail_title = 'Mail title'. + wa_mailtext = 'Mailtext'. + APPEND wa_mailtext TO t_mailtext. + + TRY. +* Create send request + cl_send_request = cl_bcs=>create_persistent( ). +* Create new document with mailtitle and mailtextg + cl_document = cl_document_bcs=>create_document( i_type = 'RAW' "#EC NOTEXT + i_text = t_mailtext + i_subject = mail_title ). +* Add attachment to document +* since the new excelfiles have an 4-character extension .xlsx but the attachment-type only holds 3 charactes .xls, +* we have to specify the real filename via attachment header +* Use attachment_type xls to have SAP display attachment with the excel-icon + attachment_subject = gc_save_file_name. + CONCATENATE '&SO_FILENAME=' attachment_subject INTO wa_attachment_header. + APPEND wa_attachment_header TO t_attachment_header. +* Attachment + sood_bytecount = bytecount. " next method expects sood_bytecount instead of any positive integer *sigh* + cl_document->add_attachment( i_attachment_type = 'XLS' "#EC NOTEXT + i_attachment_subject = attachment_subject + i_attachment_size = sood_bytecount + i_att_content_hex = t_rawdata + i_attachment_header = t_attachment_header ). + +* add document to send request + cl_send_request->set_document( cl_document ). + +* set sender in case if no own email is availabe +* cl_sender = cl_cam_address_bcs=>create_internet_address( 'sender@sender.sender' ). +* cl_send_request->set_sender( cl_sender ). + +* add recipient(s) - here only 1 will be needed + send_to = p_email. + IF send_to IS INITIAL. + send_to = 'no_email@no_email.no_email'. " Place into SOST in any case for demonstration purposes + ENDIF. + cl_recipient = cl_cam_address_bcs=>create_internet_address( send_to ). + cl_send_request->add_recipient( cl_recipient ). + +* Und abschicken + sent = cl_send_request->send( i_with_error_screen = 'X' ). + + COMMIT WORK. + + IF sent IS INITIAL. + MESSAGE i500(sbcoms) WITH p_email. + ELSE. + MESSAGE s022(so). + MESSAGE 'Document ready to be sent - Check SOST or SCOT' TYPE 'I'. + ENDIF. + + CATCH cx_bcs INTO bcs_exception. + errortext = bcs_exception->if_message~get_text( ). + MESSAGE errortext TYPE 'I'. + + ENDTRY. + ENDMETHOD. "send_email + + +ENDCLASS. "lcl_output IMPLEMENTATION + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_TECHED1 +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_teched1. + +******************************* +* Data Object declaration * +******************************* + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_excel_writer TYPE REF TO zif_excel_writer, + lo_worksheet TYPE REF TO zcl_excel_worksheet. + +DATA: lv_file TYPE xstring, + lv_bytecount TYPE i, + lt_file_tab TYPE solix_tab. + +DATA: lv_full_path TYPE string, + lv_workdir TYPE string, + lv_file_separator TYPE c. + +CONSTANTS: lv_default_file_name TYPE string VALUE 'TechEd01.xlsx'. + +******************************* +* Selection screen management * +******************************* + +PARAMETERS: p_path TYPE zexcel_export_dir. + +AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path. + lv_workdir = p_path. + cl_gui_frontend_services=>directory_browse( EXPORTING initial_folder = lv_workdir + CHANGING selected_folder = lv_workdir ). + p_path = lv_workdir. + +INITIALIZATION. + cl_gui_frontend_services=>get_sapgui_workdir( CHANGING sapworkdir = lv_workdir ). + cl_gui_cfw=>flush( ). + p_path = lv_workdir. + +START-OF-SELECTION. + + IF p_path IS INITIAL. + p_path = lv_workdir. + ENDIF. + cl_gui_frontend_services=>get_file_separator( CHANGING file_separator = lv_file_separator ). + CONCATENATE p_path lv_file_separator lv_default_file_name INTO lv_full_path. + + +******************************* +* abap2xlsx create XLSX * +******************************* + + " Create excel instance + CREATE OBJECT lo_excel. + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( ip_title = 'Demo01' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = 'Hello world' ). + + " Create xlsx stream + CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007. + lv_file = lo_excel_writer->write_file( lo_excel ). + +******************************* +* Output * +******************************* + + " Convert to binary + lt_file_tab = cl_bcs_convert=>xstring_to_solix( iv_xstring = lv_file ). + lv_bytecount = xstrlen( lv_file ). + + " Save the file + cl_gui_frontend_services=>gui_download( EXPORTING bin_filesize = lv_bytecount + filename = lv_full_path + filetype = 'BIN' + CHANGING data_tab = lt_file_tab ). + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_TECHED3 +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_teched3. + +******************************* +* Data Object declaration * +******************************* + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_excel_reader TYPE REF TO zif_excel_reader, + lo_worksheet TYPE REF TO zcl_excel_worksheet. + +DATA: lv_full_path TYPE string, + lv_workdir TYPE string, + lv_file_separator TYPE c. + +DATA: lt_files TYPE filetable, + ls_file TYPE file_table, + lv_rc TYPE i, + lv_value TYPE zexcel_cell_value. + +CONSTANTS: gc_save_file_name TYPE string VALUE 'TechEd01.xlsx'. +INCLUDE zdemo_excel_outputopt_incl. + +START-OF-SELECTION. + +******************************* +* abap2xlsx read XLSX * +******************************* + CREATE OBJECT lo_excel_reader TYPE zcl_excel_reader_2007. + lo_excel = lo_excel_reader->load_file( lv_full_path ). + + lo_excel->set_active_sheet_index( 1 ). + lo_worksheet = lo_excel->get_active_worksheet( ). + + lo_worksheet->get_cell( EXPORTING ip_column = 'C' + ip_row = 10 + IMPORTING ep_value = lv_value ). + + WRITE: 'abap2xlsx total score is ', lv_value. + +*** Create output + lcl_output=>output( lo_excel ). + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_TECHED2 +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_teched2. + +******************************* +* Data Object declaration * +******************************* + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_excel_writer TYPE REF TO zif_excel_writer, + lo_worksheet TYPE REF TO zcl_excel_worksheet. + +DATA: lo_style_title TYPE REF TO zcl_excel_style, + lv_style_title_guid TYPE zexcel_cell_style. + +DATA: lv_file TYPE xstring, + lv_bytecount TYPE i, + lt_file_tab TYPE solix_tab. + +DATA: lv_full_path TYPE string, + lv_workdir TYPE string, + lv_file_separator TYPE c. + +CONSTANTS: lv_default_file_name TYPE string VALUE 'TechEd01.xlsx'. + +******************************* +* Selection screen management * +******************************* + +PARAMETERS: p_path TYPE zexcel_export_dir. + +AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path. + lv_workdir = p_path. + cl_gui_frontend_services=>directory_browse( EXPORTING initial_folder = lv_workdir + CHANGING selected_folder = lv_workdir ). + p_path = lv_workdir. + +INITIALIZATION. + cl_gui_frontend_services=>get_sapgui_workdir( CHANGING sapworkdir = lv_workdir ). + cl_gui_cfw=>flush( ). + p_path = lv_workdir. + +START-OF-SELECTION. + + IF p_path IS INITIAL. + p_path = lv_workdir. + ENDIF. + cl_gui_frontend_services=>get_file_separator( CHANGING file_separator = lv_file_separator ). + CONCATENATE p_path lv_file_separator lv_default_file_name INTO lv_full_path. + +******************************* +* abap2xlsx create XLSX * +******************************* + + " Create excel instance + CREATE OBJECT lo_excel. + + " Styles + lo_style_title = lo_excel->add_new_style( ). + lo_style_title->font->bold = abap_true. + lo_style_title->font->color-rgb = zcl_excel_style_color=>c_blue. + lv_style_title_guid = lo_style_title->get_guid( ). + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( ip_title = 'Demo TechEd' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 5 ip_value = 'TechEd demo' ip_style = lv_style_title_guid ). + + " Create xlsx stream + CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007. + lv_file = lo_excel_writer->write_file( lo_excel ). + +******************************* +* Output * +******************************* + + " Convert to binary + lt_file_tab = cl_bcs_convert=>xstring_to_solix( iv_xstring = lv_file ). + lv_bytecount = xstrlen( lv_file ). + + " Save the file + cl_gui_frontend_services=>gui_download( EXPORTING bin_filesize = lv_bytecount + filename = lv_full_path + filetype = 'BIN' + CHANGING data_tab = lt_file_tab ). + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_TECHED3 +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_teched3. + +******************************* +* Data Object declaration * +******************************* + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_excel_writer TYPE REF TO zif_excel_writer, + lo_worksheet TYPE REF TO zcl_excel_worksheet. + +DATA: lo_style_title TYPE REF TO zcl_excel_style, + lo_drawing TYPE REF TO zcl_excel_drawing, + lv_style_title_guid TYPE zexcel_cell_style, + ls_key TYPE wwwdatatab. + +DATA: lv_file TYPE xstring, + lv_bytecount TYPE i, + lt_file_tab TYPE solix_tab. + +DATA: lv_full_path TYPE string, + lv_workdir TYPE string, + lv_file_separator TYPE c. + +CONSTANTS: lv_default_file_name TYPE string VALUE 'TechEd01.xlsx'. + +******************************* +* Selection screen management * +******************************* + +PARAMETERS: p_path TYPE zexcel_export_dir. + +AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path. + lv_workdir = p_path. + cl_gui_frontend_services=>directory_browse( EXPORTING initial_folder = lv_workdir + CHANGING selected_folder = lv_workdir ). + p_path = lv_workdir. + +INITIALIZATION. + cl_gui_frontend_services=>get_sapgui_workdir( CHANGING sapworkdir = lv_workdir ). + cl_gui_cfw=>flush( ). + p_path = lv_workdir. + +START-OF-SELECTION. + + IF p_path IS INITIAL. + p_path = lv_workdir. + ENDIF. + cl_gui_frontend_services=>get_file_separator( CHANGING file_separator = lv_file_separator ). + CONCATENATE p_path lv_file_separator lv_default_file_name INTO lv_full_path. + +******************************* +* abap2xlsx create XLSX * +******************************* + + " Create excel instance + CREATE OBJECT lo_excel. + + " Styles + lo_style_title = lo_excel->add_new_style( ). + lo_style_title->font->bold = abap_true. + lo_style_title->font->color-rgb = zcl_excel_style_color=>c_blue. + lv_style_title_guid = lo_style_title->get_guid( ). + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( ip_title = 'Demo TechEd' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 5 ip_value = 'TechEd demo' ip_style = lv_style_title_guid ). + + " add logo from SMWO + lo_drawing = lo_excel->add_new_drawing( ). + lo_drawing->set_position( ip_from_row = 2 + ip_from_col = 'B' ). + + ls_key-relid = 'MI'. + ls_key-objid = 'WBLOGO'. + lo_drawing->set_media_www( ip_key = ls_key + ip_width = 140 + ip_height = 64 ). + + " assign drawing to the worksheet + lo_worksheet->add_drawing( lo_drawing ). + + " Create xlsx stream + CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007. + lv_file = lo_excel_writer->write_file( lo_excel ). + +******************************* +* Output * +******************************* + + " Convert to binary + lt_file_tab = cl_bcs_convert=>xstring_to_solix( iv_xstring = lv_file ). + lv_bytecount = xstrlen( lv_file ). + + " Save the file + cl_gui_frontend_services=>gui_download( EXPORTING bin_filesize = lv_bytecount + filename = lv_full_path + filetype = 'BIN' + CHANGING data_tab = lt_file_tab ). + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_TECHED3 +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_teched3. + +******************************* +* Data Object declaration * +******************************* + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_excel_writer TYPE REF TO zif_excel_writer, + lo_worksheet TYPE REF TO zcl_excel_worksheet. + +DATA: lo_style_title TYPE REF TO zcl_excel_style, + lo_drawing TYPE REF TO zcl_excel_drawing, + lo_range TYPE REF TO zcl_excel_range, + lv_style_title_guid TYPE zexcel_cell_style, + ls_key TYPE wwwdatatab. + +DATA: lv_file TYPE xstring, + lv_bytecount TYPE i, + lt_file_tab TYPE solix_tab. + +DATA: lv_full_path TYPE string, + lv_workdir TYPE string, + lv_file_separator TYPE c. + +CONSTANTS: lv_default_file_name TYPE string VALUE 'TechEd01.xlsx'. + +******************************* +* Selection screen management * +******************************* + +PARAMETERS: p_path TYPE zexcel_export_dir. + +AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path. + lv_workdir = p_path. + cl_gui_frontend_services=>directory_browse( EXPORTING initial_folder = lv_workdir + CHANGING selected_folder = lv_workdir ). + p_path = lv_workdir. + +INITIALIZATION. + cl_gui_frontend_services=>get_sapgui_workdir( CHANGING sapworkdir = lv_workdir ). + cl_gui_cfw=>flush( ). + p_path = lv_workdir. + +START-OF-SELECTION. + + IF p_path IS INITIAL. + p_path = lv_workdir. + ENDIF. + cl_gui_frontend_services=>get_file_separator( CHANGING file_separator = lv_file_separator ). + CONCATENATE p_path lv_file_separator lv_default_file_name INTO lv_full_path. + +******************************* +* abap2xlsx create XLSX * +******************************* + + " Create excel instance + CREATE OBJECT lo_excel. + + " Styles + lo_style_title = lo_excel->add_new_style( ). + lo_style_title->font->bold = abap_true. + lo_style_title->font->color-rgb = zcl_excel_style_color=>c_blue. + lv_style_title_guid = lo_style_title->get_guid( ). + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( ip_title = 'Demo TechEd' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 5 ip_value = 'TechEd demo' ip_style = lv_style_title_guid ). + + " add logo from SMWO + lo_drawing = lo_excel->add_new_drawing( ). + lo_drawing->set_position( ip_from_row = 2 + ip_from_col = 'B' ). + + ls_key-relid = 'MI'. + ls_key-objid = 'WBLOGO'. + lo_drawing->set_media_www( ip_key = ls_key + ip_width = 140 + ip_height = 64 ). + + " assign drawing to the worksheet + lo_worksheet->add_drawing( lo_drawing ). + + " Add new sheet + lo_worksheet = lo_excel->add_new_worksheet( ). + lo_worksheet->set_title( ip_title = 'Values' ). + + " Set values for range + lo_worksheet->set_cell( ip_row = 4 ip_column = 'A' ip_value = 1 ). + lo_worksheet->set_cell( ip_row = 5 ip_column = 'A' ip_value = 2 ). + lo_worksheet->set_cell( ip_row = 6 ip_column = 'A' ip_value = 3 ). + lo_worksheet->set_cell( ip_row = 7 ip_column = 'A' ip_value = 4 ). + lo_worksheet->set_cell( ip_row = 8 ip_column = 'A' ip_value = 5 ). + + lo_range = lo_excel->add_new_range( ). + lo_range->name = 'Values'. + lo_range->set_value( ip_sheet_name = 'Values' + ip_start_column = 'A' + ip_start_row = 4 + ip_stop_column = 'A' + ip_stop_row = 8 ). + + lo_excel->set_active_sheet_index( 1 ). + + " Create xlsx stream + CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007. + lv_file = lo_excel_writer->write_file( lo_excel ). + +******************************* +* Output * +******************************* + + " Convert to binary + lt_file_tab = cl_bcs_convert=>xstring_to_solix( iv_xstring = lv_file ). + lv_bytecount = xstrlen( lv_file ). + + " Save the file + cl_gui_frontend_services=>gui_download( EXPORTING bin_filesize = lv_bytecount + filename = lv_full_path + filetype = 'BIN' + CHANGING data_tab = lt_file_tab ). + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_TECHED3 +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_teched3. + +******************************* +* Data Object declaration * +******************************* + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_excel_writer TYPE REF TO zif_excel_writer, + lo_worksheet TYPE REF TO zcl_excel_worksheet. + +DATA: lo_style_title TYPE REF TO zcl_excel_style, + lo_drawing TYPE REF TO zcl_excel_drawing, + lo_range TYPE REF TO zcl_excel_range, + lo_data_validation TYPE REF TO zcl_excel_data_validation, + lv_style_title_guid TYPE zexcel_cell_style, + ls_key TYPE wwwdatatab. + +DATA: lv_file TYPE xstring, + lv_bytecount TYPE i, + lt_file_tab TYPE solix_tab. + +DATA: lv_full_path TYPE string, + lv_workdir TYPE string, + lv_file_separator TYPE c. + +CONSTANTS: lv_default_file_name TYPE string VALUE 'TechEd01.xlsx'. + +******************************* +* Selection screen management * +******************************* + +PARAMETERS: p_path TYPE zexcel_export_dir. + +AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path. + lv_workdir = p_path. + cl_gui_frontend_services=>directory_browse( EXPORTING initial_folder = lv_workdir + CHANGING selected_folder = lv_workdir ). + p_path = lv_workdir. + +INITIALIZATION. + cl_gui_frontend_services=>get_sapgui_workdir( CHANGING sapworkdir = lv_workdir ). + cl_gui_cfw=>flush( ). + p_path = lv_workdir. + +START-OF-SELECTION. + + IF p_path IS INITIAL. + p_path = lv_workdir. + ENDIF. + cl_gui_frontend_services=>get_file_separator( CHANGING file_separator = lv_file_separator ). + CONCATENATE p_path lv_file_separator lv_default_file_name INTO lv_full_path. + +******************************* +* abap2xlsx create XLSX * +******************************* + + " Create excel instance + CREATE OBJECT lo_excel. + + " Styles + lo_style_title = lo_excel->add_new_style( ). + lo_style_title->font->bold = abap_true. + lo_style_title->font->color-rgb = zcl_excel_style_color=>c_blue. + lv_style_title_guid = lo_style_title->get_guid( ). + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( ip_title = 'Demo TechEd' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 5 ip_value = 'TechEd demo' ip_style = lv_style_title_guid ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 7 ip_value = 'Is abap2xlsx simple' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 8 ip_value = 'Is abap2xlsx CooL' ). + + " add logo from SMWO + lo_drawing = lo_excel->add_new_drawing( ). + lo_drawing->set_position( ip_from_row = 2 + ip_from_col = 'B' ). + + ls_key-relid = 'MI'. + ls_key-objid = 'WBLOGO'. + lo_drawing->set_media_www( ip_key = ls_key + ip_width = 140 + ip_height = 64 ). + + " assign drawing to the worksheet + lo_worksheet->add_drawing( lo_drawing ). + + " Add new sheet + lo_worksheet = lo_excel->add_new_worksheet( ). + lo_worksheet->set_title( ip_title = 'Values' ). + + " Set values for range + lo_worksheet->set_cell( ip_row = 4 ip_column = 'A' ip_value = 1 ). + lo_worksheet->set_cell( ip_row = 5 ip_column = 'A' ip_value = 2 ). + lo_worksheet->set_cell( ip_row = 6 ip_column = 'A' ip_value = 3 ). + lo_worksheet->set_cell( ip_row = 7 ip_column = 'A' ip_value = 4 ). + lo_worksheet->set_cell( ip_row = 8 ip_column = 'A' ip_value = 5 ). + + lo_range = lo_excel->add_new_range( ). + lo_range->name = 'Values'. + lo_range->set_value( ip_sheet_name = 'Values' + ip_start_column = 'A' + ip_start_row = 4 + ip_stop_column = 'A' + ip_stop_row = 8 ). + + lo_excel->set_active_sheet_index( 1 ). + + " add data validation + lo_worksheet = lo_excel->get_active_worksheet( ). + + lo_data_validation = lo_worksheet->add_new_data_validation( ). + lo_data_validation->type = zcl_excel_data_validation=>c_type_list. + lo_data_validation->formula1 = 'Values'. + lo_data_validation->cell_row = 7. + lo_data_validation->cell_column = 'C'. + lo_worksheet->set_cell( ip_row = 7 ip_column = 'C' ip_value = 'Select a value' ). + + + lo_data_validation = lo_worksheet->add_new_data_validation( ). + lo_data_validation->type = zcl_excel_data_validation=>c_type_list. + lo_data_validation->formula1 = 'Values'. + lo_data_validation->cell_row = 8. + lo_data_validation->cell_column = 'C'. + lo_worksheet->set_cell( ip_row = 8 ip_column = 'C' ip_value = 'Select a value' ). + + " Create xlsx stream + CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007. + lv_file = lo_excel_writer->write_file( lo_excel ). + +******************************* +* Output * +******************************* + + " Convert to binary + lt_file_tab = cl_bcs_convert=>xstring_to_solix( iv_xstring = lv_file ). + lv_bytecount = xstrlen( lv_file ). + + " Save the file + cl_gui_frontend_services=>gui_download( EXPORTING bin_filesize = lv_bytecount + filename = lv_full_path + filetype = 'BIN' + CHANGING data_tab = lt_file_tab ). + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_TECHED3 +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_teched3. + +******************************* +* Data Object declaration * +******************************* + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_excel_writer TYPE REF TO zif_excel_writer, + lo_worksheet TYPE REF TO zcl_excel_worksheet. + +DATA: lo_style_title TYPE REF TO zcl_excel_style, + lo_drawing TYPE REF TO zcl_excel_drawing, + lo_range TYPE REF TO zcl_excel_range, + lo_data_validation TYPE REF TO zcl_excel_data_validation, + lo_column_dimension TYPE REF TO zcl_excel_worksheet_columndime, + lv_style_title_guid TYPE zexcel_cell_style, + ls_key TYPE wwwdatatab. + +DATA: lv_file TYPE xstring, + lv_bytecount TYPE i, + lt_file_tab TYPE solix_tab. + +DATA: lv_full_path TYPE string, + lv_workdir TYPE string, + lv_file_separator TYPE c. + +CONSTANTS: lv_default_file_name TYPE string VALUE 'TechEd01.xlsx'. + +******************************* +* Selection screen management * +******************************* + +PARAMETERS: p_path TYPE zexcel_export_dir. + +AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path. + lv_workdir = p_path. + cl_gui_frontend_services=>directory_browse( EXPORTING initial_folder = lv_workdir + CHANGING selected_folder = lv_workdir ). + p_path = lv_workdir. + +INITIALIZATION. + cl_gui_frontend_services=>get_sapgui_workdir( CHANGING sapworkdir = lv_workdir ). + cl_gui_cfw=>flush( ). + p_path = lv_workdir. + +START-OF-SELECTION. + + IF p_path IS INITIAL. + p_path = lv_workdir. + ENDIF. + cl_gui_frontend_services=>get_file_separator( CHANGING file_separator = lv_file_separator ). + CONCATENATE p_path lv_file_separator lv_default_file_name INTO lv_full_path. + +******************************* +* abap2xlsx create XLSX * +******************************* + + " Create excel instance + CREATE OBJECT lo_excel. + + " Styles + lo_style_title = lo_excel->add_new_style( ). + lo_style_title->font->bold = abap_true. + lo_style_title->font->color-rgb = zcl_excel_style_color=>c_blue. + lv_style_title_guid = lo_style_title->get_guid( ). + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( ip_title = 'Demo TechEd' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 5 ip_value = 'TechEd demo' ip_style = lv_style_title_guid ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 7 ip_value = 'Is abap2xlsx simple' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 8 ip_value = 'Is abap2xlsx CooL' ). + + " add logo from SMWO + lo_drawing = lo_excel->add_new_drawing( ). + lo_drawing->set_position( ip_from_row = 2 + ip_from_col = 'B' ). + + ls_key-relid = 'MI'. + ls_key-objid = 'WBLOGO'. + lo_drawing->set_media_www( ip_key = ls_key + ip_width = 140 + ip_height = 64 ). + + " assign drawing to the worksheet + lo_worksheet->add_drawing( lo_drawing ). + + " Add new sheet + lo_worksheet = lo_excel->add_new_worksheet( ). + lo_worksheet->set_title( ip_title = 'Values' ). + + " Set values for range + lo_worksheet->set_cell( ip_row = 4 ip_column = 'A' ip_value = 1 ). + lo_worksheet->set_cell( ip_row = 5 ip_column = 'A' ip_value = 2 ). + lo_worksheet->set_cell( ip_row = 6 ip_column = 'A' ip_value = 3 ). + lo_worksheet->set_cell( ip_row = 7 ip_column = 'A' ip_value = 4 ). + lo_worksheet->set_cell( ip_row = 8 ip_column = 'A' ip_value = 5 ). + + lo_range = lo_excel->add_new_range( ). + lo_range->name = 'Values'. + lo_range->set_value( ip_sheet_name = 'Values' + ip_start_column = 'A' + ip_start_row = 4 + ip_stop_column = 'A' + ip_stop_row = 8 ). + + lo_excel->set_active_sheet_index( 1 ). + + " add data validation + lo_worksheet = lo_excel->get_active_worksheet( ). + + lo_data_validation = lo_worksheet->add_new_data_validation( ). + lo_data_validation->type = zcl_excel_data_validation=>c_type_list. + lo_data_validation->formula1 = 'Values'. + lo_data_validation->cell_row = 7. + lo_data_validation->cell_column = 'C'. + lo_worksheet->set_cell( ip_row = 7 ip_column = 'C' ip_value = 'Select a value' ). + + + lo_data_validation = lo_worksheet->add_new_data_validation( ). + lo_data_validation->type = zcl_excel_data_validation=>c_type_list. + lo_data_validation->formula1 = 'Values'. + lo_data_validation->cell_row = 8. + lo_data_validation->cell_column = 'C'. + lo_worksheet->set_cell( ip_row = 8 ip_column = 'C' ip_value = 'Select a value' ). + + " add autosize (column width) + lo_column_dimension = lo_worksheet->get_column_dimension( ip_column = 'B' ). + lo_column_dimension->set_auto_size( ip_auto_size = abap_true ). + lo_column_dimension = lo_worksheet->get_column_dimension( ip_column = 'C' ). + lo_column_dimension->set_auto_size( ip_auto_size = abap_true ). + + " Create xlsx stream + CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007. + lv_file = lo_excel_writer->write_file( lo_excel ). + +******************************* +* Output * +******************************* + + " Convert to binary + lt_file_tab = cl_bcs_convert=>xstring_to_solix( iv_xstring = lv_file ). + lv_bytecount = xstrlen( lv_file ). + + " Save the file + cl_gui_frontend_services=>gui_download( EXPORTING bin_filesize = lv_bytecount + filename = lv_full_path + filetype = 'BIN' + CHANGING data_tab = lt_file_tab ). + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_TECHED3 +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_teched3. + +******************************* +* Data Object declaration * +******************************* + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_excel_writer TYPE REF TO zif_excel_writer, + lo_worksheet TYPE REF TO zcl_excel_worksheet. + +DATA: lo_style_title TYPE REF TO zcl_excel_style, + lo_drawing TYPE REF TO zcl_excel_drawing, + lo_range TYPE REF TO zcl_excel_range, + lo_data_validation TYPE REF TO zcl_excel_data_validation, + lo_column_dimension TYPE REF TO zcl_excel_worksheet_columndime, + lv_style_title_guid TYPE zexcel_cell_style, + ls_key TYPE wwwdatatab. + +DATA: lv_file TYPE xstring, + lv_bytecount TYPE i, + lt_file_tab TYPE solix_tab. + +DATA: lv_full_path TYPE string, + lv_workdir TYPE string, + lv_file_separator TYPE c. + +CONSTANTS: lv_default_file_name TYPE string VALUE 'TechEd01.xlsx'. + +******************************* +* Selection screen management * +******************************* + +PARAMETERS: p_path TYPE zexcel_export_dir. + +AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path. + lv_workdir = p_path. + cl_gui_frontend_services=>directory_browse( EXPORTING initial_folder = lv_workdir + CHANGING selected_folder = lv_workdir ). + p_path = lv_workdir. + +INITIALIZATION. + cl_gui_frontend_services=>get_sapgui_workdir( CHANGING sapworkdir = lv_workdir ). + cl_gui_cfw=>flush( ). + p_path = lv_workdir. + +START-OF-SELECTION. + + IF p_path IS INITIAL. + p_path = lv_workdir. + ENDIF. + cl_gui_frontend_services=>get_file_separator( CHANGING file_separator = lv_file_separator ). + CONCATENATE p_path lv_file_separator lv_default_file_name INTO lv_full_path. + +******************************* +* abap2xlsx create XLSX * +******************************* + + " Create excel instance + CREATE OBJECT lo_excel. + + " Styles + lo_style_title = lo_excel->add_new_style( ). + lo_style_title->font->bold = abap_true. + lo_style_title->font->color-rgb = zcl_excel_style_color=>c_blue. + lv_style_title_guid = lo_style_title->get_guid( ). + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( ip_title = 'Demo TechEd' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 5 ip_value = 'TechEd demo' ip_style = lv_style_title_guid ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 7 ip_value = 'Is abap2xlsx simple' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 8 ip_value = 'Is abap2xlsx CooL' ). + + lo_worksheet->set_cell( ip_column = 'B' ip_row = 10 ip_value = 'Total score' ). + lo_worksheet->set_cell( ip_column = 'C' ip_row = 10 ip_formula = 'SUM(C7:C8)' ). + + " add logo from SMWO + lo_drawing = lo_excel->add_new_drawing( ). + lo_drawing->set_position( ip_from_row = 2 + ip_from_col = 'B' ). + + ls_key-relid = 'MI'. + ls_key-objid = 'WBLOGO'. + lo_drawing->set_media_www( ip_key = ls_key + ip_width = 140 + ip_height = 64 ). + + " assign drawing to the worksheet + lo_worksheet->add_drawing( lo_drawing ). + + " Add new sheet + lo_worksheet = lo_excel->add_new_worksheet( ). + lo_worksheet->set_title( ip_title = 'Values' ). + + " Set values for range + lo_worksheet->set_cell( ip_row = 4 ip_column = 'A' ip_value = 1 ). + lo_worksheet->set_cell( ip_row = 5 ip_column = 'A' ip_value = 2 ). + lo_worksheet->set_cell( ip_row = 6 ip_column = 'A' ip_value = 3 ). + lo_worksheet->set_cell( ip_row = 7 ip_column = 'A' ip_value = 4 ). + lo_worksheet->set_cell( ip_row = 8 ip_column = 'A' ip_value = 5 ). + + lo_range = lo_excel->add_new_range( ). + lo_range->name = 'Values'. + lo_range->set_value( ip_sheet_name = 'Values' + ip_start_column = 'A' + ip_start_row = 4 + ip_stop_column = 'A' + ip_stop_row = 8 ). + + lo_excel->set_active_sheet_index( 1 ). + + " add data validation + lo_worksheet = lo_excel->get_active_worksheet( ). + + lo_data_validation = lo_worksheet->add_new_data_validation( ). + lo_data_validation->type = zcl_excel_data_validation=>c_type_list. + lo_data_validation->formula1 = 'Values'. + lo_data_validation->cell_row = 7. + lo_data_validation->cell_column = 'C'. + lo_worksheet->set_cell( ip_row = 7 ip_column = 'C' ip_value = 'Select a value' ). + + + lo_data_validation = lo_worksheet->add_new_data_validation( ). + lo_data_validation->type = zcl_excel_data_validation=>c_type_list. + lo_data_validation->formula1 = 'Values'. + lo_data_validation->cell_row = 8. + lo_data_validation->cell_column = 'C'. + lo_worksheet->set_cell( ip_row = 8 ip_column = 'C' ip_value = 'Select a value' ). + + " add autosize (column width) + lo_column_dimension = lo_worksheet->get_column_dimension( ip_column = 'B' ). + lo_column_dimension->set_auto_size( ip_auto_size = abap_true ). + lo_column_dimension = lo_worksheet->get_column_dimension( ip_column = 'C' ). + lo_column_dimension->set_auto_size( ip_auto_size = abap_true ). + + " Create xlsx stream + CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007. + lv_file = lo_excel_writer->write_file( lo_excel ). + +******************************* +* Output * +******************************* + + " Convert to binary + lt_file_tab = cl_bcs_convert=>xstring_to_solix( iv_xstring = lv_file ). + lv_bytecount = xstrlen( lv_file ). + + " Save the file + cl_gui_frontend_services=>gui_download( EXPORTING bin_filesize = lv_bytecount + filename = lv_full_path + filetype = 'BIN' + CHANGING data_tab = lt_file_tab ). + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_TECHED3 +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_teched3. + +******************************* +* Data Object declaration * +******************************* + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_excel_writer TYPE REF TO zif_excel_writer, + lo_worksheet TYPE REF TO zcl_excel_worksheet. + +DATA: lo_style_title TYPE REF TO zcl_excel_style, + lo_style_green TYPE REF TO zcl_excel_style, + lo_style_yellow TYPE REF TO zcl_excel_style, + lo_style_red TYPE REF TO zcl_excel_style, + lo_drawing TYPE REF TO zcl_excel_drawing, + lo_range TYPE REF TO zcl_excel_range, + lo_data_validation TYPE REF TO zcl_excel_data_validation, + lo_column_dimension TYPE REF TO zcl_excel_worksheet_columndime, + lo_style_conditional TYPE REF TO zcl_excel_style_conditional, + lv_style_title_guid TYPE zexcel_cell_style, + lv_style_green_guid TYPE zexcel_cell_style, + lv_style_yellow_guid TYPE zexcel_cell_style, + lv_style_red_guid TYPE zexcel_cell_style, + ls_cellis TYPE zexcel_conditional_cellis, + ls_key TYPE wwwdatatab. + +DATA: lv_file TYPE xstring, + lv_bytecount TYPE i, + lt_file_tab TYPE solix_tab. + +DATA: lv_full_path TYPE string, + lv_workdir TYPE string, + lv_file_separator TYPE c. + +CONSTANTS: lv_default_file_name TYPE string VALUE 'TechEd01.xlsx'. + +******************************* +* Selection screen management * +******************************* + +PARAMETERS: p_path TYPE zexcel_export_dir. + +AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path. + lv_workdir = p_path. + cl_gui_frontend_services=>directory_browse( EXPORTING initial_folder = lv_workdir + CHANGING selected_folder = lv_workdir ). + p_path = lv_workdir. + +INITIALIZATION. + cl_gui_frontend_services=>get_sapgui_workdir( CHANGING sapworkdir = lv_workdir ). + cl_gui_cfw=>flush( ). + p_path = lv_workdir. + +START-OF-SELECTION. + + IF p_path IS INITIAL. + p_path = lv_workdir. + ENDIF. + cl_gui_frontend_services=>get_file_separator( CHANGING file_separator = lv_file_separator ). + CONCATENATE p_path lv_file_separator lv_default_file_name INTO lv_full_path. + +******************************* +* abap2xlsx create XLSX * +******************************* + + " Create excel instance + CREATE OBJECT lo_excel. + + " Styles + lo_style_title = lo_excel->add_new_style( ). + lo_style_title->font->bold = abap_true. + lo_style_title->font->color-rgb = zcl_excel_style_color=>c_blue. + lv_style_title_guid = lo_style_title->get_guid( ). + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( ip_title = 'Demo TechEd' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 5 ip_value = 'TechEd demo' ip_style = lv_style_title_guid ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 7 ip_value = 'Is abap2xlsx simple' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 8 ip_value = 'Is abap2xlsx CooL' ). + + lo_worksheet->set_cell( ip_column = 'B' ip_row = 10 ip_value = 'Total score' ). + lo_worksheet->set_cell( ip_column = 'C' ip_row = 10 ip_formula = 'SUM(C7:C8)' ). + + " add logo from SMWO + lo_drawing = lo_excel->add_new_drawing( ). + lo_drawing->set_position( ip_from_row = 2 + ip_from_col = 'B' ). + +* ls_key-relid = 'MI'. +* ls_key-objid = 'WBLOGO'. +* lo_drawing->set_media_www( ip_key = ls_key +* ip_width = 140 +* ip_height = 64 ). + + " assign drawing to the worksheet + lo_worksheet->add_drawing( lo_drawing ). + + " Add new sheet + lo_worksheet = lo_excel->add_new_worksheet( ). + lo_worksheet->set_title( ip_title = 'Values' ). + + " Set values for range + lo_worksheet->set_cell( ip_row = 4 ip_column = 'A' ip_value = 1 ). + lo_worksheet->set_cell( ip_row = 5 ip_column = 'A' ip_value = 2 ). + lo_worksheet->set_cell( ip_row = 6 ip_column = 'A' ip_value = 3 ). + lo_worksheet->set_cell( ip_row = 7 ip_column = 'A' ip_value = 4 ). + lo_worksheet->set_cell( ip_row = 8 ip_column = 'A' ip_value = 5 ). + + lo_range = lo_excel->add_new_range( ). + lo_range->name = 'Values'. + lo_range->set_value( ip_sheet_name = 'Values' + ip_start_column = 'A' + ip_start_row = 4 + ip_stop_column = 'A' + ip_stop_row = 8 ). + + lo_excel->set_active_sheet_index( 1 ). + + " add data validation + lo_worksheet = lo_excel->get_active_worksheet( ). + + lo_data_validation = lo_worksheet->add_new_data_validation( ). + lo_data_validation->type = zcl_excel_data_validation=>c_type_list. + lo_data_validation->formula1 = 'Values'. + lo_data_validation->cell_row = 7. + lo_data_validation->cell_column = 'C'. + lo_worksheet->set_cell( ip_row = 7 ip_column = 'C' ip_value = 'Select a value' ). + + + lo_data_validation = lo_worksheet->add_new_data_validation( ). + lo_data_validation->type = zcl_excel_data_validation=>c_type_list. + lo_data_validation->formula1 = 'Values'. + lo_data_validation->cell_row = 8. + lo_data_validation->cell_column = 'C'. + lo_worksheet->set_cell( ip_row = 8 ip_column = 'C' ip_value = 'Select a value' ). + + " add autosize (column width) + lo_column_dimension = lo_worksheet->get_column_dimension( ip_column = 'B' ). + lo_column_dimension->set_auto_size( ip_auto_size = abap_true ). + lo_column_dimension = lo_worksheet->get_column_dimension( ip_column = 'C' ). + lo_column_dimension->set_auto_size( ip_auto_size = abap_true ). + + " defne conditional styles + lo_style_green = lo_excel->add_new_style( ). + lo_style_green->fill->filltype = zcl_excel_style_fill=>c_fill_solid. + lo_style_green->fill->bgcolor-rgb = zcl_excel_style_color=>c_green. + lv_style_green_guid = lo_style_green->get_guid( ). + + lo_style_yellow = lo_excel->add_new_style( ). + lo_style_yellow->fill->filltype = zcl_excel_style_fill=>c_fill_solid. + lo_style_yellow->fill->bgcolor-rgb = zcl_excel_style_color=>c_yellow. + lv_style_yellow_guid = lo_style_yellow->get_guid( ). + + lo_style_red = lo_excel->add_new_style( ). + lo_style_red->fill->filltype = zcl_excel_style_fill=>c_fill_solid. + lo_style_red->fill->bgcolor-rgb = zcl_excel_style_color=>c_red. + lv_style_red_guid = lo_style_red->get_guid( ). + + " add conditional formatting + lo_style_conditional = lo_worksheet->add_new_conditional_style( ). + lo_style_conditional->rule = zcl_excel_style_conditional=>c_rule_cellis. + ls_cellis-formula = '5'. + ls_cellis-operator = zcl_excel_style_conditional=>c_operator_greaterthan. + ls_cellis-cell_style = lv_style_green_guid. + lo_style_conditional->mode_cellis = ls_cellis. + lo_style_conditional->priority = 1. + lo_style_conditional->set_range( ip_start_column = 'C' + ip_start_row = 10 + ip_stop_column = 'C' + ip_stop_row = 10 ). + + lo_style_conditional = lo_worksheet->add_new_conditional_style( ). + lo_style_conditional->rule = zcl_excel_style_conditional=>c_rule_cellis. + ls_cellis-formula = '5'. + ls_cellis-operator = zcl_excel_style_conditional=>c_operator_equal. + ls_cellis-cell_style = lv_style_yellow_guid. + lo_style_conditional->mode_cellis = ls_cellis. + lo_style_conditional->priority = 2. + lo_style_conditional->set_range( ip_start_column = 'C' + ip_start_row = 10 + ip_stop_column = 'C' + ip_stop_row = 10 ). + + lo_style_conditional = lo_worksheet->add_new_conditional_style( ). + lo_style_conditional->rule = zcl_excel_style_conditional=>c_rule_cellis. + ls_cellis-formula = '0'. + ls_cellis-operator = zcl_excel_style_conditional=>c_operator_greaterthan. + ls_cellis-cell_style = lv_style_red_guid. + lo_style_conditional->mode_cellis = ls_cellis. + lo_style_conditional->priority = 3. + lo_style_conditional->set_range( ip_start_column = 'C' + ip_start_row = 10 + ip_stop_column = 'C' + ip_stop_row = 10 ). + + + " Create xlsx stream + CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007. + lv_file = lo_excel_writer->write_file( lo_excel ). + +******************************* +* Output * +******************************* + + " Convert to binary + lt_file_tab = cl_bcs_convert=>xstring_to_solix( iv_xstring = lv_file ). + lv_bytecount = xstrlen( lv_file ). + + " Save the file + cl_gui_frontend_services=>gui_download( EXPORTING bin_filesize = lv_bytecount + filename = lv_full_path + filetype = 'BIN' + CHANGING data_tab = lt_file_tab ). + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_TECHED3 +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_teched3. + +******************************* +* Data Object declaration * +******************************* + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_excel_writer TYPE REF TO zif_excel_writer, + lo_worksheet TYPE REF TO zcl_excel_worksheet. + +DATA: lo_style_title TYPE REF TO zcl_excel_style, + lo_style_green TYPE REF TO zcl_excel_style, + lo_style_yellow TYPE REF TO zcl_excel_style, + lo_style_red TYPE REF TO zcl_excel_style, + lo_drawing TYPE REF TO zcl_excel_drawing, + lo_range TYPE REF TO zcl_excel_range, + lo_data_validation TYPE REF TO zcl_excel_data_validation, + lo_column_dimension TYPE REF TO zcl_excel_worksheet_columndime, + lo_style_conditional TYPE REF TO zcl_excel_style_conditional, + lv_style_title_guid TYPE zexcel_cell_style, + lv_style_green_guid TYPE zexcel_cell_style, + lv_style_yellow_guid TYPE zexcel_cell_style, + lv_style_red_guid TYPE zexcel_cell_style, + ls_cellis TYPE zexcel_conditional_cellis, + ls_key TYPE wwwdatatab. + +DATA: lo_send_request TYPE REF TO cl_bcs, + lo_document TYPE REF TO cl_document_bcs, + lo_sender TYPE REF TO cl_sapuser_bcs, + lo_recipient TYPE REF TO cl_sapuser_bcs, + lo_recipient_i TYPE REF TO CL_CAM_ADDRESS_BCS. + +DATA: lv_file TYPE xstring, + lv_bytecount TYPE i, + lv_bytecount_c TYPE sood-objlen, + lt_file_tab TYPE solix_tab. + +CONSTANTS: lv_default_file_name TYPE string VALUE 'TechEd01.xlsx'. + +******************************* +* abap2xlsx create XLSX * +******************************* + + " Create excel instance + CREATE OBJECT lo_excel. + + " Styles + lo_style_title = lo_excel->add_new_style( ). + lo_style_title->font->bold = abap_true. + lo_style_title->font->color-rgb = zcl_excel_style_color=>c_blue. + lv_style_title_guid = lo_style_title->get_guid( ). + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( ip_title = 'Demo TechEd' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 5 ip_value = 'TechEd demo' ip_style = lv_style_title_guid ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 7 ip_value = 'Is abap2xlsx simple' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 8 ip_value = 'Is abap2xlsx CooL' ). + + lo_worksheet->set_cell( ip_column = 'B' ip_row = 10 ip_value = 'Total score' ). + lo_worksheet->set_cell( ip_column = 'C' ip_row = 10 ip_formula = 'SUM(C7:C8)' ). + + " add logo from SMWO + lo_drawing = lo_excel->add_new_drawing( ). + lo_drawing->set_position( ip_from_row = 2 + ip_from_col = 'B' ). + + ls_key-relid = 'MI'. + ls_key-objid = 'WBLOGO'. + lo_drawing->set_media_www( ip_key = ls_key + ip_width = 140 + ip_height = 64 ). + + " assign drawing to the worksheet + lo_worksheet->add_drawing( lo_drawing ). + + " Add new sheet + lo_worksheet = lo_excel->add_new_worksheet( ). + lo_worksheet->set_title( ip_title = 'Values' ). + + " Set values for range + lo_worksheet->set_cell( ip_row = 4 ip_column = 'A' ip_value = 1 ). + lo_worksheet->set_cell( ip_row = 5 ip_column = 'A' ip_value = 2 ). + lo_worksheet->set_cell( ip_row = 6 ip_column = 'A' ip_value = 3 ). + lo_worksheet->set_cell( ip_row = 7 ip_column = 'A' ip_value = 4 ). + lo_worksheet->set_cell( ip_row = 8 ip_column = 'A' ip_value = 5 ). + + lo_range = lo_excel->add_new_range( ). + lo_range->name = 'Values'. + lo_range->set_value( ip_sheet_name = 'Values' + ip_start_column = 'A' + ip_start_row = 4 + ip_stop_column = 'A' + ip_stop_row = 8 ). + + lo_excel->set_active_sheet_index( 1 ). + + " add data validation + lo_worksheet = lo_excel->get_active_worksheet( ). + + lo_data_validation = lo_worksheet->add_new_data_validation( ). + lo_data_validation->type = zcl_excel_data_validation=>c_type_list. + lo_data_validation->formula1 = 'Values'. + lo_data_validation->cell_row = 7. + lo_data_validation->cell_column = 'C'. + lo_worksheet->set_cell( ip_row = 7 ip_column = 'C' ip_value = 'Select a value' ). + + + lo_data_validation = lo_worksheet->add_new_data_validation( ). + lo_data_validation->type = zcl_excel_data_validation=>c_type_list. + lo_data_validation->formula1 = 'Values'. + lo_data_validation->cell_row = 8. + lo_data_validation->cell_column = 'C'. + lo_worksheet->set_cell( ip_row = 8 ip_column = 'C' ip_value = 'Select a value' ). + + " add autosize (column width) + lo_column_dimension = lo_worksheet->get_column_dimension( ip_column = 'B' ). + lo_column_dimension->set_auto_size( ip_auto_size = abap_true ). + lo_column_dimension = lo_worksheet->get_column_dimension( ip_column = 'C' ). + lo_column_dimension->set_auto_size( ip_auto_size = abap_true ). + + " defne conditional styles + lo_style_green = lo_excel->add_new_style( ). + lo_style_green->fill->filltype = zcl_excel_style_fill=>c_fill_solid. + lo_style_green->fill->bgcolor-rgb = zcl_excel_style_color=>c_green. + lv_style_green_guid = lo_style_green->get_guid( ). + + lo_style_yellow = lo_excel->add_new_style( ). + lo_style_yellow->fill->filltype = zcl_excel_style_fill=>c_fill_solid. + lo_style_yellow->fill->bgcolor-rgb = zcl_excel_style_color=>c_yellow. + lv_style_yellow_guid = lo_style_yellow->get_guid( ). + + lo_style_red = lo_excel->add_new_style( ). + lo_style_red->fill->filltype = zcl_excel_style_fill=>c_fill_solid. + lo_style_red->fill->bgcolor-rgb = zcl_excel_style_color=>c_red. + lv_style_red_guid = lo_style_red->get_guid( ). + + " add conditional formatting + lo_style_conditional = lo_worksheet->add_new_conditional_style( ). + lo_style_conditional->rule = zcl_excel_style_conditional=>c_rule_cellis. + ls_cellis-formula = '5'. + ls_cellis-operator = zcl_excel_style_conditional=>c_operator_greaterthan. + ls_cellis-cell_style = lv_style_green_guid. + lo_style_conditional->mode_cellis = ls_cellis. + lo_style_conditional->priority = 1. + lo_style_conditional->set_range( ip_start_column = 'C' + ip_start_row = 10 + ip_stop_column = 'C' + ip_stop_row = 10 ). + + lo_style_conditional = lo_worksheet->add_new_conditional_style( ). + lo_style_conditional->rule = zcl_excel_style_conditional=>c_rule_cellis. + ls_cellis-formula = '5'. + ls_cellis-operator = zcl_excel_style_conditional=>c_operator_equal. + ls_cellis-cell_style = lv_style_yellow_guid. + lo_style_conditional->mode_cellis = ls_cellis. + lo_style_conditional->priority = 2. + lo_style_conditional->set_range( ip_start_column = 'C' + ip_start_row = 10 + ip_stop_column = 'C' + ip_stop_row = 10 ). + + lo_style_conditional = lo_worksheet->add_new_conditional_style( ). + lo_style_conditional->rule = zcl_excel_style_conditional=>c_rule_cellis. + ls_cellis-formula = '0'. + ls_cellis-operator = zcl_excel_style_conditional=>c_operator_greaterthan. + ls_cellis-cell_style = lv_style_red_guid. + lo_style_conditional->mode_cellis = ls_cellis. + lo_style_conditional->priority = 3. + lo_style_conditional->set_range( ip_start_column = 'C' + ip_start_row = 10 + ip_stop_column = 'C' + ip_stop_row = 10 ). + + + " Create xlsx stream + CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007. + lv_file = lo_excel_writer->write_file( lo_excel ). + +******************************* +* Output * +******************************* + + " Convert to binary + lt_file_tab = cl_bcs_convert=>xstring_to_solix( iv_xstring = lv_file ). + lv_bytecount = xstrlen( lv_file ). + lv_bytecount_c = lv_bytecount. + + " Send via email + lo_document = cl_document_bcs=>create_document( i_type = 'RAW' + i_subject = 'Demo TechEd' ). + + lo_document->add_attachment( i_attachment_type = 'EXT' + i_attachment_subject = 'abap2xlsx.xlsx' + i_attachment_size = lv_bytecount_c + i_att_content_hex = lt_file_tab ). + + lo_sender = cl_sapuser_bcs=>create( sy-uname ). + lo_recipient = cl_sapuser_bcs=>create( sy-uname ). +* lo_recipient_i = cl_cam_address_bcs=>create_internet_address( 'ivan.femia@techedge.it' ). + + lo_send_request = cl_bcs=>create_persistent( ). + lo_send_request->set_document( lo_document ). + lo_send_request->set_sender( lo_sender ). + lo_send_request->add_recipient( lo_recipient ). + lo_send_request->set_send_immediately( abap_true ). + lo_send_request->send( ). + + + + + + + + *&---------------------------------------------------------------------* +*& 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 + + + + + + + + *&---------------------------------------------------------------------* +*& Report Z_ZAKE_SVN +*& +*&---------------------------------------------------------------------* +*& Checkout / Checkin the ZAKE_SVN Project +*& +*&---------------------------------------------------------------------* + +REPORT zake_svn_a2x. + +CONSTANTS cl_svn TYPE seoclsname VALUE 'ZCL_ZAKE_SVN'. +CONSTANTS cl_tortoise_svn TYPE seoclsname VALUE 'ZCL_ZAKE_TORTOISE_SVN'. + +DATA package TYPE devclass. +DATA zake TYPE REF TO zake. + +DATA objects TYPE scts_tadir. +DATA object LIKE LINE OF objects. + +DATA files TYPE string_table. +DATA file LIKE LINE OF files. + +DATA zake_build TYPE string. +DATA zake_nuggetname TYPE string. + +DATA comment_str TYPE string. +DATA loclpath_str TYPE string. +DATA svnpath_str TYPE string. +DATA username_str TYPE string. +DATA password_str TYPE string. +DATA class TYPE seoclsname. + +DATA: ex TYPE REF TO zcx_saplink, + message TYPE string. + +SELECTION-SCREEN BEGIN OF BLOCK a WITH FRAME TITLE a. +PARAMETERS: + checkout TYPE flag RADIOBUTTON GROUP act, + update TYPE flag RADIOBUTTON GROUP act DEFAULT 'X', + install TYPE flag RADIOBUTTON GROUP act, + export TYPE flag RADIOBUTTON GROUP act, + build TYPE flag RADIOBUTTON GROUP act, + checkin TYPE flag RADIOBUTTON GROUP act. +SELECTION-SCREEN END OF BLOCK a. + +SELECTION-SCREEN BEGIN OF BLOCK b WITH FRAME TITLE b. +PARAMETERS: + svn TYPE flag RADIOBUTTON GROUP cl, + tortoise TYPE flag RADIOBUTTON GROUP cl. +SELECTION-SCREEN END OF BLOCK b. + +SELECTION-SCREEN BEGIN OF BLOCK c WITH FRAME TITLE c. +PARAMETERS: + loclpath TYPE char512 DEFAULT 'C:\Projects\abap2xlsx\trunk' LOWER CASE OBLIGATORY, + zakenugg TYPE char512 DEFAULT 'C:\Projects\abap2xlsx\nuggs\abap2xlsx_Daily.nugg' LOWER CASE OBLIGATORY, + svnpath TYPE char512 DEFAULT 'https://code.sdn.sap.com/svn/abap2xlsx/trunk' LOWER CASE OBLIGATORY, + comment TYPE char512 DEFAULT '' LOWER CASE, + username TYPE char512 LOWER CASE, + password TYPE char512 LOWER CASE, + testrun TYPE flag DEFAULT 'X'. +SELECTION-SCREEN END OF BLOCK c. + +INITIALIZATION. + a = 'Action'. + b = 'Version Controll Program'. + c = 'Parameters'. + +START-OF-SELECTION. + + svnpath_str = svnpath. + loclpath_str = loclpath. + zake_nuggetname = zakenugg. + comment_str = comment. + + " SELECT * INTO TABLE objects FROM tadir WHERE devclass = 'ZABAP2XLSX'. + " DELETE zake_objects WHERE object = 'DEVC'. + + TRY. + IF svn = 'X'. + class = cl_svn. + ELSE. + class = cl_tortoise_svn. + ENDIF. + + CREATE OBJECT zake + TYPE + (class) + EXPORTING + i_svnpath = svnpath_str + i_localpath = loclpath_str. + zake->set_testrun( testrun ). + zake->set_package( 'ZA2X' ). + + IF checkout = 'X'. + zake->checkout( ). + ELSEIF update = 'X'. + zake->update( ). + ELSEIF install = 'X'. + zake->install_slinkees_from_lm( testrun ). + " zake->install_objects( zake_objects ). + ELSEIF export = 'X'. + " Build Object list for Export + " Programs + object-object = 'PROG'. + object-obj_name = 'ZAKE_SVN_A2X'. + APPEND object TO objects. + zake->set_checkin_objects( objects ). + zake->download_slinkees_to_lm = abap_true. + zake->download_nugget_to_lm = space. + zake->download_zip_to_lm_flag = space. + zake->create_slinkees( zake_nuggetname ). + ELSEIF build = 'X'. + " Build a complete package for download + zake->set_checkin_objects( objects ). + " We don't want that for the complete Package Slinkees are created + " in the ZAKE folder + zake->download_slinkees_to_lm = space. + zake->download_nugget_to_lm = space. + zake->create_slinkees( zake_nuggetname ). + ELSEIF checkin = 'X'. + zake->set_package( 'ZA2X' ). + zake->set_checkin_objects( objects ). + zake->create_slinkees( zake_nuggetname ). + IF testrun IS INITIAL. + zake->checkin( comment_str ). + ENDIF. + ENDIF. + CATCH zcx_saplink INTO ex. + message = ex->msg. + WRITE: / 'An Error occured: ', message. + ENDTRY. + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZANGRY_BIRDS +*& Just for fun +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zangry_birds. + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_excel_writer TYPE REF TO zif_excel_writer, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + lo_border_light TYPE REF TO zcl_excel_style_border, + lo_style_color0 TYPE REF TO zcl_excel_style, + lo_style_color1 TYPE REF TO zcl_excel_style, + lo_style_color2 TYPE REF TO zcl_excel_style, + lo_style_color3 TYPE REF TO zcl_excel_style, + lo_style_color4 TYPE REF TO zcl_excel_style, + lo_style_color5 TYPE REF TO zcl_excel_style, + lo_style_color6 TYPE REF TO zcl_excel_style, + lo_style_color7 TYPE REF TO zcl_excel_style, + lo_style_credit TYPE REF TO zcl_excel_style, + lo_style_link TYPE REF TO zcl_excel_style, + lo_column_dimension TYPE REF TO zcl_excel_worksheet_columndime, + lo_row_dimension TYPE REF TO zcl_excel_worksheet_rowdimensi, + lo_hyperlink TYPE REF TO zcl_excel_hyperlink. + +DATA: lv_style_color0_guid TYPE zexcel_cell_style, + lv_style_color1_guid TYPE zexcel_cell_style, + lv_style_color2_guid TYPE zexcel_cell_style, + lv_style_color3_guid TYPE zexcel_cell_style, + lv_style_color4_guid TYPE zexcel_cell_style, + lv_style_color5_guid TYPE zexcel_cell_style, + lv_style_color6_guid TYPE zexcel_cell_style, + lv_style_color7_guid TYPE zexcel_cell_style, + lv_style_credit_guid TYPE zexcel_cell_style, + lv_style_link_guid TYPE zexcel_cell_style, + lv_style TYPE zexcel_cell_style. + +DATA: lv_col_str TYPE zexcel_cell_column_alpha, + lv_row TYPE i, + lv_col TYPE i, + lt_mapper TYPE TABLE OF zexcel_cell_style, + ls_mapper TYPE zexcel_cell_style. + +DATA: lv_file TYPE xstring, + lv_bytecount TYPE i, + lt_file_tab TYPE solix_tab. + +DATA: lv_full_path TYPE string, + lv_workdir TYPE string, + lv_file_separator TYPE c. + +CONSTANTS: lv_default_file_name TYPE string VALUE 'angry_birds.xlsx'. + +PARAMETERS: p_path TYPE zexcel_export_dir. + +AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path. + lv_workdir = p_path. + cl_gui_frontend_services=>directory_browse( EXPORTING initial_folder = lv_workdir + CHANGING selected_folder = lv_workdir ). + p_path = lv_workdir. + +INITIALIZATION. + cl_gui_frontend_services=>get_sapgui_workdir( CHANGING sapworkdir = lv_workdir ). + cl_gui_cfw=>flush( ). + p_path = lv_workdir. + +START-OF-SELECTION. + + IF p_path IS INITIAL. + p_path = lv_workdir. + ENDIF. + cl_gui_frontend_services=>get_file_separator( CHANGING file_separator = lv_file_separator ). + CONCATENATE p_path lv_file_separator lv_default_file_name INTO lv_full_path. + + " Creates active sheet + CREATE OBJECT lo_excel. + + CREATE OBJECT lo_border_light. + lo_border_light->border_color-rgb = zcl_excel_style_color=>c_white. + lo_border_light->border_style = zcl_excel_style_border=>c_border_thin. + + " Create color white + lo_style_color0 = lo_excel->add_new_style( ). + lo_style_color0->fill->filltype = zcl_excel_style_fill=>c_fill_solid. + lo_style_color0->fill->fgcolor-rgb = 'FFFFFFFF'. + lo_style_color0->borders->allborders = lo_border_light. + lv_style_color0_guid = lo_style_color0->get_guid( ). + + " Create color black + lo_style_color1 = lo_excel->add_new_style( ). + lo_style_color1->fill->filltype = zcl_excel_style_fill=>c_fill_solid. + lo_style_color1->fill->fgcolor-rgb = 'FF252525'. + lo_style_color1->borders->allborders = lo_border_light. + lv_style_color1_guid = lo_style_color1->get_guid( ). + + " Create color dark green + lo_style_color2 = lo_excel->add_new_style( ). + lo_style_color2->fill->filltype = zcl_excel_style_fill=>c_fill_solid. + lo_style_color2->fill->fgcolor-rgb = 'FF75913A'. + lo_style_color2->borders->allborders = lo_border_light. + lv_style_color2_guid = lo_style_color2->get_guid( ). + + " Create color light green + lo_style_color3 = lo_excel->add_new_style( ). + lo_style_color3->fill->filltype = zcl_excel_style_fill=>c_fill_solid. + lo_style_color3->fill->fgcolor-rgb = 'FF9DFB73'. + lo_style_color3->borders->allborders = lo_border_light. + lv_style_color3_guid = lo_style_color3->get_guid( ). + + " Create color green + lo_style_color4 = lo_excel->add_new_style( ). + lo_style_color4->fill->filltype = zcl_excel_style_fill=>c_fill_solid. + lo_style_color4->fill->fgcolor-rgb = 'FF92CF56'. + lo_style_color4->borders->allborders = lo_border_light. + lv_style_color4_guid = lo_style_color4->get_guid( ). + + " Create color 2dark green + lo_style_color5 = lo_excel->add_new_style( ). + lo_style_color5->fill->filltype = zcl_excel_style_fill=>c_fill_solid. + lo_style_color5->fill->fgcolor-rgb = 'FF506228'. + lo_style_color5->borders->allborders = lo_border_light. + lv_style_color5_guid = lo_style_color5->get_guid( ). + + " Create color yellow + lo_style_color6 = lo_excel->add_new_style( ). + lo_style_color6->fill->filltype = zcl_excel_style_fill=>c_fill_solid. + lo_style_color6->fill->fgcolor-rgb = 'FFC3E224'. + lo_style_color6->borders->allborders = lo_border_light. + lv_style_color6_guid = lo_style_color6->get_guid( ). + + " Create color yellow + lo_style_color7 = lo_excel->add_new_style( ). + lo_style_color7->fill->filltype = zcl_excel_style_fill=>c_fill_solid. + lo_style_color7->fill->fgcolor-rgb = 'FFB3C14F'. + lo_style_color7->borders->allborders = lo_border_light. + lv_style_color7_guid = lo_style_color7->get_guid( ). + + " Credits + lo_style_credit = lo_excel->add_new_style( ). + lo_style_credit->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_center. + lo_style_credit->alignment->vertical = zcl_excel_style_alignment=>c_vertical_center. + lo_style_credit->font->size = 20. + lv_style_credit_guid = lo_style_credit->get_guid( ). + + " Link + lo_style_link = lo_excel->add_new_style( ). + lo_style_link->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_center. + lo_style_link->alignment->vertical = zcl_excel_style_alignment=>c_vertical_center. +* lo_style_link->font->size = 20. + lv_style_link_guid = lo_style_link->get_guid( ). + + " Create image map " line 2 + DO 30 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 3 + DO 28 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 5 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 4 + DO 27 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 4 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 5 + DO 9 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 15 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 6 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 6 + DO 7 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 6 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 13 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 4 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 7 + DO 6 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 5 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 11 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 5 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 8 + DO 5 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 9 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 6 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 9 + DO 5 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 9 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 4 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 10 + DO 4 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 6 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 9 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 4 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 11 + DO 4 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 7 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 9 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 4 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 12 + DO 4 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 4 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 4 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 4 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 13 + DO 5 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 4 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 8 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 14 + DO 5 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 4 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 12 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 15 + DO 6 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 8 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 4 TIMES. APPEND lv_style_color4_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 16 + DO 7 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 7 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color4_guid TO lt_mapper. ENDDO. + DO 5 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color4_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color4_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 17 + DO 8 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 6 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color4_guid TO lt_mapper. ENDDO. + DO 13 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color4_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 18 + DO 6 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 23 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color4_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 19 + DO 5 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 27 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 20 + DO 5 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 23 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 21 + DO 4 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 19 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 22 + DO 4 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 4 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 17 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 23 + DO 4 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 17 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 8 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 24 + DO 4 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color4_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color5_guid TO lt_mapper. ENDDO. + DO 10 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 9 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color5_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 25 + DO 3 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color4_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color5_guid TO lt_mapper. ENDDO. + DO 6 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 8 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 6 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color5_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color5_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 26 + DO 3 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color4_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color5_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color5_guid TO lt_mapper. ENDDO. + DO 4 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 4 TIMES. APPEND lv_style_color7_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color6_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color7_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color5_guid TO lt_mapper. ENDDO. + DO 4 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color5_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 27 + DO 3 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color4_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color5_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color5_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 4 TIMES. APPEND lv_style_color7_guid TO lt_mapper. ENDDO. + DO 4 TIMES. APPEND lv_style_color6_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color5_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color5_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 28 + DO 3 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color4_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color5_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color5_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color7_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color5_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color7_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color5_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color6_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color7_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color5_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color5_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 29 + DO 3 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color4_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color5_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color5_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color7_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color5_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color7_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color5_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color7_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color5_guid TO lt_mapper. ENDDO. + DO 5 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color5_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 30 + DO 3 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color4_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color5_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color5_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 4 TIMES. APPEND lv_style_color7_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color5_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color7_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color5_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color7_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color5_guid TO lt_mapper. ENDDO. + DO 4 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color5_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 31 + DO 3 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color4_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color5_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 4 TIMES. APPEND lv_style_color7_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color5_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color7_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color5_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color7_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color5_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color5_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 32 + DO 3 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 8 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 9 TIMES. APPEND lv_style_color7_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 4 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color5_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 33 + DO 3 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 9 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color7_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color7_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 9 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 34 + DO 3 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 9 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 9 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 10 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 35 + DO 4 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 9 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 6 TIMES. APPEND lv_style_color7_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 11 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 36 + DO 4 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 10 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color7_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 11 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 37 + DO 5 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 10 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color7_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 11 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 38 + DO 6 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 10 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 11 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 39 + DO 7 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 22 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 1 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 40 + DO 7 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 4 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 17 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 41 + DO 8 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 3 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 4 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 15 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 4 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 42 + DO 9 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 5 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 6 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 9 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 2 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 4 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 43 + DO 11 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 6 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 4 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 5 TIMES. APPEND lv_style_color3_guid TO lt_mapper. ENDDO. + DO 7 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 44 + DO 13 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 6 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + DO 4 TIMES. APPEND lv_style_color2_guid TO lt_mapper. ENDDO. + DO 8 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 45 + DO 16 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 13 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + " line 46 + DO 18 TIMES. APPEND lv_style_color0_guid TO lt_mapper. ENDDO. + DO 8 TIMES. APPEND lv_style_color1_guid TO lt_mapper. ENDDO. + APPEND INITIAL LINE TO lt_mapper. " escape + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( ip_title = 'Angry Birds' ). + + lv_row = 1. + lv_col = 1. + + LOOP AT lt_mapper INTO ls_mapper. + lv_col_str = zcl_excel_common=>convert_column2alpha( lv_col ). + IF ls_mapper IS INITIAL. + lo_row_dimension = lo_worksheet->get_row_dimension( ip_row = lv_row ). + lo_row_dimension->set_row_height( ip_row_height = 8 ). + lv_col = 1. + lv_row = lv_row + 1. + CONTINUE. + ENDIF. + lo_worksheet->set_cell( ip_column = lv_col_str + ip_row = lv_row + ip_value = space + ip_style = ls_mapper ). + lv_col = lv_col + 1. + + lo_column_dimension = lo_worksheet->get_column_dimension( ip_column = lv_col_str ). + lo_column_dimension->set_width( ip_width = 2 ). + ENDLOOP. + + lo_worksheet->set_show_gridlines( i_show_gridlines = abap_false ). + + lo_worksheet->set_cell( ip_column = 'AP' + ip_row = 15 + ip_value = 'Created with abap2xlsx' + ip_style = lv_style_credit_guid ). + + lo_hyperlink = zcl_excel_hyperlink=>create_external_link( iv_url = 'http://www.abap2xlsx.org' ). + lo_worksheet->set_cell( ip_column = 'AP' + ip_row = 24 + ip_value = 'http://www.abap2xlsx.org' + ip_style = lv_style_link_guid + ip_hyperlink = lo_hyperlink ). + + lo_column_dimension = lo_worksheet->get_column_dimension( ip_column = 'AP' ). + lo_column_dimension->set_auto_size( ip_auto_size = abap_true ). + lo_worksheet->set_merge( ip_row = 15 ip_column_start = 'AP' ip_row_to = 22 ip_column_end = 'AR' ). + lo_worksheet->set_merge( ip_row = 24 ip_column_start = 'AP' ip_row_to = 26 ip_column_end = 'AR' ). + + CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007. + lv_file = lo_excel_writer->write_file( lo_excel ). + + " Convert to binary + CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' + EXPORTING + buffer = lv_file + IMPORTING + output_length = lv_bytecount + TABLES + binary_tab = lt_file_tab. +* " This method is only available on AS ABAP > 6.40 +* lt_file_tab = cl_bcs_convert=>xstring_to_solix( iv_xstring = lv_file ). +* lv_bytecount = xstrlen( lv_file ). + + " Save the file + cl_gui_frontend_services=>gui_download( EXPORTING bin_filesize = lv_bytecount + filename = lv_full_path + filetype = 'BIN' + CHANGING data_tab = lt_file_tab ). + + + + + + + + + + + + + + + + + + + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_CALENDAR +*& abap2xlsx Demo: Create Calendar with Pictures +*&---------------------------------------------------------------------* +*& This report creates a monthly calendar in the specified date range. +*& Each month is put on a seperate worksheet. The pictures for each +*& month can be specified in a tab delimited file called "Calendar.txt" +*& which is saved in the Export Directory. By default this is the SAP +*& Workdir. The file contains 3 fields: +*& +*& Month (with leading 0) +*& Image Filename +*& Image Description +*& URL for the Description +*& +*& The Images should be landscape JPEG's with a 3:2 ratio and min. +*& 450 pixel height. They must also be saved in the Export Directory. +*& In my tests I've discovered a limit of 20 MB in the +*& cl_gui_frontend_services=>gui_download method. So keep your images +*& smaller or chnage to a server export using OPEN DATASET. +*&---------------------------------------------------------------------* + +REPORT zdemo_calendar. + +TYPE-POOLS: abap. +CONSTANTS: gc_save_file_name TYPE string VALUE 'Calendar.xlsx'. +INCLUDE zdemo_excel_outputopt_incl. +INCLUDE zdemo_calendar_classes. + +DATA: lv_workdir TYPE string. + +PARAMETERS: p_from TYPE dfrom DEFAULT '20130101', + p_to TYPE dto DEFAULT '20131231'. + +SELECTION-SCREEN BEGIN OF BLOCK orientation WITH FRAME TITLE orient. +PARAMETERS: p_portr TYPE flag RADIOBUTTON GROUP orie, + p_lands TYPE flag RADIOBUTTON GROUP orie DEFAULT 'X'. +SELECTION-SCREEN END OF BLOCK orientation. + +INITIALIZATION. + cl_gui_frontend_services=>get_sapgui_workdir( CHANGING sapworkdir = lv_workdir ). + cl_gui_cfw=>flush( ). + p_path = lv_workdir. + orient = 'Orientation'(000). + +START-OF-SELECTION. + + DATA: lo_excel TYPE REF TO zcl_excel, + lo_excel_writer TYPE REF TO zif_excel_writer, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + lo_col_dim TYPE REF TO zcl_excel_worksheet_columndime, + lo_row_dim TYPE REF TO zcl_excel_worksheet_rowdimensi, + hyperlink TYPE REF TO zcl_excel_hyperlink, + lo_drawing TYPE REF TO zcl_excel_drawing. + + DATA: lo_style_month TYPE REF TO zcl_excel_style, + lv_style_month_guid TYPE zexcel_cell_style. + DATA: lo_style_border TYPE REF TO zcl_excel_style, + lo_border_dark TYPE REF TO zcl_excel_style_border, + lv_style_border_guid TYPE zexcel_cell_style. + DATA: lo_style_center TYPE REF TO zcl_excel_style, + lv_style_center_guid TYPE zexcel_cell_style. + + DATA: lv_file TYPE xstring, + lv_bytecount TYPE i, + lt_file_tab TYPE solix_tab. + + DATA: lv_full_path TYPE string, + image_descr_path TYPE string, + lv_file_separator TYPE c. + DATA: lv_content TYPE xstring, + width TYPE i, + lv_height TYPE i, + lv_from_row TYPE zexcel_cell_row. + + DATA: month TYPE i, + month_nr TYPE fcmnr, + count TYPE i VALUE 1, + title TYPE zexcel_sheet_title, + value TYPE string, + image_path TYPE string, + date_from TYPE datum, + date_to TYPE datum, + row TYPE zexcel_cell_row, + to_row TYPE zexcel_cell_row, + to_col TYPE zexcel_cell_column_alpha, + to_col_end TYPE zexcel_cell_column_alpha, + to_col_int TYPE i. + + DATA: month_names TYPE TABLE OF t247. + FIELD-SYMBOLS: <month_name> LIKE LINE OF month_names. + + TYPES: BEGIN OF tt_datatab, + month_nr TYPE fcmnr, + filename TYPE string, + descr TYPE string, + url TYPE string, + END OF tt_datatab. + + DATA: image_descriptions TYPE TABLE OF tt_datatab. + FIELD-SYMBOLS: <img_descr> LIKE LINE OF image_descriptions. + + CONSTANTS: lv_default_file_name TYPE string VALUE 'Calendar', "#EC NOTEXT + c_from_row_portrait TYPE zexcel_cell_row VALUE 28, + c_from_row_landscape TYPE zexcel_cell_row VALUE 38, + from_col TYPE zexcel_cell_column_alpha VALUE 'C', + c_height_portrait TYPE i VALUE 450, " Image Height in Portrait Mode + c_height_landscape TYPE i VALUE 670, " Image Height in Landscape Mode + c_factor TYPE f VALUE '1.5'. " Image Ratio, default 3:2 + + IF p_path IS INITIAL. + p_path = lv_workdir. + ENDIF. + cl_gui_frontend_services=>get_file_separator( CHANGING file_separator = lv_file_separator ). + CONCATENATE p_path lv_file_separator lv_default_file_name '.xlsx' INTO lv_full_path. "#EC NOTEXT + + " Read Image Names for Month and Description + CONCATENATE p_path lv_file_separator lv_default_file_name '.txt' INTO image_descr_path. "#EC NOTEXT + cl_gui_frontend_services=>gui_upload( + EXPORTING + filename = image_descr_path " Name of file + filetype = 'ASC' " File Type (ASCII, Binary) + has_field_separator = 'X' + read_by_line = 'X' " File Written Line-By-Line to the Internal Table + CHANGING + data_tab = image_descriptions " Transfer table for file contents + 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. + MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno + WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. + ENDIF. + + " Creates active sheet + CREATE OBJECT lo_excel. + + " Create Styles + " Create an underline double style + lo_style_month = lo_excel->add_new_style( ). + " lo_style_month->font->underline = abap_true. + " lo_style_month->font->underline_mode = zcl_excel_style_font=>c_underline_single. + lo_style_month->font->name = zcl_excel_style_font=>c_name_roman. + lo_style_month->font->scheme = zcl_excel_style_font=>c_scheme_none. + lo_style_month->font->family = zcl_excel_style_font=>c_family_roman. + lo_style_month->font->bold = abap_true. + lo_style_month->font->size = 36. + lv_style_month_guid = lo_style_month->get_guid( ). + " Create border object + CREATE OBJECT lo_border_dark. + lo_border_dark->border_color-rgb = zcl_excel_style_color=>c_black. + lo_border_dark->border_style = zcl_excel_style_border=>c_border_thin. + "Create style with border + lo_style_border = lo_excel->add_new_style( ). + lo_style_border->borders->allborders = lo_border_dark. + lo_style_border->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_right. + lo_style_border->alignment->vertical = zcl_excel_style_alignment=>c_vertical_top. + lv_style_border_guid = lo_style_border->get_guid( ). + "Create style alignment center + lo_style_center = lo_excel->add_new_style( ). + lo_style_center->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_center. + lo_style_center->alignment->vertical = zcl_excel_style_alignment=>c_vertical_top. + lv_style_center_guid = lo_style_center->get_guid( ). + + " Get Month Names + CALL FUNCTION 'MONTH_NAMES_GET' + TABLES + month_names = month_names. + + zcl_date_calculation=>months_between_two_dates( + EXPORTING + i_date_from = p_from + i_date_to = p_to + i_incl_to = abap_true + IMPORTING + e_month = month + ). + + date_from = p_from. + + WHILE count <= month. + IF count = 1. + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + ELSE. + lo_worksheet = lo_excel->add_new_worksheet( ). + ENDIF. + + lo_worksheet->zif_excel_sheet_properties~selected = zif_excel_sheet_properties=>c_selected. + + title = count. + value = count. + CONDENSE title. + CONDENSE value. + lo_worksheet->set_title( title ). + lo_worksheet->set_print_gridlines( abap_false ). + lo_worksheet->sheet_setup->paper_size = zcl_excel_sheet_setup=>c_papersize_a4. + lo_worksheet->sheet_setup->horizontal_centered = abap_true. + lo_worksheet->sheet_setup->vertical_centered = abap_true. + lo_col_dim = lo_worksheet->get_column_dimension( 'A' ). + lo_col_dim->set_width( '1.0' ). + lo_col_dim = lo_worksheet->get_column_dimension( 'B' ). + lo_col_dim->set_width( '2.0' ). + IF p_lands = abap_true. + lo_worksheet->sheet_setup->orientation = zcl_excel_sheet_setup=>c_orientation_landscape. + lv_height = c_height_landscape. + lv_from_row = c_from_row_landscape. + lo_worksheet->sheet_setup->margin_top = '0.10'. + lo_worksheet->sheet_setup->margin_left = '0.10'. + lo_worksheet->sheet_setup->margin_right = '0.10'. + lo_worksheet->sheet_setup->margin_bottom = '0.10'. + ELSE. + lo_col_dim = lo_worksheet->get_column_dimension( 'K' ). + lo_col_dim->set_width( '3.0' ). + lo_worksheet->sheet_setup->margin_top = '0.80'. + lo_worksheet->sheet_setup->margin_left = '0.55'. + lo_worksheet->sheet_setup->margin_right = '0.05'. + lo_worksheet->sheet_setup->margin_bottom = '0.30'. + lv_height = c_height_portrait. + lv_from_row = c_from_row_portrait. + ENDIF. + + " Add Month Name + month_nr = date_from+4(2). + IF p_portr = abap_true. + READ TABLE month_names WITH KEY mnr = month_nr ASSIGNING <month_name>. + CONCATENATE <month_name>-ltx ` ` date_from(4) INTO value. + row = lv_from_row - 2. + to_col = from_col. + ELSE. + row = lv_from_row - 1. + to_col_int = zcl_excel_common=>convert_column2int( from_col ) + 32. + to_col = zcl_excel_common=>convert_column2alpha( to_col_int ). + to_col_int = to_col_int + 1. + to_col_end = zcl_excel_common=>convert_column2alpha( to_col_int ). + CONCATENATE month_nr '/' date_from+2(2) INTO value. + to_row = row + 2. + lo_worksheet->set_merge( + EXPORTING + ip_column_start = to_col " Cell Column Start + ip_column_end = to_col_end " Cell Column End + ip_row = row " Cell Row + ip_row_to = to_row " Cell Row + ). + ENDIF. + lo_worksheet->set_cell( + EXPORTING + ip_column = to_col " Cell Column + ip_row = row " Cell Row + ip_value = value " Cell Value + ip_style = lv_style_month_guid + ). + +* to_col_int = zcl_excel_common=>convert_column2int( from_col ) + 7. +* to_col = zcl_excel_common=>convert_column2alpha( to_col_int ). +* +* lo_worksheet->set_merge( +* EXPORTING +* ip_column_start = from_col " Cell Column Start +* ip_column_end = to_col " Cell Column End +* ip_row = row " Cell Row +* ip_row_to = row " Cell Row +* ). + + " Add drawing from a XSTRING read from a file + UNASSIGN <img_descr>. + READ TABLE image_descriptions WITH KEY month_nr = month_nr ASSIGNING <img_descr>. + IF <img_descr> IS ASSIGNED. + value = <img_descr>-descr. + IF p_portr = abap_true. + row = lv_from_row - 3. + ELSE. + row = lv_from_row - 2. + ENDIF. + IF NOT <img_descr>-url IS INITIAL. + hyperlink = zcl_excel_hyperlink=>create_external_link( <img_descr>-url ). + lo_worksheet->set_cell( + EXPORTING + ip_column = from_col " Cell Column + ip_row = row " Cell Row + ip_value = value " Cell Value + ip_hyperlink = hyperlink + ). + ELSE. + lo_worksheet->set_cell( + EXPORTING + ip_column = from_col " Cell Column + ip_row = row " Cell Row + ip_value = value " Cell Value + ). + ENDIF. + lo_row_dim = lo_worksheet->get_row_dimension( row ). + lo_row_dim->set_row_height( '22.0' ). + + " In Landscape mode the row between the description and the + " dates should be not so high + IF p_lands = abap_true. + row = lv_from_row - 3. + lo_worksheet->set_cell( + EXPORTING + ip_column = from_col " Cell Column + ip_row = row " Cell Row + ip_value = ' ' " Cell Value + ). + lo_row_dim = lo_worksheet->get_row_dimension( row ). + lo_row_dim->set_row_height( '7.0' ). + row = lv_from_row - 1. + lo_row_dim = lo_worksheet->get_row_dimension( row ). + lo_row_dim->set_row_height( '5.0' ). + ENDIF. + + CONCATENATE p_path lv_file_separator <img_descr>-filename INTO image_path. + lo_drawing = lo_excel->add_new_drawing( ). + lo_drawing->set_position( ip_from_row = 1 + ip_from_col = 'B' ). + + lv_content = zcl_helper=>load_image( image_path ). + width = lv_height * c_factor. + lo_drawing->set_media( ip_media = lv_content + ip_media_type = zcl_excel_drawing=>c_media_type_jpg + ip_width = width + ip_height = lv_height ). + lo_worksheet->add_drawing( lo_drawing ). + ENDIF. + + " Add Calendar + CALL FUNCTION 'SLS_MISC_GET_LAST_DAY_OF_MONTH' + EXPORTING + day_in = date_from + IMPORTING + last_day_of_month = date_to. + IF p_portr = abap_true. + zcl_helper=>add_calendar( + EXPORTING + i_date_from = date_from + i_date_to = date_to + i_from_row = lv_from_row + i_from_col = from_col + i_day_style = lv_style_border_guid + i_cw_style = lv_style_center_guid + CHANGING + c_worksheet = lo_worksheet + ). + ELSE. + zcl_helper=>add_calendar_landscape( + EXPORTING + i_date_from = date_from + i_date_to = date_to + i_from_row = lv_from_row + i_from_col = from_col + i_day_style = lv_style_border_guid + i_cw_style = lv_style_center_guid + CHANGING + c_worksheet = lo_worksheet + ). + ENDIF. + count = count + 1. + date_from = date_to + 1. + ENDWHILE. + + lo_excel->set_active_sheet_index_by_name( '1' ). +*** Create output + lcl_output=>output( lo_excel ). + + + + + + + + *&---------------------------------------------------------------------* +*& Include ZDEMO_CALENDAR_CLASSES +*&---------------------------------------------------------------------* + +*&---------------------------------------------------------------------* +*& Class ZCL_DATE_CALCULATION +*&---------------------------------------------------------------------* +* Text +*----------------------------------------------------------------------* +CLASS zcl_date_calculation DEFINITION. + PUBLIC SECTION. + CLASS-METHODS: months_between_two_dates + IMPORTING + i_date_from TYPE datum + i_date_to TYPE datum + i_incl_to TYPE flag + EXPORTING + e_month TYPE i. +ENDCLASS. "ZCL_DATE_CALCULATION + + +*----------------------------------------------------------------------* +* CLASS ZCL_DATE_CALCULATION IMPLEMENTATION +*----------------------------------------------------------------------* +* +*----------------------------------------------------------------------* +CLASS zcl_date_calculation IMPLEMENTATION. + METHOD months_between_two_dates. + DATA: date_to TYPE datum. + DATA: BEGIN OF datum_von, + jjjj(4) TYPE n, + mm(2) TYPE n, + tt(2) TYPE n, + END OF datum_von. + + DATA: BEGIN OF datum_bis, + jjjj(4) TYPE n, + mm(2) TYPE n, + tt(2) TYPE n, + END OF datum_bis. + + e_month = 0. + + CHECK NOT ( i_date_from IS INITIAL ) + AND NOT ( i_date_to IS INITIAL ). + + date_to = i_date_to. + IF i_incl_to = abap_true. + date_to = date_to + 1. + ENDIF. + + datum_von = i_date_from. + datum_bis = date_to. + + e_month = ( datum_bis-jjjj - datum_von-jjjj ) * 12 + + ( datum_bis-mm - datum_von-mm ). + ENDMETHOD. "MONTHS_BETWEEN_TWO_DATES +ENDCLASS. "ZCL_DATE_CALCULATION IMPLEMENTATION + +*----------------------------------------------------------------------* +* CLASS zcl_date_calculation_test DEFINITION +*----------------------------------------------------------------------* +* +*----------------------------------------------------------------------* +CLASS zcl_date_calculation_test DEFINITION FOR TESTING + " DURATION SHORT + " RISK LEVEL HARMLESS + "#AU Duration Medium + "#AU Risk_Level Harmless + . + PUBLIC SECTION. + METHODS: + months_between_two_dates FOR TESTING. +ENDCLASS. "zcl_date_calculation_test DEFINITION +*----------------------------------------------------------------------* +* CLASS zcl_date_calculation_test IMPLEMENTATION +*----------------------------------------------------------------------* +* +*----------------------------------------------------------------------* +CLASS zcl_date_calculation_test IMPLEMENTATION. + METHOD months_between_two_dates. + + DATA: date_from TYPE datum VALUE '20120101', + date_to TYPE datum VALUE '20121231'. + DATA: month TYPE i. + + zcl_date_calculation=>months_between_two_dates( + EXPORTING + i_date_from = date_from + i_date_to = date_to + i_incl_to = abap_true + IMPORTING + e_month = month + ). + + cl_aunit_assert=>assert_equals( + exp = 12 " Data Object with Expected Type + act = month " Data Object with Current Value + msg = 'Calculated date is wrong' " Message in Case of Error + ). + + ENDMETHOD. "months_between_two_dates +ENDCLASS. "zcl_date_calculation_test IMPLEMENTATION +*----------------------------------------------------------------------* +* CLASS zcl_helper DEFINITION +*----------------------------------------------------------------------* +* +*----------------------------------------------------------------------* +CLASS zcl_helper DEFINITION. + PUBLIC SECTION. + CLASS-METHODS: + load_image + IMPORTING + filename TYPE string + RETURNING value(r_image) TYPE xstring, + add_calendar + IMPORTING + i_date_from TYPE datum + i_date_to TYPE datum + i_from_row TYPE zexcel_cell_row + i_from_col TYPE zexcel_cell_column_alpha + i_day_style TYPE zexcel_cell_style + i_cw_style TYPE zexcel_cell_style + CHANGING + c_worksheet TYPE REF TO zcl_excel_worksheet, + add_calendar_landscape + IMPORTING + i_date_from TYPE datum + i_date_to TYPE datum + i_from_row TYPE zexcel_cell_row + i_from_col TYPE zexcel_cell_column_alpha + i_day_style TYPE zexcel_cell_style + i_cw_style TYPE zexcel_cell_style + CHANGING + c_worksheet TYPE REF TO zcl_excel_worksheet, + add_a2x_footer + IMPORTING + i_from_row TYPE zexcel_cell_row + i_from_col TYPE zexcel_cell_column_alpha + CHANGING + c_worksheet TYPE REF TO zcl_excel_worksheet, + add_calender_week + IMPORTING + i_date TYPE datum + i_row TYPE zexcel_cell_row + i_col TYPE zexcel_cell_column_alpha + i_style TYPE zexcel_cell_style + CHANGING + c_worksheet TYPE REF TO zcl_excel_worksheet. +ENDCLASS. "zcl_helper DEFINITION + +*----------------------------------------------------------------------* +* CLASS zcl_helper IMPLEMENTATION +*----------------------------------------------------------------------* +* +*----------------------------------------------------------------------* +CLASS zcl_helper IMPLEMENTATION. + METHOD load_image. + "Load samle image + DATA: lt_bin TYPE solix_tab, + lv_len TYPE i. + + CALL METHOD cl_gui_frontend_services=>gui_upload + EXPORTING + filename = filename + filetype = 'BIN' + IMPORTING + filelength = lv_len + CHANGING + data_tab = lt_bin + 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. + MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno + WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. + ENDIF. + + CALL FUNCTION 'SCMS_BINARY_TO_XSTRING' + EXPORTING + input_length = lv_len + IMPORTING + buffer = r_image + TABLES + binary_tab = lt_bin + EXCEPTIONS + failed = 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. + ENDMETHOD. "load_image + METHOD add_calendar. + DATA: day_names TYPE TABLE OF t246. + DATA: row TYPE zexcel_cell_row, + row_max TYPE i, + col_int TYPE zexcel_cell_column, + col_max TYPE i, + from_col_int TYPE zexcel_cell_column, + col TYPE zexcel_cell_column_alpha, + lr_col_dim TYPE REF TO zcl_excel_worksheet_columndime, + lr_row_dim TYPE REF TO zcl_excel_worksheet_rowdimensi. + DATA: lv_date TYPE datum, + value TYPE string, + weekday TYPE wotnr, + weekrow TYPE wotnr VALUE 1, + day TYPE i, + width TYPE f, + height TYPE f. + DATA: hyperlink TYPE REF TO zcl_excel_hyperlink. + + FIELD-SYMBOLS: <day_name> LIKE LINE OF day_names. + + lv_date = i_date_from. + from_col_int = zcl_excel_common=>convert_column2int( i_from_col ). + " Add description for Calendar Week + c_worksheet->set_cell( + EXPORTING + ip_column = i_from_col " Cell Column + ip_row = i_from_row " Cell Row + ip_value = 'CW'(001) " Cell Value + ip_style = i_cw_style + ). + + " Add Days + CALL FUNCTION 'DAY_NAMES_GET' + TABLES + day_names = day_names. + + LOOP AT day_names ASSIGNING <day_name>. + row = i_from_row. + col_int = from_col_int + <day_name>-wotnr. + col = zcl_excel_common=>convert_column2alpha( col_int ). + value = <day_name>-langt. + c_worksheet->set_cell( + EXPORTING + ip_column = col " Cell Column + ip_row = row " Cell Row + ip_value = value " Cell Value + ip_style = i_cw_style + ). + ENDLOOP. + + WHILE lv_date <= i_date_to. + day = lv_date+6(2). + CALL FUNCTION 'FIMA_X_DAY_IN_MONTH_COMPUTE' + EXPORTING + i_datum = lv_date + IMPORTING + e_wochentag_nr = weekday. + + row = i_from_row + weekrow. + col_int = from_col_int + weekday. + col = zcl_excel_common=>convert_column2alpha( col_int ). + + value = day. + CONDENSE value. + + c_worksheet->set_cell( + EXPORTING + ip_column = col " Cell Column + ip_row = row " Cell Row + ip_value = value " Cell Value + ip_style = i_day_style " Single-Character Indicator + ). + + IF weekday = 7. + " Add Calender Week + zcl_helper=>add_calender_week( + EXPORTING + i_date = lv_date + i_row = row + i_col = i_from_col + i_style = i_cw_style + CHANGING + c_worksheet = c_worksheet + ). + weekrow = weekrow + 1. + ENDIF. + lv_date = lv_date + 1. + ENDWHILE. + " Add Calender Week + zcl_helper=>add_calender_week( + EXPORTING + i_date = lv_date + i_row = row + i_col = i_from_col + i_style = i_cw_style + CHANGING + c_worksheet = c_worksheet + ). + " Add Created with abap2xlsx + row = row + 2. + zcl_helper=>add_a2x_footer( + EXPORTING + i_from_row = row + i_from_col = i_from_col + CHANGING + c_worksheet = c_worksheet + ). + col_int = from_col_int. + col_max = from_col_int + 7. + WHILE col_int <= col_max. + col = zcl_excel_common=>convert_column2alpha( col_int ). + IF sy-index = 1. + width = '5.0'. + ELSE. + width = '11.4'. + ENDIF. + lr_col_dim = c_worksheet->get_column_dimension( col ). + lr_col_dim->set_width( width ). + col_int = col_int + 1. + ENDWHILE. + row = i_from_row + 1. + row_max = i_from_row + 6. + WHILE row <= row_max. + height = 50. + lr_row_dim = c_worksheet->get_row_dimension( row ). + lr_row_dim->set_row_height( height ). + row = row + 1. + ENDWHILE. + ENDMETHOD. "add_calendar + METHOD add_a2x_footer. + DATA: value TYPE string, + hyperlink TYPE REF TO zcl_excel_hyperlink. + + value = 'Created with abap2xlsx. Find more information at http://abap2xlsx.org.'(002). + hyperlink = zcl_excel_hyperlink=>create_external_link( 'http://abap2xlsx.org' ). "#EC NOTEXT + c_worksheet->set_cell( + EXPORTING + ip_column = i_from_col " Cell Column + ip_row = i_from_row " Cell Row + ip_value = value " Cell Value + ip_hyperlink = hyperlink + ). + + ENDMETHOD. "add_a2x_footer + METHOD add_calendar_landscape. + DATA: day_names TYPE TABLE OF t246. + + DATA: lv_date TYPE datum, + day TYPE i, + value TYPE string, + weekday TYPE wotnr. + DATA: row TYPE zexcel_cell_row, + from_col_int TYPE zexcel_cell_column, + col_int TYPE zexcel_cell_column, + col TYPE zexcel_cell_column_alpha. + DATA: lo_col_dim TYPE REF TO zcl_excel_worksheet_columndime, + lo_row_dim TYPE REF TO zcl_excel_worksheet_rowdimensi. + + FIELD-SYMBOLS: <day_name> LIKE LINE OF day_names. + + lv_date = i_date_from. + " Add Days + CALL FUNCTION 'DAY_NAMES_GET' + TABLES + day_names = day_names. + + WHILE lv_date <= i_date_to. + day = lv_date+6(2). + CALL FUNCTION 'FIMA_X_DAY_IN_MONTH_COMPUTE' + EXPORTING + i_datum = lv_date + IMPORTING + e_wochentag_nr = weekday. + " Day name row + row = i_from_row. + col_int = from_col_int + day + 2. + col = zcl_excel_common=>convert_column2alpha( col_int ). + READ TABLE day_names ASSIGNING <day_name> + WITH KEY wotnr = weekday. + value = <day_name>-kurzt. + c_worksheet->set_cell( + EXPORTING + ip_column = col " Cell Column + ip_row = row " Cell Row + ip_value = value " Cell Value + ip_style = i_cw_style + ). + + " Day row + row = i_from_row + 1. + value = day. + CONDENSE value. + + c_worksheet->set_cell( + EXPORTING + ip_column = col " Cell Column + ip_row = row " Cell Row + ip_value = value " Cell Value + ip_style = i_day_style " Single-Character Indicator + ). + " width + lo_col_dim = c_worksheet->get_column_dimension( col ). + lo_col_dim->set_width( '3.6' ). + + + lv_date = lv_date + 1. + ENDWHILE. + " Add ABAP2XLSX Footer + row = i_from_row + 2. + c_worksheet->set_cell( + EXPORTING + ip_column = col " Cell Column + ip_row = row " Cell Row + ip_value = ' ' " Cell Value + ). + lo_row_dim = c_worksheet->get_row_dimension( row ). + lo_row_dim->set_row_height( '5.0' ). + row = i_from_row + 3. + zcl_helper=>add_a2x_footer( + EXPORTING + i_from_row = row + i_from_col = i_from_col + CHANGING + c_worksheet = c_worksheet + ). + + " Set with for all 31 coulumns + WHILE day < 32. + day = day + 1. + col_int = from_col_int + day + 2. + col = zcl_excel_common=>convert_column2alpha( col_int ). + " width + lo_col_dim = c_worksheet->get_column_dimension( col ). + lo_col_dim->set_width( '3.6' ). + ENDWHILE. + ENDMETHOD. "ADD_CALENDAR_LANDSCAPE + + METHOD add_calender_week. + DATA: week TYPE kweek, + week_int TYPE i, + value TYPE string. + " Add Calender Week + CALL FUNCTION 'DATE_GET_WEEK' + EXPORTING + date = i_date " Date for which the week should be calculated + IMPORTING + week = week. " Week for date (format:YYYYWW) + value = week+4(2). + week_int = value. + value = week_int. + CONDENSE value. + c_worksheet->set_cell( + EXPORTING + ip_column = i_col " Cell Column + ip_row = i_row " Cell Row + ip_value = value " Cell Value + ip_style = i_style + ). + ENDMETHOD. "add_calender_week +ENDCLASS. "zcl_helper IMPLEMENTATION + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_excel. + +DATA: lv_workdir TYPE string, + lv_upfile TYPE string. + +PARAMETERS: p_path TYPE zexcel_export_dir. + +AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path. + lv_workdir = p_path. + cl_gui_frontend_services=>directory_browse( EXPORTING initial_folder = lv_workdir + CHANGING selected_folder = lv_workdir ). + p_path = lv_workdir. + +INITIALIZATION. + cl_gui_frontend_services=>get_sapgui_workdir( CHANGING sapworkdir = lv_workdir ). + cl_gui_cfw=>flush( ). + p_path = lv_workdir. + +START-OF-SELECTION. + + IF p_path IS INITIAL. + p_path = lv_workdir. + ENDIF. + + cl_gui_frontend_services=>get_file_separator( CHANGING file_separator = sy-lisel ). + CONCATENATE p_path sy-lisel '01_HelloWorld.xlsx' INTO lv_upfile. + + SUBMIT zdemo_excel1 WITH p_path = p_path AND RETURN. " abap2xlsx Demo: Hello world + SUBMIT zdemo_excel2 WITH p_path = p_path AND RETURN. " abap2xlsx Demo: Styles + SUBMIT zdemo_excel3 WITH p_path = p_path AND RETURN. " abap2xlsx Demo: iTab binding + SUBMIT zdemo_excel4 WITH p_path = p_path AND RETURN. " abap2xlsx Demo: Multi sheets, page setup and sheet properties + SUBMIT zdemo_excel5 WITH p_path = p_path AND RETURN. " abap2xlsx Demo: Conditional formatting + SUBMIT zdemo_excel6 WITH p_path = p_path AND RETURN. " abap2xlsx Demo: Formulas + SUBMIT zdemo_excel7 WITH p_path = p_path AND RETURN. " abap2xlsx Demo: Conditional formatting + SUBMIT zdemo_excel8 WITH p_path = p_path AND RETURN. " abap2xlsx Demo: Ranges + SUBMIT zdemo_excel9 WITH p_path = p_path AND RETURN. " abap2xlsx Demo: Data validation + SUBMIT zdemo_excel10 WITH p_path = p_path AND RETURN. " abap2xlsx Demo: Bind table with field catalog + " zdemo_excel11 is not added because it has a selection screen and + " you also need to have business partners maintained in transaction BP + SUBMIT zdemo_excel12 WITH p_path = p_path AND RETURN. " abap2xlsx Demo: Column size + SUBMIT zdemo_excel13 WITH p_path = p_path AND RETURN. " abap2xlsx Demo: Merge cell + SUBMIT zdemo_excel14 WITH p_path = p_path AND RETURN. " abap2xlsx Demo: Alignment + SUBMIT zdemo_excel16 WITH p_path = p_path AND RETURN. " abap2xlsx Demo: Drawing + SUBMIT zdemo_excel17 WITH p_path = p_path AND RETURN. " abap2xlsx Demo: Lock sheet + SUBMIT zdemo_excel18 WITH p_path = p_path AND RETURN. " abap2xlsx Demo: Lock workbook + SUBMIT zdemo_excel19 WITH p_path = p_path AND RETURN. " abap2xlsx Demo: Set active sheet + " zdemo_excel20 is not added because it uses ALV and cannot be processed (OLE2) + SUBMIT zdemo_excel21 WITH p_path = p_path AND RETURN. " abap2xlsx Demo: Color Picker + SUBMIT zdemo_excel22 WITH p_path = p_path AND RETURN. " abap2xlsx Demo: Bind table with field catalog & sheet style + SUBMIT zdemo_excel23 WITH p_path = p_path AND RETURN. " abap2xlsx Demo: Multiple sheets with and w/o grid lines, print options + SUBMIT zdemo_excel24 WITH p_path = p_path AND RETURN. " abap2xlsx Demo: Multiple sheets with different default date formats + SUBMIT zdemo_excel25 AND RETURN. " abap2xlsx Demo: Create and xlsx on Application Server (could be executed in batch mode) + " zdemo_excel26 is not added because it uses ALV and cannot be processed (Native) + SUBMIT zdemo_excel27 WITH p_path = p_path AND RETURN. " abap2xlsx Demo: Conditional Formatting + SUBMIT zdemo_excel28 WITH p_path = p_path AND RETURN. " abap2xlsx Demo: CSV writer + " SUBMIT zdemo_excel29 WITH p_path = p_path AND RETURN. " abap2xlsx Demo: Macro enabled workbook + SUBMIT zdemo_excel30 WITH p_path = p_path AND RETURN. " abap2xlsx Demo: ABAP Cell data types + SUBMIT zdemo_excel31 WITH p_path = p_path AND RETURN. " abap2xlsx Demo: Autosize Column with different Font sizes + " zdemo_excel32 is not added because it uses ALV and cannot be processed (Native) + SUBMIT zdemo_excel33 WITH p_path = p_path AND RETURN. " abap2xlsx Demo: Table autofilter + SUBMIT zdemo_excel34 WITH p_path = p_path AND RETURN. " abap2xlsx Demo: Static Styles Chess + SUBMIT zdemo_excel35 WITH p_path = p_path AND RETURN. " abap2xlsx Demo: Static Styles + SUBMIT zdemo_excel36 WITH p_path = p_path AND RETURN. " abap2xlsx Demo: Style applied to sheet, column and single cell + SUBMIT zdemo_excel37 WITH p_upfile = lv_upfile + WITH p_path = p_path AND RETURN. " abap2xlsx Demo: Simplest call of the reader and writer - passthrough data + SUBMIT zdemo_excel38 WITH p_path = p_path AND RETURN. " abap2xlsx Demo: Show off integration of drawings ( here using the SAP-Icons ) + SUBMIT ZDEMO_EXCEL39 WITH p_path = p_path AND RETURN. " abap2xlsx Demo: Charts + " + " Reader/Writer Demo must always run at the end + " to make sure all documents where created + " + SUBMIT zdemo_excel15 WITH p_path = p_path AND RETURN. " Read Excel and write it back + + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL1 +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_excel1. + + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + lo_hyperlink TYPE REF TO zcl_excel_hyperlink, + column_dimension TYPE REF TO zcl_excel_worksheet_columndime. + +CONSTANTS: gc_save_file_name TYPE string VALUE '01_HelloWorld.xlsx'. +INCLUDE zdemo_excel_outputopt_incl. + + +START-OF-SELECTION. + " Creates active sheet + CREATE OBJECT lo_excel. + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). +* lo_worksheet->set_title( ip_title = 'Sheet1' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = 'Hello world' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 3 ip_value = sy-datum ). + lo_worksheet->set_cell( ip_column = 'C' ip_row = 3 ip_value = sy-uzeit ). + lo_hyperlink = zcl_excel_hyperlink=>create_external_link( iv_url = 'http://www.abap2xlsx.org' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 4 ip_value = 'Click here to visit abap2xlsx homepage' ip_hyperlink = lo_hyperlink ). + + column_dimension = lo_worksheet->get_column_dimension( ip_column = 'B' ). + column_dimension->set_width( ip_width = 11 ). + + + +*** Create output + lcl_output=>output( lo_excel ). + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL10 +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_excel10. + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + lo_style_conditional2 TYPE REF TO zcl_excel_style_conditional, + column_dimension TYPE REF TO zcl_excel_worksheet_columndime. + +DATA: lt_field_catalog TYPE zexcel_t_fieldcatalog, + ls_table_settings TYPE zexcel_s_table_settings, + ls_iconset TYPE zexcel_conditional_iconset. + +CONSTANTS: gc_save_file_name TYPE string VALUE '10_iTabFieldCatalog.xlsx'. +INCLUDE zdemo_excel_outputopt_incl. + + +START-OF-SELECTION. + + FIELD-SYMBOLS: <fs_field_catalog> TYPE zexcel_s_fieldcatalog. + + " Creates active sheet + CREATE OBJECT lo_excel. + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( 'Internal table' ). + + ls_iconset-iconset = zcl_excel_style_conditional=>c_iconset_5arrows. + 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'. + ls_iconset-showvalue = zcl_excel_style_conditional=>c_showvalue_true. + + "Conditional style + lo_style_conditional2 = lo_worksheet->add_new_conditional_style( ). + lo_style_conditional2->rule = zcl_excel_style_conditional=>c_rule_iconset. + lo_style_conditional2->mode_iconset = ls_iconset. + lo_style_conditional2->priority = 1. + + DATA lt_test TYPE TABLE OF sflight. + SELECT * FROM sflight INTO TABLE lt_test. "#EC CI_NOWHERE + + lt_field_catalog = zcl_excel_common=>get_fieldcatalog( ip_table = lt_test ). + + LOOP AT lt_field_catalog ASSIGNING <fs_field_catalog>. + CASE <fs_field_catalog>-fieldname. + WHEN 'CARRID'. + <fs_field_catalog>-position = 3. + <fs_field_catalog>-dynpfld = abap_true. + <fs_field_catalog>-totals_function = zcl_excel_table=>totals_function_count. + WHEN 'CONNID'. + <fs_field_catalog>-position = 4. + <fs_field_catalog>-dynpfld = abap_true. + WHEN 'FLDATE'. + <fs_field_catalog>-position = 2. + <fs_field_catalog>-dynpfld = abap_true. + WHEN 'PRICE'. + <fs_field_catalog>-position = 1. + <fs_field_catalog>-dynpfld = abap_true. + <fs_field_catalog>-totals_function = zcl_excel_table=>totals_function_sum. + <fs_field_catalog>-cond_style = lo_style_conditional2. + WHEN OTHERS. + <fs_field_catalog>-dynpfld = abap_false. + ENDCASE. + ENDLOOP. + + ls_table_settings-table_style = zcl_excel_table=>builtinstyle_medium5. + + lo_worksheet->bind_table( ip_table = lt_test + is_table_settings = ls_table_settings + it_field_catalog = lt_field_catalog ). + + column_dimension = lo_worksheet->get_column_dimension( ip_column = 'D' ). "make date field a bit wider + column_dimension->set_width( ip_width = 13 ). + + +*** Create output + lcl_output=>output( lo_excel ). + + + + + + + + + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL11 +*& Export Organisation and Contact Persons using ABAP2XLSX +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_excel11. + +TYPE-POOLS: abap. + +DATA: central_search TYPE bapibus1006_central_search, + addressdata_search TYPE bapibus1006_addr_search, + others_search TYPE bapibus1006_other_data. +DATA: searchresult TYPE TABLE OF bapibus1006_bp_addr, + return TYPE TABLE OF bapiret2. +DATA: lines TYPE i. +FIELD-SYMBOLS: <searchresult_line> LIKE LINE OF searchresult. +DATA: centraldata TYPE bapibus1006_central, + centraldataperson TYPE bapibus1006_central_person, + centraldataorganization TYPE bapibus1006_central_organ. +DATA: addressdata TYPE bapibus1006_address. +DATA: relationships TYPE TABLE OF bapibus1006_relations. +FIELD-SYMBOLS: <relationship> LIKE LINE OF relationships. +DATA: relationship_centraldata TYPE bapibus1006002_central. +DATA: relationship_addresses TYPE TABLE OF bapibus1006002_addresses. +FIELD-SYMBOLS: <relationship_address> LIKE LINE OF relationship_addresses. + +DATA: lt_download TYPE TABLE OF zexcel_s_org_rel. +FIELD-SYMBOLS: <download> LIKE LINE OF lt_download. + +CONSTANTS: gc_save_file_name TYPE string VALUE '11_Export_Org_and_Contact.xlsx'. +INCLUDE zdemo_excel_outputopt_incl. + + +PARAMETERS: md TYPE flag RADIOBUTTON GROUP act. + +SELECTION-SCREEN BEGIN OF BLOCK a WITH FRAME TITLE a. +PARAMETERS: partnerc TYPE bu_type DEFAULT 2, " Organizations + postlcod TYPE ad_pstcd1 DEFAULT '8334*', + country TYPE land1 DEFAULT 'DE', + maxsel TYPE bu_maxsel DEFAULT 100. +SELECTION-SCREEN END OF BLOCK a. + +PARAMETERS: rel TYPE flag RADIOBUTTON GROUP act DEFAULT 'X'. + +SELECTION-SCREEN BEGIN OF BLOCK b WITH FRAME TITLE b. +PARAMETERS: reltyp TYPE bu_reltyp DEFAULT 'BUR011', + partner TYPE bu_partner DEFAULT '191'. +SELECTION-SCREEN END OF BLOCK b. + +INITIALIZATION. + a = 'Select by master data'. + b = 'Select by relationship'. + +START-OF-SELECTION. + IF md = abap_true. + " Read all Companies by Master Data + central_search-partnercategory = partnerc. + addressdata_search-postl_cod1 = postlcod. + addressdata_search-country = country. + others_search-maxsel = maxsel. + others_search-no_search_for_contactperson = 'X'. + + CALL FUNCTION 'BAPI_BUPA_SEARCH_2' + EXPORTING + centraldata = central_search + addressdata = addressdata_search + OTHERS = others_search + TABLES + searchresult = searchresult + return = return. + + SORT searchresult BY partner. + DELETE ADJACENT DUPLICATES FROM searchresult COMPARING partner. + ELSEIF rel = abap_true. + " Read by Relationship + SELECT but050~partner1 AS partner FROM but050 + INNER JOIN but000 ON but000~partner = but050~partner1 AND but000~type = '2' + INTO CORRESPONDING FIELDS OF TABLE searchresult + WHERE but050~partner2 = partner + AND but050~reltyp = reltyp. + ENDIF. + + DESCRIBE TABLE searchresult LINES lines. + WRITE: / 'Number of search results: ', lines. + + LOOP AT searchresult ASSIGNING <searchresult_line>. + " Read Details of Organization + CALL FUNCTION 'BAPI_BUPA_CENTRAL_GETDETAIL' + EXPORTING + businesspartner = <searchresult_line>-partner + IMPORTING + centraldataorganization = centraldataorganization. + " Read Standard Address of Organization + CALL FUNCTION 'BAPI_BUPA_ADDRESS_GETDETAIL' + EXPORTING + businesspartner = <searchresult_line>-partner + IMPORTING + addressdata = addressdata. + + " Add Organization to Download + APPEND INITIAL LINE TO lt_download ASSIGNING <download>. + " Fill Organization Partner Numbers + CALL FUNCTION 'BAPI_BUPA_GET_NUMBERS' + EXPORTING + businesspartner = <searchresult_line>-partner + IMPORTING + businesspartnerout = <download>-org_number + businesspartnerguidout = <download>-org_guid. + + MOVE-CORRESPONDING centraldataorganization TO <download>. + MOVE-CORRESPONDING addressdata TO <download>. + CLEAR: addressdata. + + " Read all Relationships + CLEAR: relationships. + CALL FUNCTION 'BAPI_BUPA_RELATIONSHIPS_GET' + EXPORTING + businesspartner = <searchresult_line>-partner + TABLES + relationships = relationships. + DELETE relationships WHERE relationshipcategory <> 'BUR001'. + LOOP AT relationships ASSIGNING <relationship>. + " Read details of Contact person + CALL FUNCTION 'BAPI_BUPA_CENTRAL_GETDETAIL' + EXPORTING + businesspartner = <relationship>-partner2 + IMPORTING + centraldata = centraldata + centraldataperson = centraldataperson. + " Read details of the Relationship + CALL FUNCTION 'BAPI_BUPR_CONTP_GETDETAIL' + EXPORTING + businesspartner = <relationship>-partner1 + contactperson = <relationship>-partner2 + IMPORTING + centraldata = relationship_centraldata. + " Read relationship address + CLEAR: relationship_addresses. + + CALL FUNCTION 'BAPI_BUPR_CONTP_ADDRESSES_GET' + EXPORTING + businesspartner = <relationship>-partner1 + contactperson = <relationship>-partner2 + TABLES + addresses = relationship_addresses. + + READ TABLE relationship_addresses + ASSIGNING <relationship_address> + WITH KEY standardaddress = 'X'. + + IF <relationship_address> IS ASSIGNED. + " Read Relationship Address + CLEAR addressdata. + CALL FUNCTION 'BAPI_BUPA_ADDRESS_GETDETAIL' + EXPORTING + businesspartner = <searchresult_line>-partner + addressguid = <relationship_address>-addressguid + IMPORTING + addressdata = addressdata. + + APPEND INITIAL LINE TO lt_download ASSIGNING <download>. + CALL FUNCTION 'BAPI_BUPA_GET_NUMBERS' + EXPORTING + businesspartner = <relationship>-partner1 + IMPORTING + businesspartnerout = <download>-org_number + businesspartnerguidout = <download>-org_guid. + + CALL FUNCTION 'BAPI_BUPA_GET_NUMBERS' + EXPORTING + businesspartner = <relationship>-partner2 + IMPORTING + businesspartnerout = <download>-contpers_number + businesspartnerguidout = <download>-contpers_guid. + + MOVE-CORRESPONDING centraldataorganization TO <download>. + MOVE-CORRESPONDING addressdata TO <download>. + MOVE-CORRESPONDING centraldataperson TO <download>. + MOVE-CORRESPONDING relationship_centraldata TO <download>. + + WRITE: / <relationship>-partner1, <relationship>-partner2. + WRITE: centraldataorganization-name1(20), centraldataorganization-name2(10). + WRITE: centraldataperson-firstname(15), centraldataperson-lastname(15). + WRITE: addressdata-street(25), addressdata-house_no, + addressdata-postl_cod1, addressdata-city(25). + ENDIF. + ENDLOOP. + + ENDLOOP. + + DATA: lo_excel TYPE REF TO zcl_excel, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + lo_style_body TYPE REF TO zcl_excel_style, + lo_border_dark TYPE REF TO zcl_excel_style_border, + column_dimension TYPE REF TO zcl_excel_worksheet_columndime, + row_dimension TYPE REF TO zcl_excel_worksheet_rowdimensi. + + DATA: lv_style_body_even_guid TYPE zexcel_cell_style, + lv_style_body_green TYPE zexcel_cell_style. + + DATA: row TYPE zexcel_cell_row. + + DATA: lv_file TYPE xstring, + lv_bytecount TYPE i, + lt_file_tab TYPE solix_tab. + + DATA: lt_field_catalog TYPE zexcel_t_fieldcatalog, + ls_table_settings TYPE zexcel_s_table_settings. + + DATA: column TYPE zexcel_cell_column, + column_alpha TYPE zexcel_cell_column_alpha, + value TYPE zexcel_cell_value. + + FIELD-SYMBOLS: <fs_field_catalog> TYPE zexcel_s_fieldcatalog. + + " Creates active sheet + CREATE OBJECT lo_excel. + + " Create border object + CREATE OBJECT lo_border_dark. + lo_border_dark->border_color-rgb = zcl_excel_style_color=>c_black. + lo_border_dark->border_style = zcl_excel_style_border=>c_border_thin. + "Create style with border even + lo_style_body = lo_excel->add_new_style( ). + lo_style_body->fill->fgcolor-rgb = zcl_excel_style_color=>c_yellow. + lo_style_body->borders->allborders = lo_border_dark. + lv_style_body_even_guid = lo_style_body->get_guid( ). + "Create style with border and green fill + lo_style_body = lo_excel->add_new_style( ). + lo_style_body->fill->fgcolor-rgb = zcl_excel_style_color=>c_green. + lo_style_body->borders->allborders = lo_border_dark. + lv_style_body_green = lo_style_body->get_guid( ). + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( 'Internal table' ). + + lt_field_catalog = zcl_excel_common=>get_fieldcatalog( ip_table = lt_download ). + + LOOP AT lt_field_catalog ASSIGNING <fs_field_catalog>. + CASE <fs_field_catalog>-fieldname. + WHEN 'ORG_NUMBER'. + <fs_field_catalog>-position = 1. + <fs_field_catalog>-dynpfld = abap_true. + WHEN 'CONTPERS_NUMBER'. + <fs_field_catalog>-position = 2. + <fs_field_catalog>-dynpfld = abap_true. + WHEN 'NAME1'. + <fs_field_catalog>-position = 3. + <fs_field_catalog>-dynpfld = abap_true. + WHEN 'NAME2'. + <fs_field_catalog>-position = 4. + <fs_field_catalog>-dynpfld = abap_true. + WHEN 'STREET'. + <fs_field_catalog>-position = 5. + <fs_field_catalog>-dynpfld = abap_true. + WHEN 'HOUSE_NO'. + <fs_field_catalog>-position = 6. + <fs_field_catalog>-dynpfld = abap_true. + WHEN 'POSTL_COD1'. + <fs_field_catalog>-position = 7. + <fs_field_catalog>-dynpfld = abap_true. + WHEN 'CITY'. + <fs_field_catalog>-position = 8. + <fs_field_catalog>-dynpfld = abap_true. + WHEN 'COUNTRYISO'. + <fs_field_catalog>-position = 9. + <fs_field_catalog>-dynpfld = abap_true. + WHEN 'FIRSTNAME'. + <fs_field_catalog>-position = 10. + <fs_field_catalog>-dynpfld = abap_true. + WHEN 'LASTNAME'. + <fs_field_catalog>-position = 11. + <fs_field_catalog>-dynpfld = abap_true. + WHEN 'FUNCTIONNAME'. + <fs_field_catalog>-position = 12. + <fs_field_catalog>-dynpfld = abap_true. + WHEN 'DEPARTMENTNAME'. + <fs_field_catalog>-position = 13. + <fs_field_catalog>-dynpfld = abap_true. + WHEN 'TEL1_NUMBR'. + <fs_field_catalog>-position = 14. + <fs_field_catalog>-dynpfld = abap_true. + WHEN 'TEL1_EXT'. + <fs_field_catalog>-position = 15. + <fs_field_catalog>-dynpfld = abap_true. + WHEN 'FAX_NUMBER'. + <fs_field_catalog>-position = 16. + <fs_field_catalog>-dynpfld = abap_true. + WHEN 'FAX_EXTENS'. + <fs_field_catalog>-position = 17. + <fs_field_catalog>-dynpfld = abap_true. + WHEN 'E_MAIL'. + <fs_field_catalog>-position = 18. + <fs_field_catalog>-dynpfld = abap_true. + WHEN OTHERS. + <fs_field_catalog>-dynpfld = abap_false. + ENDCASE. + ENDLOOP. + + ls_table_settings-top_left_column = 'A'. + ls_table_settings-top_left_row = '2'. + ls_table_settings-table_style = zcl_excel_table=>builtinstyle_medium5. + + lo_worksheet->bind_table( ip_table = lt_download + is_table_settings = ls_table_settings + it_field_catalog = lt_field_catalog ). + LOOP AT lt_download ASSIGNING <download>. + row = sy-tabix + 2. + IF NOT <download>-org_number IS INITIAL + AND <download>-contpers_number IS INITIAL. + " Mark fields of Organization which can be changed green + lo_worksheet->set_cell_style( + ip_column = 'C' + ip_row = row + ip_style = lv_style_body_green + ). + lo_worksheet->set_cell_style( + ip_column = 'D' + ip_row = row + ip_style = lv_style_body_green + ). +* CATCH zcx_excel. " Exceptions for ABAP2XLSX + ELSEIF NOT <download>-org_number IS INITIAL + AND NOT <download>-contpers_number IS INITIAL. + " Mark fields of Relationship which can be changed green + lo_worksheet->set_cell_style( + ip_column = 'L' ip_row = row ip_style = lv_style_body_green + ). + lo_worksheet->set_cell_style( + ip_column = 'M' ip_row = row ip_style = lv_style_body_green + ). + lo_worksheet->set_cell_style( + ip_column = 'N' ip_row = row ip_style = lv_style_body_green + ). + lo_worksheet->set_cell_style( + ip_column = 'O' ip_row = row ip_style = lv_style_body_green + ). + lo_worksheet->set_cell_style( + ip_column = 'P' ip_row = row ip_style = lv_style_body_green + ). + lo_worksheet->set_cell_style( + ip_column = 'Q' ip_row = row ip_style = lv_style_body_green + ). + lo_worksheet->set_cell_style( + ip_column = 'R' ip_row = row ip_style = lv_style_body_green + ). + ENDIF. + ENDLOOP. + " Add Fieldnames in first row and hide the row + LOOP AT lt_field_catalog ASSIGNING <fs_field_catalog> + WHERE position <> '' AND dynpfld = abap_true. + column = <fs_field_catalog>-position. + column_alpha = zcl_excel_common=>convert_column2alpha( column ). + value = <fs_field_catalog>-fieldname. + lo_worksheet->set_cell( ip_column = column_alpha + ip_row = 1 + ip_value = value + ip_style = lv_style_body_even_guid ). + ENDLOOP. + " Hide first row + row_dimension = lo_worksheet->get_row_dimension( 1 ). + row_dimension->set_visible( abap_false ). + + DATA: highest_column TYPE zexcel_cell_column, + count TYPE int4, + col_alpha TYPE zexcel_cell_column_alpha. + + highest_column = lo_worksheet->get_highest_column( ). + count = 1. + WHILE count <= highest_column. + col_alpha = zcl_excel_common=>convert_column2alpha( ip_column = count ). + column_dimension = lo_worksheet->get_column_dimension( ip_column = col_alpha ). + column_dimension->set_auto_size( ip_auto_size = abap_true ). + count = count + 1. + ENDWHILE. +* " Set Column width manuall +* column_dimension = lo_worksheet->get_column_dimension( ip_column = 'A' ). +* column_dimension->set_width( ip_width = 11 ). +* column_dimension = lo_worksheet->get_column_dimension( ip_column = 'B' ). +* column_dimension->set_width( ip_width = 11 ). +* column_dimension = lo_worksheet->get_column_dimension( ip_column = 'C' ). +* column_dimension->set_width( ip_width = 35 ). +* column_dimension = lo_worksheet->get_column_dimension( ip_column = 'E' ). +* column_dimension->set_width( ip_width = 18 ). +* column_dimension = lo_worksheet->get_column_dimension( ip_column = 'F' ). +* column_dimension->set_width( ip_width = 5 ). +* column_dimension = lo_worksheet->get_column_dimension( ip_column = 'G' ). +* column_dimension->set_width( ip_width = 6 ). +* column_dimension = lo_worksheet->get_column_dimension( ip_column = 'H' ). +* column_dimension->set_width( ip_width = 12 ). +* column_dimension = lo_worksheet->get_column_dimension( ip_column = 'I' ). +* column_dimension->set_width( ip_width = 3 ). +* column_dimension = lo_worksheet->get_column_dimension( ip_column = 'J' ). +* column_dimension->set_width( ip_width = 13 ). +* column_dimension = lo_worksheet->get_column_dimension( ip_column = 'K' ). +* column_dimension->set_width( ip_width = 13 ). +* column_dimension = lo_worksheet->get_column_dimension( ip_column = 'L' ). +* column_dimension->set_width( ip_width = 13 ). +* column_dimension = lo_worksheet->get_column_dimension( ip_column = 'M' ). +* column_dimension->set_width( ip_width = 13 ). +* column_dimension = lo_worksheet->get_column_dimension( ip_column = 'N' ). +* column_dimension->set_width( ip_width = 12 ). +* column_dimension = lo_worksheet->get_column_dimension( ip_column = 'O' ). +* column_dimension->set_width( ip_width = 9 ). +* column_dimension = lo_worksheet->get_column_dimension( ip_column = 'P' ). +* column_dimension->set_width( ip_width = 12 ). +* column_dimension = lo_worksheet->get_column_dimension( ip_column = 'Q' ). +* column_dimension->set_width( ip_width = 9 ). +* column_dimension = lo_worksheet->get_column_dimension( ip_column = 'R' ). +* column_dimension->set_width( ip_width = 40 ). + + +*** Create output + lcl_output=>output( lo_excel ). + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL12 +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_excel12. + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + column_dimension TYPE REF TO zcl_excel_worksheet_columndime, + row_dimension TYPE REF TO zcl_excel_worksheet_rowdimensi. + +DATA: lv_file TYPE xstring, + lv_bytecount TYPE i, + lt_file_tab TYPE solix_tab. + +DATA: lv_full_path TYPE string, + lv_workdir TYPE string, + lv_file_separator TYPE c. + +CONSTANTS: gc_save_file_name TYPE string VALUE '12_HideSizeOutlineRowsAndColumns.xlsx'. +INCLUDE zdemo_excel_outputopt_incl. + +START-OF-SELECTION. + + " Creates active sheet + CREATE OBJECT lo_excel. + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( 'Sheet1' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = 'Hello world in AutoSize column' ). + lo_worksheet->set_cell( ip_column = 'C' ip_row = 3 ip_value = 'Hello world in a column width size 50' ). + lo_worksheet->set_cell( ip_column = 'D' ip_row = 4 ip_value = 'Hello world (hidden column)' ). + lo_worksheet->set_cell( ip_column = 'F' ip_row = 2 ip_value = 'Outline column level 0' ). + lo_worksheet->set_cell( ip_column = 'G' ip_row = 2 ip_value = 'Outline column level 1' ). + lo_worksheet->set_cell( ip_column = 'H' ip_row = 2 ip_value = 'Outline column level 2' ). + lo_worksheet->set_cell( ip_column = 'I' ip_row = 2 ip_value = 'Small' ). + + + lo_worksheet->set_cell( ip_column = 'A' ip_row = 1 ip_value = 'Hello world (hidden row)' ). + lo_worksheet->set_cell( ip_column = 'E' ip_row = 5 ip_value = 'Hello world in a row height size 20' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 6 ip_value = 'Outline row level 0' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 7 ip_value = 'Outline row level 1' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 8 ip_value = 'Outline row level 2' ). + + lo_worksheet->zif_excel_sheet_properties~summarybelow = zif_excel_sheet_properties=>c_below_off. " By default is on + lo_worksheet->zif_excel_sheet_properties~summaryright = zif_excel_sheet_properties=>c_right_off. " By default is on + + " Column Settings + " Auto size + column_dimension = lo_worksheet->get_column_dimension( ip_column = 'B' ). + column_dimension->set_auto_size( ip_auto_size = abap_true ). + column_dimension = lo_worksheet->get_column_dimension( ip_column = 'I' ). + column_dimension->set_auto_size( ip_auto_size = abap_true ). + " Manual Width + column_dimension = lo_worksheet->get_column_dimension( ip_column = 'C' ). + column_dimension->set_width( ip_width = 50 ). + column_dimension = lo_worksheet->get_column_dimension( ip_column = 'D' ). + column_dimension->set_visible( ip_visible = abap_false ). + " Implementation in the Writer is not working yet ===== TODO ===== + column_dimension = lo_worksheet->get_column_dimension( ip_column = 'F' ). + column_dimension->set_outline_level( ip_outline_level = 0 ). + column_dimension = lo_worksheet->get_column_dimension( ip_column = 'G' ). + column_dimension->set_outline_level( ip_outline_level = 1 ). + column_dimension = lo_worksheet->get_column_dimension( ip_column = 'H' ). + column_dimension->set_outline_level( ip_outline_level = 2 ). + + row_dimension = lo_worksheet->get_row_dimension( ip_row = 1 ). + row_dimension->set_visible( ip_visible = abap_false ). + row_dimension = lo_worksheet->get_row_dimension( ip_row = 5 ). + row_dimension->set_row_height( ip_row_height = 20 ). + " Implementation in the Writer is not working yet ===== TODO ===== + row_dimension = lo_worksheet->get_row_dimension( ip_row = 6 ). + row_dimension->set_outline_level( ip_outline_level = 0 ). + row_dimension = lo_worksheet->get_row_dimension( ip_row = 7 ). + row_dimension->set_outline_level( ip_outline_level = 1 ). + row_dimension = lo_worksheet->get_row_dimension( ip_row = 8 ). + row_dimension->set_outline_level( ip_outline_level = 2 ). + +*** Create output + lcl_output=>output( lo_excel ). + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL13 +*& +*&---------------------------------------------------------------------* +*& Example by: Alvaro "Blag" Tejada Galindo. +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_excel13. + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + lv_style_bold_border_guid TYPE zexcel_cell_style, + lo_style_bold_border TYPE REF TO zcl_excel_style, + lo_border_dark TYPE REF TO zcl_excel_style_border. + + +CONSTANTS: gc_save_file_name TYPE string VALUE '13_MergedCells.xlsx'. +INCLUDE zdemo_excel_outputopt_incl. + +START-OF-SELECTION. + + CREATE OBJECT lo_excel. + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( 'sheet1' ). + + CREATE OBJECT lo_border_dark. + lo_border_dark->border_color-rgb = zcl_excel_style_color=>c_black. + lo_border_dark->border_style = zcl_excel_style_border=>c_border_thin. + + lo_style_bold_border = lo_excel->add_new_style( ). + lo_style_bold_border->font->bold = abap_true. + lo_style_bold_border->font->italic = abap_false. + lo_style_bold_border->font->color-rgb = zcl_excel_style_color=>c_black. + lo_style_bold_border->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_center. + lo_style_bold_border->borders->allborders = lo_border_dark. + lv_style_bold_border_guid = lo_style_bold_border->get_guid( ). + + lo_worksheet->set_cell( ip_row = 2 ip_column = 'A' ip_value = 'Test' ). + + lo_worksheet->set_cell( ip_row = 2 ip_column = 'B' ip_value = 'Banana' ip_style = lv_style_bold_border_guid ). + lo_worksheet->set_cell( ip_row = 2 ip_column = 'C' ip_value = '' ip_style = lv_style_bold_border_guid ). + lo_worksheet->set_cell( ip_row = 2 ip_column = 'D' ip_value = '' ip_style = lv_style_bold_border_guid ). + lo_worksheet->set_cell( ip_row = 2 ip_column = 'E' ip_value = '' ip_style = lv_style_bold_border_guid ). + lo_worksheet->set_cell( ip_row = 2 ip_column = 'F' ip_value = '' ip_style = lv_style_bold_border_guid ). + lo_worksheet->set_cell( ip_row = 2 ip_column = 'G' ip_value = '' ip_style = lv_style_bold_border_guid ). + lo_worksheet->set_cell( ip_row = 4 ip_column = 'B' ip_value = 'Apple' ip_style = lv_style_bold_border_guid ). + lo_worksheet->set_cell( ip_row = 4 ip_column = 'C' ip_value = '' ip_style = lv_style_bold_border_guid ). + lo_worksheet->set_cell( ip_row = 4 ip_column = 'D' ip_value = '' ip_style = lv_style_bold_border_guid ). + lo_worksheet->set_cell( ip_row = 4 ip_column = 'E' ip_value = '' ip_style = lv_style_bold_border_guid ). + lo_worksheet->set_cell( ip_row = 4 ip_column = 'F' ip_value = '' ip_style = lv_style_bold_border_guid ). + lo_worksheet->set_cell( ip_row = 4 ip_column = 'G' ip_value = '' ip_style = lv_style_bold_border_guid ). + + lo_worksheet->set_merge( ip_row = 4 ip_column_start = 'B' ip_column_end = 'G' ). + + " Test also if merge works when oher merged chells are empty + lo_worksheet->set_cell( ip_row = 6 ip_column = 'B' ip_value = 'Tomato' ). + lo_worksheet->set_merge( ip_row = 6 ip_column_start = 'B' ip_column_end = 'G' ). + + " Test the patch provided by Victor Alekhin to merge cells in one column + lo_worksheet->set_cell( ip_row = 8 ip_column = 'B' ip_value = 'Merge cells also over multiple rows by Victor Alekhin' ). + lo_worksheet->set_merge( ip_row = 8 ip_column_start = 'B' ip_column_end = 'G' ip_row_to = 10 ). + + " Test the patch provided by Alexander Budeyev with different column merges + lo_worksheet->set_cell( ip_row = 12 ip_column = 'B' ip_value = 'Merge cells with different merges by Alexander Budeyev' ). + lo_worksheet->set_cell( ip_row = 13 ip_column = 'B' ip_value = 'Test' ). + + lo_worksheet->set_cell( ip_row = 13 ip_column = 'D' ip_value = 'Banana' ip_style = lv_style_bold_border_guid ). + lo_worksheet->set_cell( ip_row = 14 ip_column = 'D' ip_value = '' ip_style = lv_style_bold_border_guid ). + lo_worksheet->set_cell( ip_row = 13 ip_column = 'E' ip_value = 'Apple' ip_style = lv_style_bold_border_guid ). + lo_worksheet->set_cell( ip_row = 13 ip_column = 'F' ip_value = '' ip_style = lv_style_bold_border_guid ). + + " Test merge (issue) + lo_worksheet->set_merge( ip_row = 13 ip_column_start = 'B' ip_column_end = 'C' ip_row_to = 15 ). + lo_worksheet->set_merge( ip_row = 13 ip_column_start = 'D' ip_column_end = 'D' ip_row_to = 14 ). + lo_worksheet->set_merge( ip_row = 13 ip_column_start = 'E' ip_column_end = 'F' ). + + + +*** Create output + lcl_output=>output( lo_excel ). + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL14 +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_excel14. + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + lo_style_center TYPE REF TO zcl_excel_style, + lo_style_right TYPE REF TO zcl_excel_style, + lo_style_left TYPE REF TO zcl_excel_style, + lo_style_general TYPE REF TO zcl_excel_style, + lo_style_bottom TYPE REF TO zcl_excel_style, + lo_style_middle TYPE REF TO zcl_excel_style, + lo_style_top TYPE REF TO zcl_excel_style, + lo_style_justify TYPE REF TO zcl_excel_style, + lo_style_mixed TYPE REF TO zcl_excel_style, + lo_style_mixed_wrap TYPE REF TO zcl_excel_style, + lo_style_rotated TYPE REF TO zcl_excel_style, + lo_style_shrink TYPE REF TO zcl_excel_style, + lo_style_indent TYPE REF TO zcl_excel_style, + lv_style_center_guid TYPE zexcel_cell_style, + lv_style_right_guid TYPE zexcel_cell_style, + lv_style_left_guid TYPE zexcel_cell_style, + lv_style_general_guid TYPE zexcel_cell_style, + lv_style_bottom_guid TYPE zexcel_cell_style, + lv_style_middle_guid TYPE zexcel_cell_style, + lv_style_top_guid TYPE zexcel_cell_style, + lv_style_justify_guid TYPE zexcel_cell_style, + lv_style_mixed_guid TYPE zexcel_cell_style, + lv_style_mixed_wrap_guid TYPE zexcel_cell_style, + lv_style_rotated_guid TYPE zexcel_cell_style, + lv_style_shrink_guid TYPE zexcel_cell_style, + lv_style_indent_guid TYPE zexcel_cell_style. + +DATA: lo_row_dimension TYPE REF TO zcl_excel_worksheet_rowdimensi. + +CONSTANTS: gc_save_file_name TYPE string VALUE '14_Alignment.xlsx'. +INCLUDE zdemo_excel_outputopt_incl. + + +START-OF-SELECTION. + + CREATE OBJECT lo_excel. + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( 'sheet1' ). + + "Center + lo_style_center = lo_excel->add_new_style( ). + lo_style_center->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_center. + lv_style_center_guid = lo_style_center->get_guid( ). + "Right + lo_style_right = lo_excel->add_new_style( ). + lo_style_right->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_right. + lv_style_right_guid = lo_style_right->get_guid( ). + "Left + lo_style_left = lo_excel->add_new_style( ). + lo_style_left->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_left. + lv_style_left_guid = lo_style_left->get_guid( ). + "General + lo_style_general = lo_excel->add_new_style( ). + lo_style_general->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_general. + lv_style_general_guid = lo_style_general->get_guid( ). + "Bottom + lo_style_bottom = lo_excel->add_new_style( ). + lo_style_bottom->alignment->vertical = zcl_excel_style_alignment=>c_vertical_bottom. + lv_style_bottom_guid = lo_style_bottom->get_guid( ). + "Middle + lo_style_middle = lo_excel->add_new_style( ). + lo_style_middle->alignment->vertical = zcl_excel_style_alignment=>c_vertical_center. + lv_style_middle_guid = lo_style_middle->get_guid( ). + "Top + lo_style_top = lo_excel->add_new_style( ). + lo_style_top->alignment->vertical = zcl_excel_style_alignment=>c_vertical_top. + lv_style_top_guid = lo_style_top->get_guid( ). + "Justify + lo_style_justify = lo_excel->add_new_style( ). + lo_style_justify->alignment->vertical = zcl_excel_style_alignment=>c_vertical_justify. + lv_style_justify_guid = lo_style_justify->get_guid( ). + + "Shrink + lo_style_shrink = lo_excel->add_new_style( ). + lo_style_shrink->alignment->shrinktofit = abap_true. + lv_style_shrink_guid = lo_style_shrink->get_guid( ). + + "Indent + lo_style_indent = lo_excel->add_new_style( ). + lo_style_indent->alignment->indent = 5. + lv_style_indent_guid = lo_style_indent->get_guid( ). + + "Middle / Centered / Wrap + lo_style_mixed_wrap = lo_excel->add_new_style( ). + lo_style_mixed_wrap->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_center. + lo_style_mixed_wrap->alignment->vertical = zcl_excel_style_alignment=>c_vertical_center. + lo_style_mixed_wrap->alignment->wraptext = abap_true. + lv_style_mixed_wrap_guid = lo_style_mixed_wrap->get_guid( ). + + "Middle / Centered / Wrap + lo_style_mixed = lo_excel->add_new_style( ). + lo_style_mixed->alignment->horizontal = zcl_excel_style_alignment=>c_horizontal_center. + lo_style_mixed->alignment->vertical = zcl_excel_style_alignment=>c_vertical_center. + lv_style_mixed_guid = lo_style_mixed->get_guid( ). + + "Center + 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° + lv_style_rotated_guid = lo_style_rotated->get_guid( ). + + + " Set row size for first 7 rows to 40 + DO 7 TIMES. + lo_row_dimension = lo_worksheet->get_row_dimension( sy-index ). + lo_row_dimension->set_row_height( 40 ). + ENDDO. + + "Horizontal alignment + lo_worksheet->set_cell( ip_row = 4 ip_column = 'B' ip_value = 'Centered Text' ip_style = lv_style_center_guid ). + lo_worksheet->set_cell( ip_row = 5 ip_column = 'B' ip_value = 'Right Text' ip_style = lv_style_right_guid ). + lo_worksheet->set_cell( ip_row = 6 ip_column = 'B' ip_value = 'Left Text' ip_style = lv_style_left_guid ). + lo_worksheet->set_cell( ip_row = 7 ip_column = 'B' ip_value = 'General Text' ip_style = lv_style_general_guid ). + + " Shrink & indent + lo_worksheet->set_cell( ip_row = 4 ip_column = 'F' ip_value = 'Text shrinked' ip_style = lv_style_shrink_guid ). + lo_worksheet->set_cell( ip_row = 5 ip_column = 'F' ip_value = 'Text indented' ip_style = lv_style_indent_guid ). + + "Vertical alignment + + lo_worksheet->set_cell( ip_row = 4 ip_column = 'D' ip_value = 'Bottom Text' ip_style = lv_style_bottom_guid ). + lo_worksheet->set_cell( ip_row = 5 ip_column = 'D' ip_value = 'Middle Text' ip_style = lv_style_middle_guid ). + lo_worksheet->set_cell( ip_row = 6 ip_column = 'D' ip_value = 'Top Text' ip_style = lv_style_top_guid ). + lo_worksheet->set_cell( ip_row = 7 ip_column = 'D' ip_value = 'Justify Text' ip_style = lv_style_justify_guid ). + + " Wrapped + lo_worksheet->set_cell( ip_row = 10 ip_column = 'B' + ip_value = 'This is a wrapped text centered in the middle' + ip_style = lv_style_mixed_wrap_guid ). + + " Rotated + lo_worksheet->set_cell( ip_row = 10 ip_column = 'D' + ip_value = 'This is a centered text rotated by -75°' + ip_style = lv_style_rotated_guid ). + + " forced line break + DATA: lv_value TYPE string. + CONCATENATE 'This is a wrapped text centered in the middle' cl_abap_char_utilities=>cr_lf + 'and a manuall line break.' INTO lv_value. + lo_worksheet->set_cell( ip_row = 11 ip_column = 'B' + ip_value = lv_value + ip_style = lv_style_mixed_guid ). + +*** Create output + lcl_output=>output( lo_excel ). + + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL15 +*& +*&---------------------------------------------------------------------* +*& 2010-10-30, Gregor Wolf: +*& Added the functionality to ouput the read table content +*& 2011-12-19, Shahrin Shahrulzaman: +*& Added the functionality to have multiple input and output files +*&---------------------------------------------------------------------* + +REPORT zdemo_excel15. + +TYPE-POOLS: abap. + +TYPES: + BEGIN OF t_demo_excel15, + input TYPE string, + END OF t_demo_excel15. + +DATA: excel TYPE REF TO zcl_excel, + lo_excel_writer TYPE REF TO zif_excel_writer, + reader TYPE REF TO zif_excel_reader. + +DATA: ex TYPE REF TO zcx_excel, + msg TYPE string. + +DATA: lv_file TYPE xstring, + lv_bytecount TYPE i, + lt_file_tab TYPE solix_tab. + +DATA: lv_workdir TYPE string, + output_file_path TYPE string, + input_file_path TYPE string, + lv_file_separator TYPE c. + +DATA: worksheet TYPE REF TO zcl_excel_worksheet, + highest_column TYPE zexcel_cell_column, + highest_row TYPE int4, + column TYPE zexcel_cell_column VALUE 1, + col_str TYPE zexcel_cell_column_alpha, + row TYPE int4 VALUE 1, + value TYPE zexcel_cell_value. + +DATA: + lt_files TYPE TABLE OF t_demo_excel15. +FIELD-SYMBOLS: <wa_files> TYPE t_demo_excel15. + +PARAMETERS: p_path TYPE zexcel_export_dir, + p_noout TYPE xfeld DEFAULT abap_true. + + +AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path. + lv_workdir = p_path. + cl_gui_frontend_services=>directory_browse( EXPORTING initial_folder = lv_workdir + CHANGING selected_folder = lv_workdir ). + p_path = lv_workdir. + +INITIALIZATION. + cl_gui_frontend_services=>get_sapgui_workdir( CHANGING sapworkdir = lv_workdir ). + cl_gui_cfw=>flush( ). + p_path = lv_workdir. + + APPEND INITIAL LINE TO lt_files ASSIGNING <wa_files>. + <wa_files>-input = '01_HelloWorld.xlsx'. + APPEND INITIAL LINE TO lt_files ASSIGNING <wa_files>. + <wa_files>-input = '02_Styles.xlsx'. + APPEND INITIAL LINE TO lt_files ASSIGNING <wa_files>. + <wa_files>-input = '03_iTab.xlsx'. + APPEND INITIAL LINE TO lt_files ASSIGNING <wa_files>. + <wa_files>-input = '04_Sheets.xlsx'. + APPEND INITIAL LINE TO lt_files ASSIGNING <wa_files>. + <wa_files>-input = '08_Range.xlsx'. + APPEND INITIAL LINE TO lt_files ASSIGNING <wa_files>. + <wa_files>-input = '13_MergedCells.xlsx'. + APPEND INITIAL LINE TO lt_files ASSIGNING <wa_files>. + <wa_files>-input = '31_AutosizeWithDifferentFontSizes.xlsx'. + +START-OF-SELECTION. + + IF p_path IS INITIAL. + p_path = lv_workdir. + ENDIF. + cl_gui_frontend_services=>get_file_separator( CHANGING file_separator = lv_file_separator ). + + LOOP AT lt_files ASSIGNING <wa_files>. + CONCATENATE p_path lv_file_separator <wa_files>-input INTO input_file_path. + CONCATENATE p_path lv_file_separator '15_' <wa_files>-input INTO output_file_path. + REPLACE '.xlsx' IN output_file_path WITH 'FromReader.xlsx'. + + TRY. + CREATE OBJECT reader TYPE zcl_excel_reader_2007. + excel = reader->load_file( input_file_path ). + + IF p_noout EQ abap_false. + worksheet = excel->get_active_worksheet( ). + highest_column = worksheet->get_highest_column( ). + highest_row = worksheet->get_highest_row( ). + + WRITE: 'Highest column: ', highest_column, 'Highest row: ', highest_row. + WRITE: /. + + WHILE row <= highest_row. + WHILE column <= highest_column. + col_str = zcl_excel_common=>convert_column2alpha( column ). + worksheet->get_cell( + EXPORTING + ip_column = col_str + ip_row = row + IMPORTING + ep_value = value + ). + WRITE: value. + column = column + 1. + ENDWHILE. + WRITE: /. + column = 1. + row = row + 1. + ENDWHILE. + ENDIF. + CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007. + lv_file = lo_excel_writer->write_file( excel ). + + " Convert to binary + CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' + EXPORTING + buffer = lv_file + IMPORTING + output_length = lv_bytecount + TABLES + binary_tab = lt_file_tab. +* " This method is only available on AS ABAP > 6.40 +* lt_file_tab = cl_bcs_convert=>xstring_to_solix( iv_xstring = lv_file ). +* lv_bytecount = xstrlen( lv_file ). + + " Save the file + cl_gui_frontend_services=>gui_download( EXPORTING bin_filesize = lv_bytecount + filename = output_file_path + filetype = 'BIN' + CHANGING data_tab = lt_file_tab ). + + + CATCH zcx_excel INTO ex. " Exceptions for ABAP2XLSX + msg = ex->get_text( ). + WRITE: / msg. + ENDTRY. + ENDLOOP. + + + + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL16 +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_excel16. + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + lo_drawing TYPE REF TO zcl_excel_drawing. + + +DATA: ls_io TYPE skwf_io. + +CONSTANTS: gc_save_file_name TYPE string VALUE '16_Drawings.xlsx'. +INCLUDE zdemo_excel_outputopt_incl. + +PARAMETERS: p_objid TYPE sdok_docid DEFAULT '456694429165174BE10000000A1550C0', " Question mark in standard Web Dynpro WDT_QUIZ + p_class TYPE sdok_class DEFAULT 'M_IMAGE_P', + pobjtype TYPE skwf_ioty DEFAULT 'P'. + + +START-OF-SELECTION. + + " Creates active sheet + CREATE OBJECT lo_excel. + + "Load samle image + DATA: lt_bin TYPE solix_tab, + lv_len TYPE i, + lv_content TYPE xstring, + ls_key TYPE wwwdatatab. + + CALL METHOD cl_gui_frontend_services=>gui_upload + EXPORTING + filename = 'c:\Program Files\SAP\FrontEnd\SAPgui\wwi\graphics\W_bio.bmp' + filetype = 'BIN' + IMPORTING + filelength = lv_len + CHANGING + data_tab = lt_bin + 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. +* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno +* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. + ENDIF. + + CALL FUNCTION 'SCMS_BINARY_TO_XSTRING' + EXPORTING + input_length = lv_len + IMPORTING + buffer = lv_content + TABLES + binary_tab = lt_bin + EXCEPTIONS + failed = 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. + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( 'Sheet1' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = 'Image from web repository (SMW0)' ). + + " create global drawing, set position and media from web repository + lo_drawing = lo_excel->add_new_drawing( ). + lo_drawing->set_position( ip_from_row = 3 + ip_from_col = 'B' ). + + ls_key-relid = 'MI'. + ls_key-objid = 'SAPLOGO.GIF'. + lo_drawing->set_media_www( ip_key = ls_key + ip_width = 166 + ip_height = 75 ). + + " assign drawing to the worksheet + lo_worksheet->add_drawing( lo_drawing ). + + " another drawing from a XSTRING read from a file + lo_worksheet->set_cell( ip_column = 'B' ip_row = 8 ip_value = 'Image from a file (c:\Program Files\SAP\FrontEnd\SAPgui\wwi\graphics\W_bio.bmp)' ). + lo_drawing = lo_excel->add_new_drawing( ). + lo_drawing->set_position( ip_from_row = 9 + ip_from_col = 'B' ). + lo_drawing->set_media( ip_media = lv_content + ip_media_type = zcl_excel_drawing=>c_media_type_bmp + ip_width = 83 + ip_height = 160 ). + + lo_worksheet->add_drawing( lo_drawing ). + + ls_io-objid = p_objid. + ls_io-class = p_class. + ls_io-objtype = pobjtype. + IF ls_io IS NOT INITIAL. + " another drawing from a XSTRING read from a file + lo_worksheet->set_cell( ip_column = 'B' ip_row = 18 ip_value = 'Mime repository (by default Question mark in standard Web Dynpro WDT_QUIZ)' ). + lo_drawing = lo_excel->add_new_drawing( ). + lo_drawing->set_position( ip_from_row = 19 + ip_from_col = 'B' ). + lo_drawing->set_media_mime( ip_io = ls_io + ip_width = 126 + ip_height = 145 ). + + lo_worksheet->add_drawing( lo_drawing ). + ENDIF. + + + + +*** Create output + lcl_output=>output( lo_excel ). + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL26 +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_excel29. + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_excel_writer TYPE REF TO zif_excel_writer, + lo_excel_reader TYPE REF TO zif_excel_reader. + +DATA: lv_file TYPE xstring, + lv_bytecount TYPE i, + lt_file_tab TYPE solix_tab. + +DATA: lv_full_path TYPE string, + lv_filename TYPE string, + lv_workdir TYPE string, + lv_file_separator TYPE c. + +PARAMETERS: p_path TYPE zexcel_export_dir OBLIGATORY. + +AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path. + + DATA: lt_filetable TYPE filetable, + lv_rc TYPE i. + + cl_gui_frontend_services=>get_sapgui_workdir( CHANGING sapworkdir = lv_workdir ). + cl_gui_cfw=>flush( ). + p_path = lv_workdir. + + CALL METHOD cl_gui_frontend_services=>file_open_dialog + EXPORTING + window_title = 'Select Macro-Enabled Workbook template' + default_extension = '*.xlsm' + file_filter = 'Excel Macro-Enabled Workbook (*.xlsm)|*.xlsm' + initial_directory = lv_workdir + CHANGING + file_table = lt_filetable + rc = lv_rc + EXCEPTIONS + file_open_dialog_failed = 1 + cntl_error = 2 + error_no_gui = 3 + not_supported_by_gui = 4 + OTHERS = 5. + IF sy-subrc <> 0. + MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno + WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. + ENDIF. + READ TABLE lt_filetable INTO lv_filename INDEX 1. + p_path = lv_filename. + +START-OF-SELECTION. + + lv_full_path = p_path. + + CREATE OBJECT lo_excel_reader TYPE zcl_excel_reader_xlsm. + CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_xlsm. + lo_excel = lo_excel_reader->load_file( lv_full_path ). + lv_file = lo_excel_writer->write_file( lo_excel ). + REPLACE '.xlsm' IN lv_full_path WITH 'FromReader.xlsm'. + + " Convert to binary + CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' + EXPORTING + buffer = lv_file + IMPORTING + output_length = lv_bytecount + TABLES + binary_tab = lt_file_tab. + + " Save the file + cl_gui_frontend_services=>gui_download( EXPORTING bin_filesize = lv_bytecount + filename = lv_full_path + filetype = 'BIN' + CHANGING data_tab = lt_file_tab ). + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL28 +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_excel28. + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_excel_writer TYPE REF TO zif_excel_writer, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + lo_hyperlink TYPE REF TO zcl_excel_hyperlink, + column_dimension TYPE REF TO zcl_excel_worksheet_columndime. + +DATA: lv_file TYPE xstring, + lv_bytecount TYPE i, + lt_file_tab TYPE solix_tab. + +DATA: lv_file_name TYPE string, + lv_file_path TYPE string, + lv_full_path TYPE string, + lv_workdir TYPE string, + lv_file_separator TYPE c. + +CONSTANTS: lv_default_file_name TYPE string VALUE '28_HelloWorld.csv'. + +PARAMETERS: p_path TYPE string. + +AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path. + + cl_gui_frontend_services=>directory_browse( EXPORTING initial_folder = p_path + CHANGING selected_folder = p_path ). + +INITIALIZATION. + cl_gui_frontend_services=>get_sapgui_workdir( CHANGING sapworkdir = lv_workdir ). + cl_gui_cfw=>flush( ). + p_path = lv_workdir. + +START-OF-SELECTION. + + IF p_path IS INITIAL. + p_path = lv_workdir. + ENDIF. + cl_gui_frontend_services=>get_file_separator( CHANGING file_separator = lv_file_separator ). + CONCATENATE p_path lv_file_separator lv_default_file_name INTO lv_full_path. + + " Creates active sheet + CREATE OBJECT lo_excel. + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( ip_title = 'Sheet1' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = 'Hello world' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 3 ip_value = sy-datum ). + lo_worksheet->set_cell( ip_column = 'C' ip_row = 3 ip_value = sy-uzeit ). + + column_dimension = lo_worksheet->get_column_dimension( 'B' ). + column_dimension->set_width( 11 ). + + lo_worksheet = lo_excel->add_new_worksheet( ). + lo_worksheet->set_title( ip_title = 'Sheet2' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = 'This is the second sheet' ). + + CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_csv. + zcl_excel_writer_csv=>set_delimiter( ip_value = cl_abap_char_utilities=>horizontal_tab ). + zcl_excel_writer_csv=>set_enclosure( ip_value = '''' ). + zcl_excel_writer_csv=>set_endofline( ip_value = cl_abap_char_utilities=>cr_lf ). + + zcl_excel_writer_csv=>set_active_sheet_index( i_active_worksheet = 2 ). +* zcl_excel_writer_csv=>set_active_sheet_index_by_name( I_WORKSHEET_NAME = 'Sheet2' ). + + lv_file = lo_excel_writer->write_file( lo_excel ). + + " Convert to binary + CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' + EXPORTING + buffer = lv_file + IMPORTING + output_length = lv_bytecount + TABLES + binary_tab = lt_file_tab. +* " This method is only available on AS ABAP > 6.40 +* lt_file_tab = cl_bcs_convert=>xstring_to_solix( iv_xstring = lv_file ). +* lv_bytecount = xstrlen( lv_file ). + + " Save the file + REPLACE FIRST OCCURRENCE OF '.csv' IN lv_full_path WITH '_Sheet2.csv'. + cl_gui_frontend_services=>gui_download( EXPORTING bin_filesize = lv_bytecount + filename = lv_full_path + filetype = 'BIN' + CHANGING data_tab = lt_file_tab ). + +* zcl_excel_writer_csv=>set_active_sheet_index( i_active_worksheet = 2 ). + zcl_excel_writer_csv=>set_active_sheet_index_by_name( I_WORKSHEET_NAME = 'Sheet1' ). + lv_file = lo_excel_writer->write_file( lo_excel ). + REPLACE FIRST OCCURRENCE OF '_Sheet2.csv' IN lv_full_path WITH '_Sheet1.csv'. + + " Convert to binary + CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' + EXPORTING + buffer = lv_file + IMPORTING + output_length = lv_bytecount + TABLES + binary_tab = lt_file_tab. +* " This method is only available on AS ABAP > 6.40 +* lt_file_tab = cl_bcs_convert=>xstring_to_solix( iv_xstring = lv_file ). +* lv_bytecount = xstrlen( lv_file ). + + " Save the file + cl_gui_frontend_services=>gui_download( EXPORTING bin_filesize = lv_bytecount + filename = lv_full_path + filetype = 'BIN' + CHANGING data_tab = lt_file_tab ). + + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL27 +*& Test Styles for ABAP2XLSX +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_excel27. + +CONSTANTS: c_fish TYPE string VALUE 'Fish'. + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + lo_range TYPE REF TO zcl_excel_range, + lo_data_validation TYPE REF TO zcl_excel_data_validation, + lo_style_conditional TYPE REF TO zcl_excel_style_conditional, + lo_style_1 TYPE REF TO zcl_excel_style, + lo_style_2 TYPE REF TO zcl_excel_style, + lv_style_1_guid TYPE zexcel_cell_style, + lv_style_2_guid TYPE zexcel_cell_style, + ls_cellis TYPE zexcel_conditional_cellis. + + +DATA: lv_title TYPE zexcel_sheet_title. + +CONSTANTS: gc_save_file_name TYPE string VALUE '27_ConditionalFormatting.xlsx'. +INCLUDE zdemo_excel_outputopt_incl. + + +START-OF-SELECTION. + + + " Creates active sheet + CREATE OBJECT lo_excel. + + lo_style_1 = lo_excel->add_new_style( ). + lo_style_1->fill->filltype = zcl_excel_style_fill=>c_fill_solid. + lo_style_1->fill->bgcolor-rgb = zcl_excel_style_color=>c_green. + lv_style_1_guid = lo_style_1->get_guid( ). + + lo_style_2 = lo_excel->add_new_style( ). + lo_style_2->fill->filltype = zcl_excel_style_fill=>c_fill_solid. + lo_style_2->fill->bgcolor-rgb = zcl_excel_style_color=>c_red. + lv_style_2_guid = lo_style_2->get_guid( ). + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + lv_title = 'Data Validation'. + lo_worksheet->set_title( lv_title ). + " Set values for dropdown + lo_worksheet->set_cell( ip_row = 2 ip_column = 'A' ip_value = c_fish ). + lo_worksheet->set_cell( ip_row = 4 ip_column = 'A' ip_value = 'Anchovy' ). + lo_worksheet->set_cell( ip_row = 5 ip_column = 'A' ip_value = 'Carp' ). + lo_worksheet->set_cell( ip_row = 6 ip_column = 'A' ip_value = 'Catfish' ). + lo_worksheet->set_cell( ip_row = 7 ip_column = 'A' ip_value = 'Cod' ). + lo_worksheet->set_cell( ip_row = 8 ip_column = 'A' ip_value = 'Eel' ). + lo_worksheet->set_cell( ip_row = 9 ip_column = 'A' ip_value = 'Haddock' ). + + lo_range = lo_excel->add_new_range( ). + lo_range->name = c_fish. + lo_range->set_value( ip_sheet_name = lv_title + ip_start_column = 'A' + ip_start_row = 4 + ip_stop_column = 'A' + ip_stop_row = 9 ). + + " 1st validation + lo_data_validation = lo_worksheet->add_new_data_validation( ). + lo_data_validation->type = zcl_excel_data_validation=>c_type_list. + lo_data_validation->formula1 = c_fish. + lo_data_validation->cell_row = 2. + lo_data_validation->cell_column = 'C'. + lo_worksheet->set_cell( ip_row = 2 ip_column = 'C' ip_value = 'Select a value' ). + + lo_style_conditional = lo_worksheet->add_new_conditional_style( ). + lo_style_conditional->rule = zcl_excel_style_conditional=>c_rule_cellis. + ls_cellis-formula = '"Anchovy"'. + ls_cellis-operator = zcl_excel_style_conditional=>c_operator_equal. + ls_cellis-cell_style = lv_style_1_guid. + lo_style_conditional->mode_cellis = ls_cellis. + lo_style_conditional->priority = 1. + lo_style_conditional->set_range( ip_start_column = 'C' + ip_start_row = 2 + ip_stop_column = 'C' + ip_stop_row = 2 ). + + lo_style_conditional = lo_worksheet->add_new_conditional_style( ). + lo_style_conditional->rule = zcl_excel_style_conditional=>c_rule_cellis. + ls_cellis-formula = '"Carp"'. + ls_cellis-operator = zcl_excel_style_conditional=>c_operator_equal. + ls_cellis-cell_style = lv_style_2_guid. + lo_style_conditional->mode_cellis = ls_cellis. + lo_style_conditional->priority = 2. + lo_style_conditional->set_range( ip_start_column = 'C' + ip_start_row = 2 + ip_stop_column = 'C' + ip_stop_row = 2 ). + + + +*** Create output + lcl_output=>output( lo_excel ). + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + *--------------------------------------------------------------------* +* REPORT ZDEMO_EXCEL26 +* Demo for method zcl_excel_worksheet-bind_object: +* export data from ALV (CL_GUI_ALV_GRID) object or cl_salv_table object +* to Excel. +*--------------------------------------------------------------------* +report zdemo_excel26. + +*----------------------------------------------------------------------* +* CLASS lcl_handle_events DEFINITION +*----------------------------------------------------------------------* +* +*----------------------------------------------------------------------* +class lcl_handle_events definition. + public section. + methods: + on_user_command for event added_function of cl_salv_events + importing e_salv_function. +endclass. "lcl_handle_events DEFINITION + +*----------------------------------------------------------------------* +* CLASS lcl_handle_events IMPLEMENTATION +*----------------------------------------------------------------------* +* +*----------------------------------------------------------------------* +class lcl_handle_events implementation. + method on_user_command. + perform user_command." using e_salv_function text-i08. + endmethod. "on_user_command +endclass. "lcl_handle_events IMPLEMENTATION + +*--------------------------------------------------------------------* +* DATA DECLARATION +*--------------------------------------------------------------------* + +data: lo_excel type ref to zcl_excel, + lo_worksheet type ref to zcl_excel_worksheet, + lo_salv type ref to cl_salv_table, + gr_events type ref to lcl_handle_events, + lr_events type ref to cl_salv_events_table, + gt_sbook type table of sbook. + +data: l_path type string, " local dir + lv_workdir type string, + lv_file_separator type c. + +constants: + lv_default_file_name type string value '26_Bind_ALV.xlsx'. +*--------------------------------------------------------------------* +*START-OF-SELECTION +*--------------------------------------------------------------------* + +start-of-selection. + +* get data +* ------------------------------------------ + + select * + into table gt_sbook[] + from sbook "#EC CI_NOWHERE + up to 10 rows. + +* Display ALV +* ------------------------------------------ + + try. + cl_salv_table=>factory( + exporting + list_display = abap_false + importing + r_salv_table = lo_salv + changing + t_table = gt_sbook[] ). + catch cx_salv_msg . + endtry. + + try. + lo_salv->set_screen_status( + exporting + report = sy-repid + pfstatus = 'ALV_STATUS' + set_functions = lo_salv->c_functions_all ). + catch cx_salv_msg . + endtry. + + lr_events = lo_salv->get_event( ). + create object gr_events. + set handler gr_events->on_user_command for lr_events. + + lo_salv->display( ). + + +*&---------------------------------------------------------------------* +*& Form USER_COMMAND +*&---------------------------------------------------------------------* +* ALV user command +*--------------------------------------------------------------------* +form user_command . + if sy-ucomm = 'EXCEL'. + +* get save file path + cl_gui_frontend_services=>get_sapgui_workdir( changing sapworkdir = l_path ). + cl_gui_cfw=>flush( ). + cl_gui_frontend_services=>directory_browse( + exporting initial_folder = l_path + changing selected_folder = l_path ). + + if l_path is initial. + cl_gui_frontend_services=>get_sapgui_workdir( + changing sapworkdir = lv_workdir ). + l_path = lv_workdir. + endif. + + cl_gui_frontend_services=>get_file_separator( + changing file_separator = lv_file_separator ). + + concatenate l_path lv_file_separator lv_default_file_name + into l_path. + +* export file to save file path + perform export_to_excel. + + endif. +endform. " USER_COMMAND + +*--------------------------------------------------------------------* +* FORM EXPORT_TO_EXCEL +*--------------------------------------------------------------------* +* This subroutine is principal demo session +*--------------------------------------------------------------------* +form export_to_excel. + data: lo_converter type ref to zcl_excel_converter. +* create zcl_excel_worksheet object + + create object lo_excel. + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( ip_title = 'Sheet1' ). + +* write to excel using method Bin_object + try. + lo_worksheet->bind_alv( + io_alv = lo_salv + it_table = gt_sbook + i_top = 2 + i_left = 1 + ). + catch zcx_excel . + endtry. + + perform write_file. + +endform. "EXPORT_TO_EXCEL +*&---------------------------------------------------------------------* +*& Form WRITE_FILE +*&---------------------------------------------------------------------* +* text +*----------------------------------------------------------------------* +* --> p1 text +* <-- p2 text +*----------------------------------------------------------------------* +form write_file . + data: lt_file type solix_tab, + l_bytecount type i, + l_file type xstring. + + data: lo_excel_writer type ref to zif_excel_writer. + + data: ls_seoclass type seoclass. + + create object lo_excel_writer type zcl_excel_writer_2007. + l_file = lo_excel_writer->write_file( lo_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 = l_file + receiving + et_solix = lt_file. + + l_bytecount = xstrlen( l_file ). + else. + " Convert to binary + call function 'SCMS_XSTRING_TO_BINARY' + exporting + buffer = l_file + importing + output_length = l_bytecount + tables + binary_tab = lt_file. + endif. + + cl_gui_frontend_services=>gui_download( exporting bin_filesize = l_bytecount + filename = l_path + filetype = 'BIN' + changing data_tab = lt_file ). + +endform. " WRITE_FILE + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL25 +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_excel25. + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_excel_writer TYPE REF TO zif_excel_writer, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + lo_exception TYPE REF TO cx_root. + +DATA: lv_file TYPE xstring. + +CONSTANTS: lv_file_name TYPE string VALUE '25_HelloWorld.xlsx'. +DATA: lv_default_file_name TYPE string. +DATA: lv_error TYPE string. + +CALL FUNCTION 'FILE_GET_NAME_USING_PATH' + EXPORTING + logical_path = 'LOCAL_TEMPORARY_FILES' " Logical path' + file_name = lv_file_name " File name + IMPORTING + file_name_with_path = lv_default_file_name. " File name with path +" Creates active sheet +CREATE OBJECT lo_excel. + +" Get active sheet +lo_worksheet = lo_excel->get_active_worksheet( ). +lo_worksheet->set_title( ip_title = 'Sheet1' ). +lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = 'Hello world' ). + +CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007. +lv_file = lo_excel_writer->write_file( lo_excel ). + +TRY. + OPEN DATASET lv_default_file_name FOR OUTPUT IN BINARY MODE. + TRANSFER lv_file TO lv_default_file_name. + CLOSE DATASET lv_default_file_name. + CATCH cx_root INTO lo_exception. + lv_error = lo_exception->get_text( ). + MESSAGE lv_error TYPE 'I'. +ENDTRY. + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL23 +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_excel24. + +TYPE-POOLS: abap. + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + column_dimension TYPE REF TO zcl_excel_worksheet_columndime, + lo_hyperlink TYPE REF TO zcl_excel_hyperlink. + +DATA: lv_file TYPE xstring, + lv_bytecount TYPE i, + lt_file_tab TYPE solix_tab. + +DATA: lv_full_path TYPE string, + lv_workdir TYPE string, + lv_file_separator TYPE c. + +DATA: lv_value TYPE string. + +CONSTANTS: gc_save_file_name TYPE string VALUE '24_Sheets_with_different_default_date_formats.xlsx'. +INCLUDE zdemo_excel_outputopt_incl. + + +START-OF-SELECTION. + + " Creates active sheet + CREATE OBJECT lo_excel. + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( ip_title = 'Sheet1' ). + lo_worksheet->set_cell( ip_column = 'A' ip_row = 1 ip_value = 'Default Date Format' ). + " Insert current date + lo_worksheet->set_cell( ip_column = 'A' ip_row = 3 ip_value = 'Current Date:' ). + lo_worksheet->set_cell( ip_column = 'A' ip_row = 4 ip_value = sy-datum ). + + lo_hyperlink = zcl_excel_hyperlink=>create_internal_link( iv_location = 'Sheet2!A1' ). + lo_worksheet->set_cell( ip_column = 'A' ip_row = 6 ip_value = 'This is a link to the second sheet' ip_hyperlink = lo_hyperlink ). + column_dimension = lo_worksheet->get_column_dimension( ip_column = 'A' ). + column_dimension->set_auto_size( ip_auto_size = abap_true ). + + + " Second sheet + lo_worksheet = lo_excel->add_new_worksheet( ). + lo_worksheet->set_default_excel_date_format( zcl_excel_style_number_format=>c_format_date_yyyymmdd ). + lo_worksheet->set_title( ip_title = 'Sheet2' ). + lo_worksheet->set_cell( ip_column = 'A' ip_row = 1 ip_value = 'Date Format set to YYYYMMDD' ). + " Insert current date + lo_worksheet->set_cell( ip_column = 'A' ip_row = 3 ip_value = 'Current Date:' ). + lo_worksheet->set_cell( ip_column = 'A' ip_row = 4 ip_value = sy-datum ). + + lo_hyperlink = zcl_excel_hyperlink=>create_internal_link( iv_location = 'Sheet3!B2' ). + lo_worksheet->set_cell( ip_column = 'A' ip_row = 6 ip_value = 'This is link to the third sheet' ip_hyperlink = lo_hyperlink ). + + " Third sheet + lo_worksheet = lo_excel->add_new_worksheet( ). + " TODO: It seems that the zcl_excel_style_number_format=>c_format_date_yyyymmddslash + " does not produce a valid output + lo_worksheet->set_default_excel_date_format( zcl_excel_style_number_format=>c_format_date_yyyymmddslash ). + lo_worksheet->set_title( ip_title = 'Sheet3' ). + lo_worksheet->set_cell( ip_column = 'A' ip_row = 1 ip_value = 'Date Format set to YYYY/MM/DD' ). + " Insert current date + lo_worksheet->set_cell( ip_column = 'A' ip_row = 3 ip_value = 'Current Date:' ). + lo_worksheet->set_cell( ip_column = 'A' ip_row = 4 ip_value = sy-datum ). + + lo_hyperlink = zcl_excel_hyperlink=>create_internal_link( iv_location = 'Sheet4!B2' ). + lo_worksheet->set_cell( ip_column = 'A' ip_row = 6 ip_value = 'This is link to the 4th sheet' ip_hyperlink = lo_hyperlink ). + + " 4th sheet + lo_worksheet = lo_excel->add_new_worksheet( ). + " Illustrate the Problem caused by: + " Excel 2000 incorrectly assumes that the year 1900 is a leap year. + " http://support.microsoft.com/kb/214326/en-us + lo_worksheet->set_title( ip_title = 'Sheet4' ). + " Loop from Start Date to the Max Date current data in daily steps + CONSTANTS: lv_max type d VALUE '19000302'. + + DATA: lv_date TYPE d VALUE '19000226', + lv_row TYPE i. + lo_worksheet->set_cell( ip_column = 'B' ip_row = 3 ip_value = 'Formated date' ). + lo_worksheet->set_cell( ip_column = 'C' ip_row = 3 ip_value = 'Integer value for this date' ). + lo_worksheet->set_cell( ip_column = 'D' ip_row = 3 ip_value = 'Date as string' ). + + lv_row = 4. + WHILE lv_date < lv_max. + lo_worksheet->set_cell( ip_column = 'B' ip_row = lv_row ip_value = lv_date ). + lv_value = zcl_excel_common=>date_to_excel_string( lv_date ). + lo_worksheet->set_cell( ip_column = 'C' ip_row = lv_row ip_value = lv_value ). + lv_value = lv_date. + lo_worksheet->set_cell( ip_column = 'D' ip_row = lv_row ip_value = lv_value ). + lv_date = lv_date + 1. + lv_row = lv_row + 1. + ENDWHILE. + + lv_row = lv_row + 1. + + lo_hyperlink = zcl_excel_hyperlink=>create_internal_link( iv_location = 'Sheet1!B2' ). + lo_worksheet->set_cell( ip_column = 'A' ip_row = lv_row ip_value = 'This is link to the first sheet' ip_hyperlink = lo_hyperlink ). + + lo_excel->set_active_sheet_index_by_name( 'Sheet1' ). + +*** Create output + lcl_output=>output( lo_excel ). + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL23 +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_excel23. + +TYPE-POOLS: abap. + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + lo_hyperlink TYPE REF TO zcl_excel_hyperlink. + + +CONSTANTS: gc_save_file_name TYPE string VALUE '23_Sheets_with_and_without_grid_lines.xlsx'. +INCLUDE zdemo_excel_outputopt_incl. + + +START-OF-SELECTION. + + + " Creates active sheet + CREATE OBJECT lo_excel. + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( ip_title = 'Sheet1' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = 'This is the first sheet with grid lines and print centered horizontal & vertical' ). + lo_worksheet->set_show_gridlines( i_show_gridlines = abap_true ). + + lo_hyperlink = zcl_excel_hyperlink=>create_internal_link( iv_location = 'Sheet2!B2' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 3 ip_value = 'This is a link to the second sheet' ip_hyperlink = lo_hyperlink ). + + lo_worksheet->zif_excel_sheet_protection~protected = zif_excel_sheet_protection=>c_protected. + lo_worksheet->zif_excel_sheet_properties~zoomscale = 150. + lo_worksheet->ZIF_EXCEL_SHEET_PROPERTIES~ZOOMSCALE_NORMAL = 150. + + lo_worksheet->sheet_setup->vertical_centered = abap_true. + lo_worksheet->sheet_setup->horizontal_centered = abap_true. + + " Second sheet + lo_worksheet = lo_excel->add_new_worksheet( ). + lo_worksheet->set_title( ip_title = 'Sheet2' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = 'This is the second sheet with grid lines in display and print' ). + lo_worksheet->set_show_gridlines( i_show_gridlines = abap_true ). + lo_worksheet->set_print_gridlines( i_print_gridlines = abap_true ). + + lo_hyperlink = zcl_excel_hyperlink=>create_internal_link( iv_location = 'Sheet3!B2' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 3 ip_value = 'This is link to the third sheet' ip_hyperlink = lo_hyperlink ). + + lo_worksheet->zif_excel_sheet_protection~protected = zif_excel_sheet_protection=>c_protected. + lo_worksheet->zif_excel_sheet_properties~zoomscale = 160. + lo_worksheet->ZIF_EXCEL_SHEET_PROPERTIES~ZOOMSCALE_PAGELAYOUTVIEW = 200. + + " Third sheet + lo_worksheet = lo_excel->add_new_worksheet( ). + lo_worksheet->set_title( ip_title = 'Sheet3' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = 'This is the third sheet without grid lines in display and print' ). + lo_worksheet->set_show_gridlines( i_show_gridlines = abap_false ). + lo_worksheet->set_print_gridlines( i_print_gridlines = abap_false ). + + lo_hyperlink = zcl_excel_hyperlink=>create_internal_link( iv_location = 'Sheet4!B2' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 3 ip_value = 'This is link to the fourth sheet' ip_hyperlink = lo_hyperlink ). + + lo_worksheet->zif_excel_sheet_protection~protected = zif_excel_sheet_protection=>c_protected. + lo_worksheet->zif_excel_sheet_properties~zoomscale = 170. + lo_worksheet->ZIF_EXCEL_SHEET_PROPERTIES~ZOOMSCALE_SHEETLAYOUTVIEW = 150. + + " Fourth sheet + lo_worksheet = lo_excel->add_new_worksheet( ). + lo_worksheet->set_title( ip_title = 'Sheet4' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = 'This is the fourth sheet with grid lines and print centered ONLY horizontal' ). + lo_worksheet->set_show_gridlines( i_show_gridlines = abap_true ). + + lo_hyperlink = zcl_excel_hyperlink=>create_internal_link( iv_location = 'Sheet1!B2' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 3 ip_value = 'This is link to the first sheet' ip_hyperlink = lo_hyperlink ). + + lo_worksheet->zif_excel_sheet_protection~protected = zif_excel_sheet_protection=>c_protected. + lo_worksheet->zif_excel_sheet_properties~zoomscale = 150. + lo_worksheet->ZIF_EXCEL_SHEET_PROPERTIES~ZOOMSCALE_NORMAL = 150. + +" lo_worksheet->sheet_setup->vertical_centered = abap_true. + lo_worksheet->sheet_setup->horizontal_centered = abap_true. + + + +*** Create output + lcl_output=>output( lo_excel ). + + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL17 +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_excel17. + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + lo_style_protection TYPE REF TO zcl_excel_style, + lv_style_protection_guid TYPE zexcel_cell_style, + lo_style TYPE REF TO zcl_excel_style, + lv_style TYPE zexcel_cell_style. + + +CONSTANTS: gc_save_file_name TYPE string VALUE '17_SheetProtection.xlsx'. +INCLUDE zdemo_excel_outputopt_incl. + +PARAMETERS: p_pwd TYPE zexcel_aes_password LOWER CASE DEFAULT 'secret'. + +START-OF-SELECTION. + + CREATE OBJECT lo_excel. + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->zif_excel_sheet_protection~protected = zif_excel_sheet_protection=>c_protected. +* lo_worksheet->zif_excel_sheet_protection~password = 'DAA7'. "it is the encoded word "secret" + lo_worksheet->zif_excel_sheet_protection~password = zcl_excel_common=>encrypt_password( p_pwd ). + lo_worksheet->zif_excel_sheet_protection~sheet = zif_excel_sheet_protection=>c_active. + lo_worksheet->zif_excel_sheet_protection~objects = zif_excel_sheet_protection=>c_active. + lo_worksheet->zif_excel_sheet_protection~scenarios = zif_excel_sheet_protection=>c_active. + " First style to unlock a cell + lo_style_protection = lo_excel->add_new_style( ). + lo_style_protection->protection->locked = zcl_excel_style_protection=>c_protection_unlocked. + lv_style_protection_guid = lo_style_protection->get_guid( ). + " Another style which should not affect the unlock style + lo_style = lo_excel->add_new_style( ). + lo_style->fill->filltype = zcl_excel_style_fill=>c_fill_solid. + lo_style->fill->fgcolor-rgb = 'FFCC3333'. + lv_style = lo_style->get_guid( ). + lo_worksheet->set_cell( ip_row = 3 ip_column = 'C' ip_value = 'This cell is locked locked and has the second formating' ip_style = lv_style ). + lo_worksheet->set_cell( ip_row = 4 ip_column = 'C' ip_value = 'This cell is unlocked' ip_style = lv_style_protection_guid ). + lo_worksheet->set_cell( ip_row = 5 ip_column = 'C' ip_value = 'This cell is locked as all the others empty cell' ). + lo_worksheet->set_cell( ip_row = 6 ip_column = 'C' ip_value = 'This cell is unlocked' ip_style = lv_style_protection_guid ). + lo_worksheet->set_cell( ip_row = 7 ip_column = 'C' ip_value = 'This cell is unlocked' ip_style = lv_style_protection_guid ). + lo_worksheet->set_cell( ip_row = 8 ip_column = 'C' ip_value = 'This cell is locked as all the others empty cell' ). + + + + +*** Create output + lcl_output=>output( lo_excel ). + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL18 +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_excel18. + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + lv_style_protection_guid TYPE zexcel_cell_style. + + +CONSTANTS: gc_save_file_name TYPE string VALUE '18_BookProtection.xlsx'. +INCLUDE zdemo_excel_outputopt_incl. + + +START-OF-SELECTION. + + CREATE OBJECT lo_excel. + + " Get active sheet + lo_excel->zif_excel_book_protection~protected = zif_excel_book_protection=>c_protected. + lo_excel->zif_excel_book_protection~lockrevision = zif_excel_book_protection=>c_locked. + lo_excel->zif_excel_book_protection~lockstructure = zif_excel_book_protection=>c_locked. + lo_excel->zif_excel_book_protection~lockwindows = zif_excel_book_protection=>c_locked. + + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_cell( ip_row = 4 ip_column = 'C' ip_value = 'This cell is unlocked' ip_style = lv_style_protection_guid ). + + + + +*** Create output + lcl_output=>output( lo_excel ). + + + + + + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL19 +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_excel19. + +TYPE-POOLS: abap. + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_worksheet TYPE REF TO zcl_excel_worksheet. + + +CONSTANTS: gc_save_file_name TYPE string VALUE '19_SetActiveSheet.xlsx'. +INCLUDE zdemo_excel_outputopt_incl. + +PARAMETERS: p_noout TYPE xfeld DEFAULT abap_true. + + +START-OF-SELECTION. + + CREATE OBJECT lo_excel. + + " First Worksheet + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( 'First' ). + lo_worksheet->set_cell( ip_row = 1 ip_column = 'A' ip_value = 'This is Sheet 1' ). + + " Second Worksheet + lo_worksheet = lo_excel->add_new_worksheet( ). + lo_worksheet->set_title( 'Second' ). + lo_worksheet->set_cell( ip_row = 1 ip_column = 'A' ip_value = 'This is Sheet 2' ). + + " Third Worksheet + lo_worksheet = lo_excel->add_new_worksheet( ). + lo_worksheet->set_title( 'Third' ). + lo_worksheet->set_cell( ip_row = 1 ip_column = 'A' ip_value = 'This is Sheet 3' ). + + IF p_noout EQ abap_false. + " lo_excel->set_active_sheet_index_by_name( data_sheet_name ). + DATA: active_sheet_index TYPE zexcel_active_worksheet. + active_sheet_index = lo_excel->get_active_sheet_index( ). + WRITE: 'Sheet Index before: ', active_sheet_index. + ENDIF. + lo_excel->set_active_sheet_index( '2' ). + IF p_noout EQ abap_false. + active_sheet_index = lo_excel->get_active_sheet_index( ). + WRITE: 'Sheet Index after: ', active_sheet_index. + ENDIF. + + +*** Create output + lcl_output=>output( lo_excel ). + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL2 +*& Test Styles for ABAP2XLSX +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_excel2. + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + lo_style_bold TYPE REF TO zcl_excel_style, + lo_style_underline TYPE REF TO zcl_excel_style, + lo_style_filled TYPE REF TO zcl_excel_style, + lo_style_border TYPE REF TO zcl_excel_style, + lo_style_button TYPE REF TO zcl_excel_style, + lo_border_dark TYPE REF TO zcl_excel_style_border, + lo_border_light TYPE REF TO zcl_excel_style_border. + +DATA: lv_style_bold_guid TYPE zexcel_cell_style, + lv_style_underline_guid TYPE zexcel_cell_style, + lv_style_filled_guid TYPE zexcel_cell_style, + lv_style_filled_green_guid TYPE zexcel_cell_style, + lv_style_border_guid TYPE zexcel_cell_style, + lv_style_button_guid TYPE zexcel_cell_style, + lv_style_filled_turquoise_guid TYPE zexcel_cell_style. + +DATA: lv_file TYPE xstring, + lv_bytecount TYPE i, + lt_file_tab TYPE solix_tab. + +DATA: lv_full_path TYPE string, + lv_workdir TYPE string, + lv_file_separator TYPE c. + +CONSTANTS: gc_save_file_name TYPE string VALUE '02_Styles.xlsx'. +INCLUDE zdemo_excel_outputopt_incl. + + + +START-OF-SELECTION. + + + " Creates active sheet + CREATE OBJECT lo_excel. + + " Create border object + CREATE OBJECT lo_border_dark. + lo_border_dark->border_color-rgb = zcl_excel_style_color=>c_black. + lo_border_dark->border_style = zcl_excel_style_border=>c_border_thin. + CREATE OBJECT lo_border_light. + lo_border_light->border_color-rgb = zcl_excel_style_color=>c_gray. + lo_border_light->border_style = zcl_excel_style_border=>c_border_thin. + " Create a bold / italic style + lo_style_bold = lo_excel->add_new_style( ). + lo_style_bold->font->bold = abap_true. + lo_style_bold->font->italic = abap_true. + lo_style_bold->font->name = zcl_excel_style_font=>c_name_arial. + lo_style_bold->font->scheme = zcl_excel_style_font=>c_scheme_none. + lo_style_bold->font->color-rgb = zcl_excel_style_color=>c_red. + lv_style_bold_guid = lo_style_bold->get_guid( ). + " Create an underline double style + lo_style_underline = lo_excel->add_new_style( ). + lo_style_underline->font->underline = abap_true. + lo_style_underline->font->underline_mode = zcl_excel_style_font=>c_underline_double. + lo_style_underline->font->name = zcl_excel_style_font=>c_name_roman. + lo_style_underline->font->scheme = zcl_excel_style_font=>c_scheme_none. + lo_style_underline->font->family = zcl_excel_style_font=>c_family_roman. + lv_style_underline_guid = lo_style_underline->get_guid( ). + " Create filled style yellow + lo_style_filled = lo_excel->add_new_style( ). + lo_style_filled->fill->filltype = zcl_excel_style_fill=>c_fill_solid. + lo_style_filled->fill->fgcolor-theme = zcl_excel_style_color=>c_theme_accent6. + lv_style_filled_guid = lo_style_filled->get_guid( ). + " Create border with button effects + lo_style_button = lo_excel->add_new_style( ). + lo_style_button->borders->right = lo_border_dark. + lo_style_button->borders->down = lo_border_dark. + lo_style_button->borders->left = lo_border_light. + lo_style_button->borders->top = lo_border_light. + lv_style_button_guid = lo_style_button->get_guid( ). + "Create style with border + lo_style_border = lo_excel->add_new_style( ). + lo_style_border->borders->allborders = lo_border_dark. + lo_style_border->borders->diagonal = lo_border_dark. + lo_style_border->borders->diagonal_mode = zcl_excel_style_borders=>c_diagonal_both. + lv_style_border_guid = lo_style_border->get_guid( ). + " Create filled style green + lo_style_filled = lo_excel->add_new_style( ). + lo_style_filled->fill->filltype = zcl_excel_style_fill=>c_fill_solid. + lo_style_filled->fill->fgcolor-rgb = zcl_excel_style_color=>c_green. + lo_style_filled->font->name = zcl_excel_style_font=>c_name_cambria. + lo_style_filled->font->scheme = zcl_excel_style_font=>c_scheme_major. + lv_style_filled_green_guid = lo_style_filled->get_guid( ). + + " Create filled style turquoise using legacy excel ver <= 2003 palette. (https://code.sdn.sap.com/spaces/abap2xlsx/tickets/92) + lo_style_filled = lo_excel->add_new_style( ). + lo_excel->legacy_palette->set_color( "replace built-in color from palette with out custom RGB turquoise + ip_index = 16 + ip_color = '0040E0D0' ). + + lo_style_filled->fill->filltype = zcl_excel_style_fill=>c_fill_solid. + lo_style_filled->fill->fgcolor-indexed = 16. + lv_style_filled_turquoise_guid = lo_style_filled->get_guid( ). + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( ip_title = 'Styles' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = 'Hello world' ). + lo_worksheet->set_cell( ip_column = 'C' ip_row = 3 ip_value = 'Bold text' ip_style = lv_style_bold_guid ). + lo_worksheet->set_cell( ip_column = 'D' ip_row = 4 ip_value = 'Underlined text' ip_style = lv_style_underline_guid ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 5 ip_value = 'Filled text' ip_style = lv_style_filled_guid ). + lo_worksheet->set_cell( ip_column = 'C' ip_row = 6 ip_value = 'Borders' ip_style = lv_style_border_guid ). + lo_worksheet->set_cell( ip_column = 'D' ip_row = 7 ip_value = 'I''m not a button :)' ip_style = lv_style_button_guid ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 9 ip_value = 'Modified color for Excel 2003' ip_style = lv_style_filled_turquoise_guid ). + " Fill the cell and apply one style + lo_worksheet->set_cell( ip_column = 'B' ip_row = 6 ip_value = 'Filled text' ip_style = lv_style_filled_guid ). + " Change the style + lo_worksheet->set_cell_style( ip_column = 'B' ip_row = 6 ip_style = lv_style_filled_green_guid ). + " Add Style to an empty cell to test Fix for Issue + "#44 Exception ZCX_EXCEL thrown when style is set for an empty cell + " https://code.sdn.sap.com/spaces/abap2xlsx/tickets/44-exception-zcx_excel-thrown-when-style-is-set-for-an-empty-cell + lo_worksheet->set_cell_style( ip_column = 'E' ip_row = 6 ip_style = lv_style_filled_green_guid ). + +* CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007. +* lv_file = lo_excel_writer->write_file( lo_excel ). +* +* " Convert to binary +* CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' +* EXPORTING +* buffer = lv_file +* IMPORTING +* output_length = lv_bytecount +* TABLES +* binary_tab = lt_file_tab. +** " This method is only available on AS ABAP > 6.40 +** lt_file_tab = cl_bcs_convert=>xstring_to_solix( iv_xstring = lv_file ). +** lv_bytecount = xstrlen( lv_file ). +* +* " Save the file +* cl_gui_frontend_services=>gui_download( EXPORTING bin_filesize = lv_bytecount +* filename = lv_full_path +* filetype = 'BIN' +* CHANGING data_tab = lt_file_tab ). + + lcl_output=>output( lo_excel ). + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL22 +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_excel22. + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + lo_style TYPE REF TO zcl_excel_style, + lo_style_date TYPE REF TO zcl_excel_style, + lo_style_editable TYPE REF TO zcl_excel_style, + lo_data_validation TYPE REF TO zcl_excel_data_validation. + +DATA: lt_field_catalog TYPE zexcel_t_fieldcatalog, + ls_table_settings TYPE zexcel_s_table_settings, + ls_table_settings_out TYPE zexcel_s_table_settings. + +DATA: lv_style_guid TYPE zexcel_cell_style. + +DATA: lv_row TYPE char10. + +FIELD-SYMBOLS: <fs_field_catalog> TYPE zexcel_s_fieldcatalog. + +CONSTANTS: gc_save_file_name TYPE string VALUE '22_itab_fieldcatalog.xlsx'. +INCLUDE zdemo_excel_outputopt_incl. + + +START-OF-SELECTION. + + " Creates active sheet + CREATE OBJECT lo_excel. + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( ip_title = 'PN_MASSIVE'). + + DATA lt_test TYPE TABLE OF sflight. + SELECT * FROM sflight INTO TABLE lt_test. "#EC CI_NOWHERE + + " sheet style (white background) + lo_style = lo_excel->add_new_style( ). + lo_style->fill->filltype = zcl_excel_style_fill=>c_fill_solid. + lo_style->fill->fgcolor-rgb = zcl_excel_style_color=>c_white. + lv_style_guid = lo_style->get_guid( ). + + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->zif_excel_sheet_properties~set_style( lv_style_guid ). + lo_worksheet->zif_excel_sheet_protection~protected = zif_excel_sheet_protection=>c_protected. + lo_worksheet->zif_excel_sheet_protection~password = zcl_excel_common=>encrypt_password( 'test' ). + lo_worksheet->zif_excel_sheet_protection~sheet = zif_excel_sheet_protection=>c_active. + lo_worksheet->zif_excel_sheet_protection~objects = zif_excel_sheet_protection=>c_active. + lo_worksheet->zif_excel_sheet_protection~scenarios = zif_excel_sheet_protection=>c_active. + + " Create cell style for display only fields + lo_style = lo_excel->add_new_style( ). + lo_style->fill->filltype = zcl_excel_style_fill=>c_fill_solid. + lo_style->fill->fgcolor-rgb = zcl_excel_style_color=>c_gray. + lo_style->number_format->format_code = zcl_excel_style_number_format=>c_format_text. + + " Create cell style for display only date field + lo_style_date = lo_excel->add_new_style( ). + lo_style_date->fill->filltype = zcl_excel_style_fill=>c_fill_solid. + lo_style_date->fill->fgcolor-rgb = zcl_excel_style_color=>c_gray. + lo_style_date->number_format->format_code = zcl_excel_style_number_format=>c_format_date_ddmmyyyy. + + " Create cell style for editable fields + lo_style_editable = lo_excel->add_new_style( ). + lo_style_editable->protection->locked = zcl_excel_style_protection=>c_protection_unlocked. + + lt_field_catalog = zcl_excel_common=>get_fieldcatalog( ip_table = lt_test ). + + LOOP AT lt_field_catalog ASSIGNING <fs_field_catalog>. + CASE <fs_field_catalog>-fieldname. + WHEN 'CARRID'. + <fs_field_catalog>-position = 3. + <fs_field_catalog>-dynpfld = abap_true. + <fs_field_catalog>-style = lo_style->get_guid( ). + WHEN 'CONNID'. + <fs_field_catalog>-position = 1. + <fs_field_catalog>-dynpfld = abap_true. + <fs_field_catalog>-style = lo_style->get_guid( ). + WHEN 'FLDATE'. + <fs_field_catalog>-position = 2. + <fs_field_catalog>-dynpfld = abap_true. + <fs_field_catalog>-style = lo_style_date->get_guid( ). + WHEN 'PRICE'. + <fs_field_catalog>-position = 4. + <fs_field_catalog>-dynpfld = abap_true. + <fs_field_catalog>-style = lo_style_editable->get_guid( ). + <fs_field_catalog>-totals_function = zcl_excel_table=>totals_function_sum. + WHEN OTHERS. + <fs_field_catalog>-dynpfld = abap_false. + ENDCASE. + ENDLOOP. + + ls_table_settings-table_style = zcl_excel_table=>builtinstyle_medium2. + ls_table_settings-show_row_stripes = abap_true. + + lo_worksheet->bind_table( EXPORTING + ip_table = lt_test + it_field_catalog = lt_field_catalog + is_table_settings = ls_table_settings + IMPORTING + es_table_settings = ls_table_settings_out ). + + lo_worksheet->freeze_panes( ip_num_rows = 3 ). "freeze column headers when scrolling + + lo_data_validation = lo_worksheet->add_new_data_validation( ). + lo_data_validation->type = zcl_excel_data_validation=>c_type_custom. + lv_row = ls_table_settings_out-top_left_row. + CONDENSE lv_row. + CONCATENATE 'ISNUMBER(' ls_table_settings_out-top_left_column lv_row ')' INTO lo_data_validation->formula1. + lo_data_validation->cell_row = ls_table_settings_out-top_left_row. + lo_data_validation->cell_column = ls_table_settings_out-top_left_column. + lo_data_validation->cell_row_to = ls_table_settings_out-bottom_right_row. + lo_data_validation->cell_column_to = ls_table_settings_out-bottom_right_column. + + + +*** Create output + lcl_output=>output( lo_excel ). + + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZDEMO_EXCEL21 +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_excel21. + +TYPES: + BEGIN OF t_color_style, + color TYPE zexcel_style_color_argb, + style TYPE zexcel_cell_style, + END OF t_color_style. + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + lo_style_filled TYPE REF TO zcl_excel_style. + +DATA: color_styles TYPE TABLE OF t_color_style. + +FIELD-SYMBOLS: <color_style> LIKE LINE OF color_styles. + +CONSTANTS: max TYPE i VALUE 255, + step TYPE i VALUE 51. + +DATA: red TYPE i, + green TYPE i, + blue TYPE i, + red_hex(1) TYPE x, + green_hex(1) TYPE x, + blue_hex(1) TYPE x, + red_str TYPE string, + green_str TYPE string, + blue_str TYPE string. + +DATA: color TYPE zexcel_style_color_argb, + tint TYPE zexcel_style_color_tint. + +DATA: row TYPE i, + row_tmp TYPE i, + column TYPE zexcel_cell_column VALUE 1, + col_str TYPE zexcel_cell_column_alpha. + +CONSTANTS: gc_save_file_name TYPE string VALUE '21_BackgroundColorPicker.xlsx'. +INCLUDE zdemo_excel_outputopt_incl. + + +START-OF-SELECTION. + + " Creates active sheet + CREATE OBJECT lo_excel. + + WHILE red <= max. + green = 0. + WHILE green <= max. + blue = 0. + WHILE blue <= max. + red_hex = red. + red_str = red_hex. + green_hex = green. + green_str = green_hex. + blue_hex = blue. + blue_str = blue_hex. + " Create filled + CONCATENATE 'FF' red_str green_str blue_str INTO color. + APPEND INITIAL LINE TO color_styles ASSIGNING <color_style>. + lo_style_filled = lo_excel->add_new_style( ). + lo_style_filled->fill->filltype = zcl_excel_style_fill=>c_fill_solid. + lo_style_filled->fill->fgcolor-rgb = color. + <color_style>-color = color. + <color_style>-style = lo_style_filled->get_guid( ). + blue = blue + step. + ENDWHILE. + green = green + step. + ENDWHILE. + red = red + step. + ENDWHILE. + " Get active sheet + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_title( 'Color Picker' ). + LOOP AT color_styles ASSIGNING <color_style>. + row_tmp = ( max / step + 1 ) * 3. + IF row = row_tmp. + row = 0. + column = column + 1. + ENDIF. + row = row + 1. + col_str = zcl_excel_common=>convert_column2alpha( column ). + + " Fill the cell and apply one style + lo_worksheet->set_cell( ip_column = col_str + ip_row = row + ip_value = <color_style>-color + ip_style = <color_style>-style ). + ENDLOOP. + + row = row + 2. + tint = '-0.5'. + DO 10 TIMES. + column = 1. + DO 10 TIMES. + lo_style_filled = lo_excel->add_new_style( ). + lo_style_filled->fill->filltype = zcl_excel_style_fill=>c_fill_solid. + lo_style_filled->fill->fgcolor-theme = sy-index - 1. + lo_style_filled->fill->fgcolor-tint = tint. + <color_style>-style = lo_style_filled->get_guid( ). + col_str = zcl_excel_common=>convert_column2alpha( column ). + lo_worksheet->set_cell_style( ip_column = col_str + ip_row = row + ip_style = <color_style>-style ). + + ADD 1 TO column. + ENDDO. + ADD '0.1' TO tint. + ADD 1 TO row. + ENDDO. + + + +*** Create output + lcl_output=>output( lo_excel ). + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + *--------------------------------------------------------------------* +* REPORT ZDEMO_EXCEL20 +* Demo for method zcl_excel_worksheet-bind_alv: +* export data from ALV (CL_GUI_ALV_GRID) object to excel +*--------------------------------------------------------------------* +REPORT zdemo_excel20. + +*----------------------------------------------------------------------* +* CLASS lcl_handle_events DEFINITION +*----------------------------------------------------------------------* +* +*----------------------------------------------------------------------* +CLASS lcl_handle_events DEFINITION. + PUBLIC SECTION. + METHODS: + on_user_command FOR EVENT added_function OF cl_salv_events + IMPORTING e_salv_function. +ENDCLASS. "lcl_handle_events DEFINITION + +*----------------------------------------------------------------------* +* CLASS lcl_handle_events IMPLEMENTATION +*----------------------------------------------------------------------* +* +*----------------------------------------------------------------------* +CLASS lcl_handle_events IMPLEMENTATION. + METHOD on_user_command. + PERFORM user_command." using e_salv_function text-i08. + ENDMETHOD. "on_user_command +ENDCLASS. "lcl_handle_events IMPLEMENTATION + +*--------------------------------------------------------------------* +* DATA DECLARATION +*--------------------------------------------------------------------* + +DATA: lo_excel TYPE REF TO zcl_excel, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + lo_alv TYPE REF TO cl_gui_alv_grid, + lo_salv TYPE REF TO cl_salv_table, + gr_events TYPE REF TO lcl_handle_events, + lr_events TYPE REF TO cl_salv_events_table, + gt_sbook TYPE TABLE OF sbook, + gt_listheader TYPE slis_t_listheader, + wa_listheader LIKE LINE OF gt_listheader. + +DATA: l_path TYPE string, " local dir + lv_workdir TYPE string, + lv_file_separator TYPE c. + +CONSTANTS: + lv_default_file_name TYPE string VALUE '20_BindAlv.xlsx'. +*--------------------------------------------------------------------* +*START-OF-SELECTION +*--------------------------------------------------------------------* + +START-OF-SELECTION. + +* get data +* ------------------------------------------ + + SELECT * + INTO TABLE gt_sbook[] + FROM sbook "#EC CI_NOWHERE + UP TO 10 ROWS. + +* Display ALV +* ------------------------------------------ + + TRY. + cl_salv_table=>factory( + EXPORTING + list_display = abap_false + IMPORTING + r_salv_table = lo_salv + CHANGING + t_table = gt_sbook[] ). + CATCH cx_salv_msg . + ENDTRY. + + TRY. + lo_salv->set_screen_status( + EXPORTING + report = sy-repid + pfstatus = 'ALV_STATUS' + set_functions = lo_salv->c_functions_all ). + CATCH cx_salv_msg . + ENDTRY. + + lr_events = lo_salv->get_event( ). + CREATE OBJECT gr_events. + SET HANDLER gr_events->on_user_command FOR lr_events. + + lo_salv->display( ). + + +*&---------------------------------------------------------------------* +*& Form USER_COMMAND +*&---------------------------------------------------------------------* +* ALV user command +*--------------------------------------------------------------------* +FORM user_command . + IF sy-ucomm = 'EXCEL'. + +* get save file path + cl_gui_frontend_services=>get_sapgui_workdir( CHANGING sapworkdir = l_path ). + cl_gui_cfw=>flush( ). + cl_gui_frontend_services=>directory_browse( + EXPORTING initial_folder = l_path + CHANGING selected_folder = l_path ). + + IF l_path IS INITIAL. + cl_gui_frontend_services=>get_sapgui_workdir( + CHANGING sapworkdir = lv_workdir ). + l_path = lv_workdir. + ENDIF. + + cl_gui_frontend_services=>get_file_separator( + CHANGING file_separator = lv_file_separator ). + + CONCATENATE l_path lv_file_separator lv_default_file_name + INTO l_path. + +* export file to save file path + + PERFORM export_to_excel. + + ENDIF. +ENDFORM. " USER_COMMAND + +*--------------------------------------------------------------------* +* FORM EXPORT_TO_EXCEL +*--------------------------------------------------------------------* +* This subroutine is principal demo session +*--------------------------------------------------------------------* +FORM export_to_excel. + +* create zcl_excel_worksheet object + + CREATE OBJECT lo_excel. + lo_worksheet = lo_excel->get_active_worksheet( ). + +* get ALV object from screen + + CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR' + IMPORTING + e_grid = lo_alv. + +* build list header + + wa_listheader-typ = 'H'. + wa_listheader-info = sy-title. + APPEND wa_listheader TO gt_listheader. + + wa_listheader-typ = 'S'. + wa_listheader-info = 'Created by: ABAP2XLSX Group'. + APPEND wa_listheader TO gt_listheader. + + wa_listheader-typ = 'A'. + wa_listheader-info = + 'Project hosting at https://cw.sdn.sap.com/cw/groups/abap2xlsx'. + APPEND wa_listheader TO gt_listheader. + +* write to excel using method Bin_ALV + + lo_worksheet->bind_alv_ole2( + EXPORTING +* I_DOCUMENT_URL = SPACE " excel template +* I_XLS = 'X' " create in xls format? + i_save_path = l_path + io_alv = lo_alv + it_listheader = gt_listheader + i_top = 2 + i_left = 1 +* I_COLUMNS_HEADER = 'X' +* I_COLUMNS_AUTOFIT = 'X' +* I_FORMAT_COL_HEADER = +* I_FORMAT_SUBTOTAL = +* I_FORMAT_TOTAL = + EXCEPTIONS + miss_guide = 1 + ex_transfer_kkblo_error = 2 + fatal_error = 3 + inv_data_range = 4 + dim_mismatch_vkey = 5 + dim_mismatch_sema = 6 + error_in_sema = 7 + OTHERS = 8 + ). + IF sy-subrc <> 0. + MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno + WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. + ENDIF. + +ENDFORM. "EXPORT_TO_EXCEL + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build/ABAP2XLSX_V_7_0.zip b/build/ABAP2XLSX_V_7_0.zip index d478a55..2812f99 100644 Binary files a/build/ABAP2XLSX_V_7_0.zip and b/build/ABAP2XLSX_V_7_0.zip differ