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
!IP_ROWOFF type INT4 optional
!IP_COLOFF type INT4 optional .
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: 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.
TYPES: BEGIN OF t_prop,
val TYPE string,
rtl TYPE string,
lang 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.
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 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.
"---------------------------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.
"TODO
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
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_sername type string.
DATA lv_label type string.
DATA lv_value type string.
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.
node2 ?= node->find_from_name( name = 'idx' namespace = 'c' ).
zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ).
lv_idx = ls_prop-val.
node2 ?= node->find_from_name( name = 'order' namespace = 'c' ).
zcl_excel_reader_2007=>fill_struct_from_attributes( EXPORTING ip_element = node2 CHANGING cp_structure = ls_prop ).
lv_order = ls_prop-val.
node2 ?= node->find_from_name( name = 'v' namespace = 'c' ).
if node2 is bound.
lv_sername = node2->get_value( ).
endif.
node2 ?= node->find_from_name( name = 'strRef' namespace = 'c' ).
if node2 is bound.
node3 ?= node2->find_from_name( name = 'f' namespace = 'c' ).
lv_label = node3->get_value( ).
endif.
node2 ?= node->find_from_name( name = 'numRef' namespace = 'c' ).
if node2 is bound.
node3 ?= node2->find_from_name( name = 'f' namespace = 'c' ).
lv_value = node3->get_value( ).
endif.
CALL METHOD lo_piechart->create_serie
EXPORTING
idx = lv_idx
order = lv_order
lbl = lv_label
REF = lv_value
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 OTHERS.
ENDCASE.
"legend
CASE me->graph_type.
WHEN c_graph_bars.
"TODO
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.
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.
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.