class ZCL_EXCEL_DRAWING definition public final create public . public section. *"* public components of class ZCL_EXCEL_DRAWING *"* 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 . data Y_REFERENCES type CHAR1 . constants TYPE_IMAGE type ZEXCEL_DRAWING_TYPE value 'image'. "#EC NOTEXT constants TYPE_CHART type ZEXCEL_DRAWING_TYPE value 'chart'. "#EC NOTEXT 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 . methods CONSTRUCTOR importing !IP_TYPE type ZEXCEL_DRAWING_TYPE default ZCL_EXCEL_DRAWING=>TYPE_IMAGE !IP_TITLE type ZEXCEL_SHEET_TITLE optional . methods CREATE_MEDIA_NAME importing !IP_INDEX type I . methods GET_FROM_COL returning value(R_FROM_COL) type ZEXCEL_CELL_COLUMN . methods GET_FROM_ROW returning value(R_FROM_ROW) type ZEXCEL_CELL_ROW . methods GET_GUID returning value(EP_GUID) type GUID_16 . methods GET_HEIGHT_EMU_STR returning value(R_HEIGHT) type STRING . methods GET_MEDIA returning value(R_MEDIA) type XSTRING . methods GET_MEDIA_NAME returning value(R_NAME) type STRING . methods GET_MEDIA_TYPE returning value(R_TYPE) type STRING . methods GET_NAME returning value(R_NAME) type STRING . methods GET_TO_COL returning value(R_TO_COL) type ZEXCEL_CELL_COLUMN . methods GET_TO_ROW returning value(R_TO_ROW) type ZEXCEL_CELL_ROW . methods GET_WIDTH_EMU_STR returning value(R_WIDTH) type STRING . class-methods PIXEL2EMU importing !IP_PIXEL type INT4 !IP_DPI type INT2 optional returning value(R_EMU) type INT4 . methods SET_MEDIA importing !IP_MEDIA type XSTRING !IP_MEDIA_TYPE type STRING !IP_WIDTH type INT4 !IP_HEIGHT type INT4 . methods SET_MEDIA_MIME importing !IP_IO type SKWF_IO !IP_WIDTH type INT4 !IP_HEIGHT type INT4 . methods SET_MEDIA_WWW importing !IP_KEY type WWWDATATAB !IP_WIDTH type INT4 !IP_HEIGHT type INT4 . methods SET_POSITION importing !IP_FROM_ROW type ZEXCEL_CELL_ROW !IP_FROM_COL type ZEXCEL_CELL_COLUMN_ALPHA . methods SET_POSITION2 importing !IP_FROM type ZEXCEL_DRAWING_LOCATION !IP_TO type ZEXCEL_DRAWING_LOCATION !IP_ANCHOR type ZEXCEL_DRAWING_ANCHOR optional . methods GET_POSITION returning value(RP_POSITION) type ZEXCEL_DRAWING_POSITION . methods GET_TYPE returning value(RP_TYPE) type ZEXCEL_DRAWING_TYPE . methods GET_INDEX returning 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. private section. *"* private components of class ZCL_EXCEL_DRAWING *"* do not include other source files here!!! data TYPE type ZEXCEL_DRAWING_TYPE value TYPE_IMAGE. "#EC NOTEXT . data INDEX type STRING . data ANCHOR type ZEXCEL_DRAWING_ANCHOR value ANCHOR_ONE_CELL. "#EC NOTEXT . constants C_MEDIA_SOURCE_WWW type CHAR1 value 1. "#EC NOTEXT constants C_MEDIA_SOURCE_XSTRING type CHAR1 value 0. "#EC NOTEXT constants C_MEDIA_SOURCE_MIME type CHAR1 value 2. "#EC NOTEXT data GUID type GUID_16 . data MEDIA type XSTRING . data MEDIA_KEY_WWW type WWWDATATAB . data MEDIA_NAME type STRING . data MEDIA_SOURCE type CHAR1 . data MEDIA_TYPE type STRING . data IO type SKWF_IO . data FROM_LOC type ZEXCEL_DRAWING_LOCATION . data TO_LOC type ZEXCEL_DRAWING_LOCATION . data SIZE type ZEXCEL_DRAWING_SIZE . *"* 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: 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. 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. media = ip_media. media_type = ip_media_type. media_source = c_media_source_xstring. size-width = ip_width. size-height = ip_height. 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. from_loc-row = ip_from_row - 1. 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.