class ZCL_EXCEL_DRAWING definition public final create public . *"* public components of class ZCL_EXCEL_DRAWING *"* do not include other source files here!!! public section. type-pools ABAP . 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 . class-methods PIXEL2EMU importing !IP_PIXEL type INT4 !IP_DPI type INT2 optional returning value(R_EMU) type INT4 . methods CONSTRUCTOR importing !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_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 SET_MEDIA importing !IP_MEDIA type XSTRING !IP_MEDIA_TYPE type STRING !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 GET_WIDTH_EMU_STR returning value(R_WIDTH) type STRING . methods GET_HEIGHT_EMU_STR returning value(R_HEIGHT) type STRING . *"* protected components of class ZCL_EXCEL_DRAWING *"* do not include other source files here!!! protected section. *"* private components of class ZCL_EXCEL_DRAWING *"* do not include other source files here!!! private section. constants C_EXCEL_COL_MODULE type INT2 value 64. "#EC NOTEXT constants C_MEDIA_SOURCE_WWW type CHAR1 value 1. "#EC NOTEXT constants C_MEDIA_SOURCE_XSTRING type CHAR1 value 0. "#EC NOTEXT data GUID type GUID_16 . data LOWER_CELL type ZEXCEL_S_CELL_DATA . 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 UPPER_CELL type ZEXCEL_S_CELL_DATA . data WIDTH type INT4 . data HEIGHT type INT4 . methods CONVERT_COLUMN2ALPHA importing !IP_COLUMN type ZEXCEL_CELL_COLUMN returning value(EP_COLUMN) type ZEXCEL_CELL_COLUMN_ALPHA . methods CONVERT_COLUMN2INT importing !IP_COLUMN type ZEXCEL_CELL_COLUMN_ALPHA returning value(EP_COLUMN) type ZEXCEL_CELL_COLUMN . *"* 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. * 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 CONVERT_COLUMN2ALPHA. DATA: lo_conv TYPE REF TO cl_abap_conv_in_ce, lv_uccpi TYPE i, lv_text TYPE sychar02, lv_module TYPE int4, lv_column TYPE zexcel_cell_column. lv_column = ip_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. DATA: lv_uccpi TYPE i, lv_char TYPE c, lv_column(2) TYPE c. * Calculate most significant letter lv_char = ip_column+1(1). IF lv_char IS NOT INITIAL. "To avoid the first 26 column that have only a char in first position ep_column = cl_abap_conv_out_ce=>uccpi( lv_char ). ep_column = ep_column MOD ( me->c_excel_col_module ). lv_char = ip_column(1). lv_uccpi = cl_abap_conv_out_ce=>uccpi( lv_char ). lv_uccpi = ( lv_uccpi MOD ( me->c_excel_col_module ) ) * 26. ep_column = ep_column + lv_uccpi. ELSE. lv_char = ip_column(1). ep_column = cl_abap_conv_out_ce=>uccpi( lv_char ). ep_column = ep_column - me->c_excel_col_module. ENDIF. endmethod. METHOD create_media_name. DATA: lv_index TYPE string. * if media name is initial, create unique name CHECK media_name IS INITIAL. lv_index = ip_index. CONCATENATE `image` lv_index INTO media_name. CONDENSE media_name NO-GAPS. ENDMETHOD. METHOD GET_FROM_COL. r_from_col = me->upper_cell-cell_column. ENDMETHOD. METHOD get_from_row. r_from_row = me->upper_cell-cell_row. ENDMETHOD. method GET_GUID. ep_guid = me->guid. endmethod. METHOD get_height_emu_str. r_height = pixel2emu( height ). CONDENSE r_height NO-GAPS. 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. 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_TO_COL. r_to_col = me->lower_cell-cell_column. ENDMETHOD. METHOD GET_TO_ROW. r_to_row = me->lower_cell-cell_row. ENDMETHOD. METHOD get_width_emu_str. r_width = pixel2emu( width ). CONDENSE r_width NO-GAPS. 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. width = ip_width. height = ip_height. 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 '.'. width = ip_width. height = ip_height. ENDMETHOD. method SET_POSITION. upper_cell-cell_column = zcl_excel_common=>convert_column2int( ip_from_col ) - 1. upper_cell-cell_row = ip_from_row - 1. endmethod.