From c9fff4fa442f2988f946b3f8bfa3b86a1f0dc83f Mon Sep 17 00:00:00 2001 From: Alessandro Iannacci Date: Fri, 30 Nov 2012 17:54:06 +0000 Subject: [PATCH] #236 Chart creation in a worksheet from ABAP - Temporary version (doesn't work) git-svn-id: https://subversion.assembla.com/svn/abap2xlsx/trunk@372 b7d68dce-7c3c-4a99-8ce0-9ea847f5d049 --- ZA2X/CLAS/ZCL_EXCEL_DRAWING.slnk | 159 +++++++++++++++++---- ZA2X/CLAS/ZCL_EXCEL_GRAPH.slnk | 33 +++++ ZA2X/CLAS/ZCL_EXCEL_GRAPH_BARS.slnk | 27 ++++ ZA2X/CLAS/ZCL_EXCEL_GRAPH_PIE.slnk | 27 ++++ ZA2X/CLAS/ZCL_EXCEL_READER_2007.slnk | 165 ++++++++++++---------- ZA2X/CLAS/ZCL_EXCEL_WRITER_2007.slnk | 202 ++++++++++++++++++++++++--- ZA2X/PROG/ZDEMO_EXCEL37.slnk | 3 + ZA2X/PROG/ZDEMO_EXCEL39.slnk | 78 +++++++++++ 8 files changed, 570 insertions(+), 124 deletions(-) create mode 100644 ZA2X/CLAS/ZCL_EXCEL_GRAPH.slnk create mode 100644 ZA2X/CLAS/ZCL_EXCEL_GRAPH_BARS.slnk create mode 100644 ZA2X/CLAS/ZCL_EXCEL_GRAPH_PIE.slnk create mode 100644 ZA2X/PROG/ZDEMO_EXCEL39.slnk diff --git a/ZA2X/CLAS/ZCL_EXCEL_DRAWING.slnk b/ZA2X/CLAS/ZCL_EXCEL_DRAWING.slnk index 45713bc..f56941d 100644 --- a/ZA2X/CLAS/ZCL_EXCEL_DRAWING.slnk +++ b/ZA2X/CLAS/ZCL_EXCEL_DRAWING.slnk @@ -1,4 +1,4 @@ - + class ZCL_EXCEL_DRAWING definition public @@ -10,6 +10,8 @@ public section. *"* do not include other source files here!!! type-pools ABAP . + constants C_GRAPH_PIE type ZEXCEL_GRAPH_TYPE value '1'. "#EC NOTEXT + constants C_GRAPH_BARS type ZEXCEL_GRAPH_TYPE value '0'. "#EC NOTEXT data GRAPH_TYPE type ZEXCEL_GRAPH_TYPE . data TITLE type STRING value 'image1.jpg'. "#EC NOTEXT . data X_REFERENCES type CHAR1 . @@ -19,8 +21,8 @@ public section. constants ANCHOR_ABSOLUTE type ZEXCEL_DRAWING_ANCHOR value 'ABS'. "#EC NOTEXT constants ANCHOR_ONE_CELL type ZEXCEL_DRAWING_ANCHOR value 'ONE'. "#EC NOTEXT constants ANCHOR_TWO_CELL type ZEXCEL_DRAWING_ANCHOR value 'TWO'. "#EC NOTEXT + data GRAPH type ref to ZCL_EXCEL_GRAPH . - class ZCL_EXCEL_DRAWING definition load . methods CONSTRUCTOR importing !IP_TYPE type ZEXCEL_DRAWING_TYPE default ZCL_EXCEL_DRAWING=>TYPE_IMAGE @@ -100,7 +102,10 @@ public section. value(RP_TYPE) type ZEXCEL_DRAWING_TYPE . methods GET_INDEX returning - value(RP_INDEX) type STRING . + value(RP_INDEX) type STRING . + methods LOAD_CHART_ATTRIBUTES + importing + value(IP_CHART) type ref to IF_IXML_DOCUMENT . *"* protected components of class ZCL_EXCEL_DRAWING *"* do not include other source files here!!! protected section. @@ -134,31 +139,34 @@ protected section. *"* in the implementation part of the class ABAP - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -339,6 +347,101 @@ endmethod. 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: node5 TYPE REF TO if_ixml_element. + DATA: node6 TYPE REF TO if_ixml_element. + DATA: node7 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. + +* chartspace = ip_chart->get_elements_by_tag_name( name = 'chartSpace' namespace = 'c' ). +* coll_length = chartspace->get_length( ). +* iterator = chartspace->create_iterator( ). +* +* DO coll_length TIMES. "always 1 +* chartelem ?= iterator->get_next( ). +* +* node ?= chartelem->find_from_name( name = 'chart' namespace = 'c' ). + + TYPES: BEGIN OF t_prop, + val TYPE string, + END OF t_prop. + + DATA ls_prop TYPE t_prop. + + node ?= ip_chart->if_ixml_node~get_first_child( ). + CHECK node IS NOT INITIAL. + node2 ?= node->find_from_name( name = 'plotArea' namespace = 'c' ). + CHECK node2 IS NOT INITIAL. + node3 ?= node2->find_from_name( name = 'pieChart' namespace = 'c' ). + IF node3 IS INITIAL. + node3 ?= node2->find_from_name( name = 'barChart' namespace = 'c' ). + IF node3 IS NOT INITIAL. + me->graph_type = c_graph_bars. + ENDIF. + ELSE. + me->graph_type = c_graph_pie. + ENDIF. + CHECK node3 IS NOT INITIAL. + node4 ?= node3->find_from_name( name = 'ser' namespace = 'c' ). + CHECK node4 IS NOT INITIAL. + node5 ?= node4->find_from_name( name = 'val' namespace = 'c' ). + CHECK node5 IS NOT INITIAL. + node6 ?= node5->find_from_name( name = 'numRef' namespace = 'c' ). + CHECK node6 IS NOT INITIAL. + node7 ?= node6->find_from_name( name = 'f' namespace = 'c' ). + CHECK node7 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 OTHERS. + ENDCASE. + + me->graph->ref = node7->get_value( ). + + "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. + +* node ?= chartElem->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. +* ENDIF. + +* ENDDO. + +ENDMETHOD. diff --git a/ZA2X/CLAS/ZCL_EXCEL_GRAPH.slnk b/ZA2X/CLAS/ZCL_EXCEL_GRAPH.slnk new file mode 100644 index 0000000..e402d31 --- /dev/null +++ b/ZA2X/CLAS/ZCL_EXCEL_GRAPH.slnk @@ -0,0 +1,33 @@ + + + class ZCL_EXCEL_GRAPH definition + public + create public . + +public section. +*"* public components of class ZCL_EXCEL_GRAPH +*"* do not include other source files here!!! + + data REF type STRING . + data NS_1904VAL type STRING value '0'. "#EC NOTEXT . + data NS_LANGVAL type STRING value 'it-IT'. "#EC NOTEXT . + data NS_ROUNDEDCORNERSVAL type STRING value '0'. "#EC NOTEXT . + protected section. +*"* protected components of class ZCL_EXCEL_GRAPH +*"* do not include other source files here!!! + private section. +*"* private components of class ZCL_EXCEL_GRAPH +*"* do not include other source files here!!! + *"* 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 + + + + + diff --git a/ZA2X/CLAS/ZCL_EXCEL_GRAPH_BARS.slnk b/ZA2X/CLAS/ZCL_EXCEL_GRAPH_BARS.slnk new file mode 100644 index 0000000..8cb5e09 --- /dev/null +++ b/ZA2X/CLAS/ZCL_EXCEL_GRAPH_BARS.slnk @@ -0,0 +1,27 @@ + + + class ZCL_EXCEL_GRAPH_BARS definition + public + inheriting from ZCL_EXCEL_GRAPH + final + create public . + +public section. +*"* public components of class ZCL_EXCEL_GRAPH_BARS +*"* do not include other source files here!!! + protected section. +*"* protected components of class ZCL_EXCEL_GRAPH_BARS +*"* do not include other source files here!!! + private section. +*"* private components of class ZCL_EXCEL_GRAPH_BARS +*"* do not include other source files here!!! + *"* 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 + + diff --git a/ZA2X/CLAS/ZCL_EXCEL_GRAPH_PIE.slnk b/ZA2X/CLAS/ZCL_EXCEL_GRAPH_PIE.slnk new file mode 100644 index 0000000..b6efb05 --- /dev/null +++ b/ZA2X/CLAS/ZCL_EXCEL_GRAPH_PIE.slnk @@ -0,0 +1,27 @@ + + + class ZCL_EXCEL_GRAPH_PIE definition + public + inheriting from ZCL_EXCEL_GRAPH + final + create public . + +public section. +*"* public components of class ZCL_EXCEL_GRAPH_PIE +*"* do not include other source files here!!! + protected section. +*"* protected components of class ZCL_EXCEL_GRAPH_PIE +*"* do not include other source files here!!! + private section. +*"* private components of class ZCL_EXCEL_GRAPH_PIE +*"* do not include other source files here!!! + *"* 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 + + diff --git a/ZA2X/CLAS/ZCL_EXCEL_READER_2007.slnk b/ZA2X/CLAS/ZCL_EXCEL_READER_2007.slnk index 4e6e762..6987cb3 100644 --- a/ZA2X/CLAS/ZCL_EXCEL_READER_2007.slnk +++ b/ZA2X/CLAS/ZCL_EXCEL_READER_2007.slnk @@ -1,72 +1,73 @@ - - - - - - - - - - - - - - - - + class ZCL_EXCEL_READER_2007 definition public create public . @@ -76,10 +77,16 @@ public section. *"* do not include other source files here!!! type-pools IXML . - interfaces ZIF_EXCEL_READER . - *"* protected components of class ZCL_EXCEL_READER_2007 + interfaces ZIF_EXCEL_READER . + + class-methods FILL_STRUCT_FROM_ATTRIBUTES + importing + !IP_ELEMENT type ref to IF_IXML_ELEMENT + changing + !CP_STRUCTURE type ANY . + protected section. +*"* protected components of class ZCL_EXCEL_READER_2007 *"* do not include other source files here!!! -protected section. types: BEGIN OF t_relationship, @@ -144,6 +151,7 @@ protected section. id TYPE string, content TYPE xstring, file_ext TYPE string, + content_xml TYPE REF TO IF_IXML_DOCUMENT, END OF t_rel_drawing . types: t_rel_drawings TYPE STANDARD TABLE OF t_rel_drawing WITH NON-UNIQUE DEFAULT KEY . @@ -153,11 +161,6 @@ protected section. !IP_PATH type STRING returning value(RP_RESULT) type STRING . - methods FILL_STRUCT_FROM_ATTRIBUTES - importing - !IP_ELEMENT type ref to IF_IXML_ELEMENT - changing - !CP_STRUCTURE type ANY . methods GET_FROM_ZIP_ARCHIVE importing !I_FILENAME type STRING @@ -530,7 +533,7 @@ endmethod. endmethod. - + method FILL_STRUCT_FROM_ATTRIBUTES. @@ -585,7 +588,7 @@ endmethod. - METHOD get_from_zip_archive. + method GET_FROM_ZIP_ARCHIVE. *--------------------------------------------------------------------* * issue #230 - Pimp my Code * - Stefan Schmöcker, (done) 2012-11-07 @@ -705,11 +708,11 @@ endmethod. * issue#234 - end of insertion *--------------------------------------------------------------------* -ENDMETHOD. +endmethod. - + method GET_IXML_FROM_ZIP_ARCHIVE. @@ -898,6 +901,11 @@ endmethod. 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. @@ -1023,7 +1031,7 @@ endmethod. - METHOD load_styles. + method LOAD_STYLES. *--------------------------------------------------------------------* * issue #230 - Pimp my Code @@ -1256,12 +1264,12 @@ endmethod. ENDWHILE. ENDIF. -ENDMETHOD. +endmethod. - METHOD load_style_borders. + method LOAD_STYLE_BORDERS. *--------------------------------------------------------------------* * issue #230 - Pimp my Code @@ -1386,12 +1394,12 @@ ENDMETHOD. ENDWHILE. -ENDMETHOD. +endmethod. - METHOD load_style_fills. + method LOAD_STYLE_FILLS. *--------------------------------------------------------------------* * ToDos: * 2do§1 Support gradientFill @@ -1504,12 +1512,12 @@ ENDMETHOD. ENDWHILE. -ENDMETHOD. +endmethod. - METHOD load_style_fonts. + method LOAD_STYLE_FONTS. *--------------------------------------------------------------------* * issue #230 - Pimp my Code @@ -1630,7 +1638,7 @@ ENDMETHOD. ENDWHILE. -ENDMETHOD. +endmethod. @@ -2621,11 +2629,12 @@ endmethod. 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 ). + 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 @@ -2637,6 +2646,16 @@ endmethod. * pfx_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( ). diff --git a/ZA2X/CLAS/ZCL_EXCEL_WRITER_2007.slnk b/ZA2X/CLAS/ZCL_EXCEL_WRITER_2007.slnk index 1bf960c..bbc4c44 100644 --- a/ZA2X/CLAS/ZCL_EXCEL_WRITER_2007.slnk +++ b/ZA2X/CLAS/ZCL_EXCEL_WRITER_2007.slnk @@ -1,6 +1,6 @@ - + class ZCL_EXCEL_WRITER_2007 definition public create public . @@ -46,6 +46,11 @@ public section. methods CREATE_RELATIONSHIPS returning value(EP_CONTENT) type XSTRING . + methods CREATE_XL_CHARTS + importing + !IO_DRAWING type ref to ZCL_EXCEL_DRAWING + returning + value(EP_CONTENT) type XSTRING . methods CREATE_XL_DRAWINGS importing !IO_WORKSHEET type ref to ZCL_EXCEL_WORKSHEET @@ -161,7 +166,7 @@ endmethod. - method CREATE. + METHOD create. * Office 2007 file format is a cab of several xml files with extension .xlsx @@ -333,17 +338,28 @@ endmethod. 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 ). + + "-------------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. +ENDMETHOD. @@ -1067,7 +1083,147 @@ endmethod. 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_style_ns_val TYPE string VALUE '102', + lc_xml_node_fallback TYPE string VALUE 'mc:Fallback', + lc_xml_node_style2 TYPE string VALUE 'c:style', + lc_xml_node_style2_ns_val TYPE string VALUE '2'. + + + 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. + +********************************************************************** +* 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_chart TYPE REF TO zcl_excel_graph. + 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 = lc_xml_node_style_ns_val ). + + "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 = lc_xml_node_style2_ns_val ). + + DATA lo_chartb TYPE REF TO zcl_excel_graph_bars. + DATA lo_chartp TYPE REF TO zcl_excel_graph_pie. + + + 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 OTHERS. + ENDCASE. + + + + +********************************************************************** +* 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. @@ -1147,7 +1303,7 @@ endmethod. endmethod. - + method CREATE_XL_DRAWINGS_RELS. @@ -1246,7 +1402,7 @@ endmethod. endmethod. - + @@ -1560,7 +1716,7 @@ endmethod. endmethod. - + method CREATE_XL_RELATIONSHIPS. @@ -1708,7 +1864,7 @@ endmethod. endmethod. - + method CREATE_XL_SHAREDSTRINGS. @@ -1825,7 +1981,7 @@ endmethod. endmethod. - + @@ -3431,7 +3587,7 @@ endmethod. endmethod. - + @@ -3601,7 +3757,7 @@ endmethod. endmethod. - + method CREATE_XL_STYLES. @@ -4521,7 +4677,7 @@ endmethod. endmethod. - + @@ -4572,7 +4728,7 @@ endmethod. io_parent->append_child( new_child = lo_sub_element ). endmethod. - + method CREATE_XL_TABLE. @@ -4743,7 +4899,7 @@ endmethod. endmethod. - + method CREATE_XL_THEME. @@ -4832,9 +4988,9 @@ endmethod. endmethod. - + - METHOD create_xl_workbook. + method CREATE_XL_WORKBOOK. ** Constant node name DATA: lc_xml_node_workbook TYPE string VALUE 'workbook', @@ -5120,9 +5276,9 @@ endmethod. lo_renderer = lo_ixml->create_renderer( ostream = lo_ostream document = lo_document ). lo_renderer->render( ). -ENDMETHOD. +endmethod. - + method FLAG2BOOL. @@ -5135,7 +5291,7 @@ ENDMETHOD. ENDIF. endmethod. - + method GET_SHARED_STRING_INDEX. diff --git a/ZA2X/PROG/ZDEMO_EXCEL37.slnk b/ZA2X/PROG/ZDEMO_EXCEL37.slnk index 48fcb02..066e9f6 100644 --- a/ZA2X/PROG/ZDEMO_EXCEL37.slnk +++ b/ZA2X/PROG/ZDEMO_EXCEL37.slnk @@ -36,6 +36,9 @@ START-OF-SELECTION. 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 diff --git a/ZA2X/PROG/ZDEMO_EXCEL39.slnk b/ZA2X/PROG/ZDEMO_EXCEL39.slnk new file mode 100644 index 0000000..4faee10 --- /dev/null +++ b/ZA2X/PROG/ZDEMO_EXCEL39.slnk @@ -0,0 +1,78 @@ + + + + + + + + + + + + *&---------------------------------------------------------------------* +*& 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: ls_io TYPE skwf_io. + +DATA: ls_upper TYPE ZEXCEL_DRAWING_LOCATION, + ls_lower TYPE ZEXCEL_DRAWING_LOCATION. + +CONSTANTS: gc_save_file_name TYPE string VALUE '39_Charts.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' ). + + " create global drawing, set position and media from web repository + lo_drawing = lo_worksheet->excel->add_new_drawing( + ip_type = zcl_excel_drawing=>type_chart + ip_title = 'titolografico' ). + + data lo_bar type ref to ZCL_EXCEL_GRAPH_BARS. + + create object lo_bar. + + lo_bar->REF = ''. "VALUE RANGE FOR CHART + + lo_drawing->graph = lo_bar. + + ls_lower-row = 10. + ls_lower-col = 10. + + lo_drawing->set_position2( + EXPORTING + ip_from = ls_upper + ip_to = ls_lower ). + + lo_drawing->set_media( + EXPORTING + ip_media = '0' "usato per il template + ip_media_type = 'xml' + ip_width = 0 "usati solo per le immagini + ip_height = 0 ). "usati solo per le immagini + + + lo_worksheet->add_drawing( lo_drawing ). + + +*** Create output + lcl_output=>output( lo_excel ). +