diff --git a/ZA2X/CLAS/ZCL_EXCEL.slnk b/ZA2X/CLAS/ZCL_EXCEL.slnk index 06765c2..6cf48e2 100644 --- a/ZA2X/CLAS/ZCL_EXCEL.slnk +++ b/ZA2X/CLAS/ZCL_EXCEL.slnk @@ -1,9 +1,8 @@ - - - - - + + + + class ZCL_EXCEL definition public final @@ -25,8 +24,10 @@ public section. !IO_SHEET type ref to ZCL_EXCEL_WORKSHEET returning value(RO_AUTOFILTER) type ref to ZCL_EXCEL_AUTOFILTER . + class ZCL_EXCEL_DRAWING definition load . methods ADD_NEW_DRAWING importing + !IP_TYPE type ZEXCEL_DRAWING_TYPE default ZCL_EXCEL_DRAWING=>TYPE_IMAGE !IP_TITLE type ZEXCEL_SHEET_TITLE optional returning value(EO_DRAWING) type ref to ZCL_EXCEL_DRAWING . @@ -53,6 +54,11 @@ public section. methods GET_ACTIVE_WORKSHEET returning value(EO_WORKSHEET) type ref to ZCL_EXCEL_WORKSHEET . + methods GET_WORKSHEET_BY_NAME + importing + !IP_SHEET_NAME type ZEXCEL_SHEET_TITLE + returning + value(EO_WORKSHEET) type ref to ZCL_EXCEL_WORKSHEET . methods GET_AUTOFILTERS_REFERENCE returning value(RO_AUTOFILTERS) type ref to ZCL_EXCEL_AUTOFILTERS . @@ -60,6 +66,8 @@ public section. returning value(EP_STYLE) type ZEXCEL_CELL_STYLE . methods GET_DRAWINGS_ITERATOR + importing + !IP_TYPE type ZEXCEL_DRAWING_TYPE returning value(EO_ITERATOR) type ref to CL_OBJECT_COLLECTION_ITERATOR . methods GET_NEXT_TABLE_ID @@ -126,6 +134,7 @@ protected section. data T_STYLEMAPPING1 type ZEXCEL_T_STYLEMAPPING1 . data T_STYLEMAPPING2 type ZEXCEL_T_STYLEMAPPING2 . data DEFAULT_STYLE type ZEXCEL_CELL_STYLE . + data CHARTS type ref to ZCL_EXCEL_DRAWINGS . methods STYLEMAPPING_DYNAMIC_STYLE importing @@ -140,16 +149,117 @@ protected section. *"* 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. @@ -189,37 +299,45 @@ endmethod. 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. - drawings->add( eo_drawing ). + + 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. @@ -241,10 +359,10 @@ endmethod. endmethod. - - - - + + + + method ADD_NEW_WORKSHEET. DATA: lv_guid TYPE guid_16. * Create default blank worksheet @@ -256,7 +374,7 @@ endmethod. 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 @@ -281,7 +399,7 @@ endmethod. ENDLOOP. endmethod. - + method CONSTRUCTOR. DATA: lo_worksheet TYPE REF TO zcl_excel_worksheet, lo_style TYPE REF TO zcl_excel_style. @@ -291,7 +409,12 @@ endmethod. CREATE OBJECT worksheets. CREATE OBJECT ranges. CREATE OBJECT styles. - CREATE OBJECT drawings. + 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. @@ -305,44 +428,51 @@ endmethod. 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. - eo_iterator = me->drawings->get_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, @@ -361,18 +491,18 @@ endmethod. 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. @@ -395,18 +525,18 @@ endmethod. 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, @@ -434,10 +564,10 @@ endmethod. ENDIF. endmethod. - - - - + + + + method GET_STYLE_TO_GUID. " # issue 139 @@ -457,38 +587,57 @@ endmethod. 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. + + DO get_worksheets_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, @@ -510,16 +659,16 @@ endmethod. 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( ). diff --git a/ZA2X/CLAS/ZCL_EXCEL_COMMON.slnk b/ZA2X/CLAS/ZCL_EXCEL_COMMON.slnk index 92801cd..ff69a87 100644 --- a/ZA2X/CLAS/ZCL_EXCEL_COMMON.slnk +++ b/ZA2X/CLAS/ZCL_EXCEL_COMMON.slnk @@ -1,4 +1,4 @@ - + class ZCL_EXCEL_COMMON definition public @@ -842,23 +842,23 @@ CLASS lcl_excel_common_test IMPLEMENTATION. ENDCLASS. "lcl_Excel_Common_Test ABAP - - - - - - - - - - - - - - - - - METHOD assert_differs. + + + + + + + + + + + + + + + + + method ASSERT_DIFFERS. DATA: ls_seoclass TYPE seoclass. " Let see >=7.02 @@ -898,18 +898,18 @@ ENDCLASS. "lcl_Excel_Common_Test * We do nothing for now not supported ENDIF. ENDIF. -ENDMETHOD. +endmethod. - - - - - - - - - - METHOD assert_equals. + + + + + + + + + + method ASSERT_EQUALS. DATA: ls_seoclass TYPE seoclass. " Let see >=7.02 @@ -951,11 +951,11 @@ ENDMETHOD. * We do nothing for now not supported ENDIF. ENDIF. -ENDMETHOD. +endmethod. - - - + + + method CHAR2HEX. IF o_conv IS NOT BOUND. @@ -970,10 +970,10 @@ ENDMETHOD. endmethod. - - - - + + + + method CONVERT_COLUMN2ALPHA. DATA: lo_conv TYPE REF TO cl_abap_conv_in_ce, @@ -1000,10 +1000,10 @@ endmethod. endmethod. - - - - + + + + method CONVERT_COLUMN2INT. DATA: lv_uccpi TYPE i, @@ -1091,10 +1091,10 @@ endmethod. endmethod. - - - - + + + + method CONVERT_COLUMNROW2COLUMN_A_ROW. DATA: width TYPE i, col_width TYPE i, @@ -1113,13 +1113,13 @@ endmethod. e_row = row_str. endmethod. - - - - - - - + + + + + + + method CONVERT_RANGE2COLUMN_A_ROW. DATA: sheet TYPE string, @@ -1158,10 +1158,10 @@ endmethod. ). endmethod. - - - - METHOD date_to_excel_string. + + + + method DATE_TO_EXCEL_STRING. DATA: lv_date_diff TYPE i. CHECK ip_value IS NOT INITIAL. @@ -1174,12 +1174,12 @@ endmethod. 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. +endmethod. - METHOD describe_structure. + method DESCRIBE_STRUCTURE. DATA: lt_components TYPE abap_component_tab, lt_comps TYPE abap_component_tab, lo_struct TYPE REF TO cl_abap_structdescr, @@ -1224,15 +1224,15 @@ ENDMETHOD. ENDIF. ENDLOOP. ENDIF. -ENDMETHOD. +endmethod. method DESCRIBE_TABLE. endmethod. - - - + + + method ENCRYPT_PASSWORD. DATA lv_curr_offset TYPE i. @@ -1272,9 +1272,9 @@ endmethod. endmethod. - - - + + + method ESCAPE_STRING. DATA lv_value TYPE string. @@ -1290,10 +1290,10 @@ endmethod. endmethod. - - - - + + + + method EXCEL_STRING_TO_DATE. DATA: lv_date_int TYPE i. @@ -1313,10 +1313,10 @@ endmethod. ENDTRY. endmethod. - - - - + + + + method EXCEL_STRING_TO_TIME. DATA: lv_seconds_in_day TYPE i, lv_day_fraction TYPE f, @@ -1336,12 +1336,12 @@ endmethod. ENDTRY. endmethod. - - - - - - METHOD fail. + + + + + + method FAIL. DATA: ls_seoclass TYPE seoclass. " Let see >=7.02 @@ -1374,36 +1374,87 @@ endmethod. ENDIF. ENDIF. -ENDMETHOD. +endmethod. - - - - METHOD get_fieldcatalog. + + + + method GET_FIELDCATALOG. + + +* it causes a short dump running DEMO_EXCEL3 +* rein vert to old implementation +* +* 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. +* +* CREATE DATA lr_data LIKE LINE OF ip_table. +* +* lo_structdescr ?= cl_abap_structdescr=>describe_by_data( lr_data ). +* +* lt_dfies = describe_structure( io_struct = lo_structdescr ). +* +* LOOP AT lt_dfies INTO ls_dfies. +* CLEAR ls_fieldcatalog. +* MOVE-CORRESPONDING ls_dfies TO ls_fieldcatalog. +* APPEND ls_fieldcatalog TO ep_fieldcatalog. +* ENDLOOP. DATA: lr_data TYPE REF TO data, lo_structdescr TYPE REF TO cl_abap_structdescr, + lo_elemdescr TYPE REF TO cl_abap_elemdescr, lt_dfies TYPE ddfields, ls_dfies TYPE dfies, - ls_fieldcatalog TYPE zexcel_s_fieldcatalog. + lv_sytabix TYPE sytabix, + ls_fieldcatalog TYPE zexcel_s_fieldcatalog, + lt_components TYPE abap_component_tab, + ls_component LIKE LINE OF lt_components. CREATE DATA lr_data LIKE LINE OF ip_table. - lo_structdescr ?= cl_abap_structdescr=>describe_by_data( lr_data ). + lo_structdescr ?= cl_abap_structdescr=>describe_by_data_ref( lr_data ). - lt_dfies = describe_structure( io_struct = lo_structdescr ). + "for DDIC structure get the info directly + IF lo_structdescr->is_ddic_type( ) = abap_true. + lt_dfies = lo_structdescr->get_ddic_field_list( ). - LOOP AT lt_dfies INTO ls_dfies. - CLEAR ls_fieldcatalog. - MOVE-CORRESPONDING ls_dfies TO ls_fieldcatalog. - APPEND ls_fieldcatalog TO ep_fieldcatalog. - ENDLOOP. + LOOP AT lt_dfies INTO ls_dfies. + CLEAR ls_fieldcatalog. + MOVE-CORRESPONDING ls_dfies TO ls_fieldcatalog. + APPEND ls_fieldcatalog TO ep_fieldcatalog. + ENDLOOP. + ELSE. + "if structure is not DDIC check components + lt_components = lo_structdescr->get_components( ). + LOOP AT lt_components INTO ls_component. + lv_sytabix = sy-tabix. + CLEAR ls_fieldcatalog. + lo_elemdescr ?= ls_component-type. + "component is DDIC + IF lo_elemdescr->is_ddic_type( ) = abap_true. + ls_dfies = lo_elemdescr->get_ddic_field( ). + MOVE-CORRESPONDING ls_dfies TO ls_fieldcatalog. + ls_fieldcatalog-fieldname = ls_component-name. + ELSE. + "component is not DDIC -> return minimum information required + ls_fieldcatalog-fieldname = ls_component-name. + ls_fieldcatalog-dynpfld = abap_true. + ls_fieldcatalog-scrtext_m = ls_component-name. + ENDIF. + ls_fieldcatalog-position = lv_sytabix. + APPEND ls_fieldcatalog TO ep_fieldcatalog. + ENDLOOP. + ENDIF. -ENDMETHOD. + +endmethod. - - - + + + method NUMBER_TO_EXCEL_STRING. DATA: lv_value_c TYPE c LENGTH 100. @@ -1420,10 +1471,10 @@ ENDMETHOD. ENDIF. endmethod. - - - - + + + + method RECURSIVE_CLASS_TO_STRUCT. " # issue 139 * is working for me - but after looking through this coding I guess @@ -1479,10 +1530,10 @@ endmethod. endmethod. - - - - + + + + method RECURSIVE_STRUCT_TO_CLASS. " # issue 139 * is working for me - but after looking through this coding I guess @@ -1539,9 +1590,9 @@ endmethod. endmethod. - - - + + + method SHL01. DATA: @@ -1559,9 +1610,9 @@ endmethod. endmethod. - - - + + + method SHR14. DATA: @@ -1589,7 +1640,7 @@ endmethod. - METHOD structure_case. + method STRUCTURE_CASE. DATA: lt_comp_str TYPE abap_component_tab. CASE is_component-type->kind. @@ -1603,12 +1654,12 @@ endmethod. 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. +endmethod. - METHOD structure_recursive. + method STRUCTURE_RECURSIVE. DATA: lo_struct TYPE REF TO cl_abap_structdescr, lt_components TYPE abap_component_tab, ls_components TYPE abap_componentdescr. @@ -1623,11 +1674,11 @@ ENDMETHOD. CHANGING xt_components = rt_components ) . ENDLOOP. -ENDMETHOD. +endmethod. - - - + + + method TIME_TO_EXCEL_STRING. DATA: lv_seconds_in_day TYPE i, lv_day_fraction TYPE f, diff --git a/ZA2X/CLAS/ZCL_EXCEL_DRAWING.slnk b/ZA2X/CLAS/ZCL_EXCEL_DRAWING.slnk index 88d3151..45713bc 100644 --- a/ZA2X/CLAS/ZCL_EXCEL_DRAWING.slnk +++ b/ZA2X/CLAS/ZCL_EXCEL_DRAWING.slnk @@ -1,22 +1,29 @@ - + 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!!! -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 . + 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 + class ZCL_EXCEL_DRAWING definition load . 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 @@ -79,28 +86,44 @@ public section. methods SET_POSITION importing !IP_FROM_ROW type ZEXCEL_CELL_ROW - !IP_FROM_COL type ZEXCEL_CELL_COLUMN_ALPHA . + !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 . *"* protected components of class ZCL_EXCEL_DRAWING *"* do not include other source files here!!! protected section. - *"* private components of class ZCL_EXCEL_DRAWING + private section. +*"* private components of class ZCL_EXCEL_DRAWING *"* do not include other source files here!!! -private section. + 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 HEIGHT type INT4 . - 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 IO type SKWF_IO . + 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 @@ -111,26 +134,34 @@ private section. *"* in the implementation part of the class ABAP - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + method CONSTRUCTOR. CALL FUNCTION 'GUID_CREATE' @@ -143,56 +174,62 @@ private section. title = me->guid. ENDIF. + me->type = ip_type. + * inizialize dimension range - lower_cell-cell_row = 1. - lower_cell-cell_column = 1. - upper_cell-cell_row = 1. - upper_cell-cell_column = 1. + anchor = anchor_one_cell. + from_loc-col = 1. + from_loc-row = 1. 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. + index = ip_index. + CONCATENATE me->type index INTO media_name. CONDENSE media_name NO-GAPS. endmethod. - - + + method GET_FROM_COL. - r_from_col = me->upper_cell-cell_column. + r_from_col = me->from_loc-col. endmethod. - - + + method GET_FROM_ROW. - r_from_row = me->upper_cell-cell_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( height ). + r_height = pixel2emu( size-height ). CONDENSE r_height NO-GAPS. endmethod. - - - METHOD get_media. + + + method GET_INDEX. + rp_index = me->index. +endmethod. + + + + method GET_MEDIA. CASE media_source. WHEN c_media_source_xstring. r_media = media. @@ -249,49 +286,64 @@ endmethod. failed = 1 OTHERS = 2. ENDCASE. -ENDMETHOD. +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->lower_cell-cell_column. + r_to_col = me->to_loc-col. endmethod. - - + + method GET_TO_ROW. - r_to_row = me->lower_cell-cell_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( width ). + r_width = pixel2emu( size-width ). CONDENSE r_width NO-GAPS. endmethod. - - - - + + + + method PIXEL2EMU. * suppose 96 DPI IF ip_dpi IS SUPPLIED. @@ -302,29 +354,29 @@ endmethod. 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. + size-width = ip_width. + size-height = ip_height. endmethod. - - - - - METHOD set_media_mime. + + + + + method SET_MEDIA_MIME. io = ip_io. media_source = c_media_source_mime. - width = ip_width. - height = ip_height. + size-width = ip_width. + size-height = ip_height. cl_wb_mime_repository=>load_mime( EXPORTING io = ip_io @@ -338,12 +390,12 @@ endmethod. -ENDMETHOD. +endmethod. - - - - + + + + method SET_MEDIA_WWW. DATA: lv_value(20). @@ -360,16 +412,47 @@ ENDMETHOD. media_type = lv_value. SHIFT media_type LEFT DELETING LEADING '.'. - width = ip_width. - height = ip_height. + size-width = ip_width. + size-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. + 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. diff --git a/ZA2X/CLAS/ZCL_EXCEL_DRAWINGS.slnk b/ZA2X/CLAS/ZCL_EXCEL_DRAWINGS.slnk index efa681e..74679a6 100644 --- a/ZA2X/CLAS/ZCL_EXCEL_DRAWINGS.slnk +++ b/ZA2X/CLAS/ZCL_EXCEL_DRAWINGS.slnk @@ -1,19 +1,26 @@ - + class ZCL_EXCEL_DRAWINGS definition public final create public . +public section. *"* public components of class ZCL_EXCEL_DRAWINGS *"* do not include other source files here!!! -public section. + + data TYPE type ZEXCEL_DRAWING_TYPE read-only value 'IMAGE'. "#EC NOTEXT . methods ADD importing !IP_DRAWING type ref to ZCL_EXCEL_DRAWING . + methods INCLUDE + importing + !IP_DRAWING type ref to ZCL_EXCEL_DRAWING . methods CLEAR . - methods CONSTRUCTOR . + methods CONSTRUCTOR + importing + !IP_TYPE type ZEXCEL_DRAWING_TYPE . methods GET importing !IP_INDEX type ZEXCEL_ACTIVE_WORKSHEET @@ -30,13 +37,16 @@ public section. !IP_DRAWING type ref to ZCL_EXCEL_DRAWING . methods SIZE returning - value(EP_SIZE) type I . + value(EP_SIZE) type I . + methods GET_TYPE + returning + value(RP_TYPE) type ZEXCEL_DRAWING_TYPE . *"* protected components of class ZCL_EXCEL_DRAWINGS *"* do not include other source files here!!! protected section. - *"* private components of class ZCL_EXCEL_DRAWINGS + private section. +*"* private components of class ZCL_EXCEL_DRAWINGS *"* do not include other source files here!!! -private section. data DRAWINGS type ref to CL_OBJECT_COLLECTION . *"* local class implementation for public class @@ -47,33 +57,37 @@ private section. *"* 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. + + + + + method ADD. DATA: lv_index TYPE i. drawings->add( ip_drawing ). lv_index = drawings->if_object_collection~size( ). - ip_drawing->create_media_name( lv_index ). -ENDMETHOD. + 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. @@ -81,29 +95,41 @@ endmethod. 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( ). diff --git a/ZA2X/CLAS/ZCL_EXCEL_READER_2007.slnk b/ZA2X/CLAS/ZCL_EXCEL_READER_2007.slnk index 270236f..ea23195 100644 --- a/ZA2X/CLAS/ZCL_EXCEL_READER_2007.slnk +++ b/ZA2X/CLAS/ZCL_EXCEL_READER_2007.slnk @@ -1,60 +1,68 @@ - - - - - - - - - - - - - + + class ZCL_EXCEL_READER_2007 definition @@ -67,17 +75,17 @@ public section. type-pools IXML . interfaces ZIF_EXCEL_READER . - PROTECTED SECTION. + protected section. *"* protected components of class ZCL_EXCEL_READER_2007 *"* do not include other source files here!!! - TYPES: + types: BEGIN OF t_relationship, id TYPE string, type TYPE string, target TYPE string, END OF t_relationship . - TYPES: + types: BEGIN OF t_fileversion, appname TYPE string, lastedited TYPE string, @@ -85,100 +93,125 @@ public section. rupbuild TYPE string, codename TYPE string, END OF t_fileversion . - TYPES: + types: BEGIN OF t_sheet, name TYPE string, sheetid TYPE string, id TYPE string, END OF t_sheet . - TYPES: + types: BEGIN OF t_workbookpr, codename TYPE string, defaultthemeversion TYPE string, END OF t_workbookpr . - TYPES: + types: BEGIN OF t_sheetpr, codename TYPE string, END OF t_sheetpr . - TYPES: + types: BEGIN OF t_range, name TYPE string, localsheetid TYPE string, " issue #163 END OF t_range . - - TYPES t_fills TYPE STANDARD TABLE OF REF TO zcl_excel_style_fill WITH DEFAULT KEY. - TYPES t_borders TYPE STANDARD TABLE OF REF TO zcl_excel_style_borders WITH DEFAULT KEY. - TYPES t_fonts TYPE STANDARD TABLE OF REF TO zcl_excel_style_font WITH DEFAULT KEY. - - TYPES t_style_refs TYPE TABLE OF REF TO zcl_excel_style. - - TYPES: BEGIN OF t_num_format, + types: + t_fills TYPE STANDARD TABLE OF REF TO zcl_excel_style_fill WITH DEFAULT KEY . + types: + t_borders TYPE STANDARD TABLE OF REF TO zcl_excel_style_borders WITH DEFAULT KEY . + types: + t_fonts TYPE STANDARD TABLE OF REF TO zcl_excel_style_font WITH DEFAULT KEY . + types: + t_style_refs TYPE TABLE OF REF TO zcl_excel_style . + types: + BEGIN OF t_num_format, id TYPE string, format TYPE REF TO zcl_excel_style_number_format, - END OF t_num_format. - TYPES t_num_formats TYPE HASHED TABLE OF t_num_format WITH UNIQUE KEY id. - - TYPES: BEGIN OF t_color, + END OF t_num_format . + types: + t_num_formats TYPE HASHED TABLE OF t_num_format WITH UNIQUE KEY id . + types: + BEGIN OF t_color, indexed TYPE string, rgb TYPE string, theme TYPE string, tint TYPE string, - END OF t_color. + END OF t_color . + types: + BEGIN OF T_REL_DRAWING, + id type string, + content type xstring, + file_ext type string, + end of t_rel_drawing . + types: + t_rel_drawings type TABLE OF t_rel_drawing . - 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 - RETURNING - value(r_content) TYPE xstring - RAISING - zcx_excel . - METHODS get_ixml_from_zip_archive - IMPORTING - !i_filename TYPE string - RETURNING - value(r_ixml) TYPE REF TO if_ixml_document - RAISING - zcx_excel . - METHODS load_workbook - IMPORTING - !ip_path TYPE string - !ip_excel TYPE REF TO zcl_excel . - METHODS load_worksheet - IMPORTING - !ip_path TYPE string - !io_worksheet TYPE REF TO zcl_excel_worksheet . - METHODS load_shared_strings - IMPORTING - !ip_path TYPE string . - METHODS load_styles - IMPORTING - !ip_path TYPE string - !ip_excel TYPE REF TO zcl_excel . - METHODS load_style_borders - IMPORTING - !ip_xml TYPE REF TO if_ixml_document - RETURNING - value(ep_borders) TYPE t_borders . - METHODS load_style_fills - IMPORTING - !ip_xml TYPE REF TO if_ixml_document - RETURNING - value(ep_fills) TYPE t_fills . - METHODS load_style_fonts - IMPORTING - !ip_xml TYPE REF TO if_ixml_document - RETURNING - value(ep_fonts) TYPE t_fonts . - METHODS load_style_num_formats - IMPORTING - !ip_xml TYPE REF TO if_ixml_document - RETURNING - value(ep_num_formats) TYPE t_num_formats . + class-methods RESOLVE_PATH + importing + !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 + returning + value(R_CONTENT) type XSTRING + raising + ZCX_EXCEL . + methods GET_IXML_FROM_ZIP_ARCHIVE + importing + !I_FILENAME type STRING + returning + value(R_IXML) type ref to IF_IXML_DOCUMENT + raising + ZCX_EXCEL . + methods LOAD_WORKBOOK + importing + !IP_PATH type STRING + !IP_EXCEL type ref to ZCL_EXCEL . + methods LOAD_DRAWING_ANCHOR + importing + !IO_ANCHOR_ELEMENT type ref to IF_IXML_ELEMENT + !IO_WORKSHEET type ref to ZCL_EXCEL_WORKSHEET + !IT_RELATED_DRAWINGS type T_REL_DRAWINGS . + methods LOAD_WORKSHEET + importing + !IP_PATH type STRING + !IO_WORKSHEET type ref to ZCL_EXCEL_WORKSHEET . + methods LOAD_WORKSHEET_DRAWING + importing + !IP_PATH type STRING + !IO_WORKSHEET type ref to ZCL_EXCEL_WORKSHEET . + methods LOAD_SHARED_STRINGS + importing + !IP_PATH type STRING . + methods LOAD_STYLES + importing + !IP_PATH type STRING + !IP_EXCEL type ref to ZCL_EXCEL . + methods LOAD_STYLE_BORDERS + importing + !IP_XML type ref to IF_IXML_DOCUMENT + returning + value(EP_BORDERS) type T_BORDERS . + methods LOAD_STYLE_FILLS + importing + !IP_XML type ref to IF_IXML_DOCUMENT + returning + value(EP_FILLS) type T_FILLS . + methods LOAD_STYLE_FONTS + importing + !IP_XML type ref to IF_IXML_DOCUMENT + returning + value(EP_FONTS) type T_FONTS . + methods LOAD_STYLE_NUM_FORMATS + importing + !IP_XML type ref to IF_IXML_DOCUMENT + returning + value(EP_NUM_FORMATS) type T_NUM_FORMATS . private section. *"* private components of class ZCL_EXCEL_READER_2007 *"* do not include other source files here!!! @@ -308,7 +341,7 @@ endmethod. r_excel = me->zif_excel_reader~load( excel_data ). endmethod. - + method FILL_STRUCT_FROM_ATTRIBUTES. @@ -335,7 +368,7 @@ endmethod. ENDWHILE. endmethod. - + @@ -375,7 +408,7 @@ endmethod. endmethod. - + @@ -403,7 +436,154 @@ endmethod. 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 ). + +endmethod. + + method LOAD_SHARED_STRINGS. DATA: value TYPE string, @@ -429,7 +609,7 @@ endmethod. endmethod. - + method LOAD_STYLES. @@ -600,7 +780,7 @@ endmethod. endmethod. - + method LOAD_STYLE_BORDERS. @@ -672,7 +852,7 @@ endmethod. ENDWHILE. endmethod. - + method LOAD_STYLE_FILLS. @@ -741,7 +921,7 @@ endmethod. endmethod. - + method LOAD_STYLE_FONTS. @@ -819,7 +999,7 @@ endmethod. endmethod. - + method LOAD_STYLE_NUM_FORMATS. @@ -837,13 +1017,51 @@ endmethod. node ?= node->get_next( ). ENDWHILE. + DEFINE predefined_format. + num_format-id = &1. + create object num_format-format. + num_format-format->format_code = &2. + insert num_format into table ep_num_formats. + END-OF-DEFINITION. + + 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'. + 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)'. + 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' '@'. endmethod. - + - METHOD load_workbook. + method LOAD_WORKBOOK. CONSTANTS: lc_shared_strings TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings', lc_worksheet TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet', @@ -964,12 +1182,12 @@ endmethod. node ?= node->get_next( ). ENDWHILE. -ENDMETHOD. +endmethod. - + - METHOD load_worksheet. + method LOAD_WORKSHEET. TYPES: BEGIN OF t_cell, r TYPE string, t TYPE string, @@ -982,18 +1200,9 @@ ENDMETHOD. width TYPE float, customwidth TYPE string, style TYPE string, + hidden TYPE string, END OF t_column. - TYPES: BEGIN OF t_row, - r TYPE string, - customheight TYPE string, - ht TYPE float, - spans TYPE string, - thickbot TYPE string, - customformat TYPE string, - thicktop TYPE string, - END OF t_row. - TYPES: BEGIN OF t_sheetview, showgridlines TYPE zexcel_show_gridlines, tabselected TYPE string, @@ -1006,18 +1215,56 @@ ENDMETHOD. ref TYPE string, END OF t_mergecell. + TYPES: BEGIN OF t_row, + r TYPE string, + customheight TYPE string, + ht TYPE float, + spans TYPE string, + thickbot TYPE string, + customformat TYPE string, + thicktop TYPE string, + END OF t_row. + + TYPES: BEGIN OF t_page_setup, + id TYPE string, + orientation TYPE string, + scale TYPE string, + END OF t_page_setup. + + TYPES: BEGIN OF t_page_margins, + footer TYPE string, + header TYPE string, + bottom TYPE string, + top TYPE string, + right TYPE string, + left TYPE string, + END OF t_page_margins. + + TYPES: BEGIN OF t_sheetformatpr, + customheight TYPE string, + defaultrowheight TYPE string, + customwidth TYPE string, + defaultcolwidth TYPE string, + END OF t_sheetformatpr. + + TYPES: BEGIN OF t_headerfooter, + alignwithmargins TYPE string, + differentoddeven TYPE string, + END OF t_headerfooter. + + CONSTANTS: lc_xml_attr_true TYPE string VALUE 'true', lc_xml_attr_true_int TYPE string VALUE '1'. + CONSTANTS: 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: worksheet TYPE REF TO if_ixml_document, - rows TYPE REF TO if_ixml_node_collection, cells TYPE REF TO if_ixml_node_collection, iterator TYPE REF TO if_ixml_node_iterator, iterator2 TYPE REF TO if_ixml_node_iterator, + row_elem TYPE REF TO if_ixml_element, cell_elem TYPE REF TO if_ixml_element, cell TYPE t_cell, - row_elem TYPE REF TO if_ixml_element, - row TYPE t_row, index TYPE i, value_elem TYPE REF TO if_ixml_element, formula_elem TYPE REF TO if_ixml_element, @@ -1038,13 +1285,76 @@ ENDMETHOD. merge_column_end TYPE zexcel_cell_column_alpha, merge_row_start TYPE zexcel_cell_row, merge_row_end TYPE zexcel_cell_row, - row_dimension TYPE REF TO ZCL_EXCEL_WORKSHEET_ROWDIMENSI, + + sheetformatpr_elem TYPE REF TO if_ixml_element, + sheetformatpr TYPE t_sheetformatpr, + height TYPE float, + width TYPE float, + + headerfooter_elem TYPE REF TO if_ixml_element, + headerfooter TYPE t_headerfooter, + odd_header TYPE zexcel_s_worksheet_head_foot, + odd_footer TYPE zexcel_s_worksheet_head_foot, + even_header TYPE zexcel_s_worksheet_head_foot, + even_footer TYPE zexcel_s_worksheet_head_foot, + hf_value_elem TYPE REF TO if_ixml_element, + + pagemargins_elem TYPE REF TO if_ixml_element, + pagemargins TYPE t_page_margins, + pagesetup_elem TYPE REF TO if_ixml_element, + pagesetup TYPE t_page_setup, columns TYPE REF TO if_ixml_node_collection, column_elem TYPE REF TO if_ixml_element, column TYPE t_column, column_alpha TYPE zexcel_cell_column_alpha, - column_dimension TYPE REF TO zcl_excel_worksheet_columndime. + column_dimension TYPE REF TO zcl_excel_worksheet_columndime, + + rows TYPE REF TO if_ixml_node_collection, + row TYPE t_row, + row_dimension TYPE REF TO zcl_excel_worksheet_rowdimensi, + + path TYPE string, + node TYPE REF TO if_ixml_element, + relationship TYPE t_relationship, + rels_worksheet TYPE REF TO if_ixml_document, + rels_worksheet_path TYPE string, + stripped_name TYPE chkfile, + dirname TYPE string. + + " 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_worksheet_path. + rels_worksheet = me->get_ixml_from_zip_archive( rels_worksheet_path ). + node ?= rels_worksheet->find_from_name( 'Relationship' ). + WHILE node IS BOUND. + fill_struct_from_attributes( EXPORTING ip_element = node CHANGING cp_structure = relationship ). + CONCATENATE dirname relationship-target INTO path. + path = resolve_path( path ). + + CASE relationship-type. + WHEN lc_rel_drawing. + " Read Drawings + CALL METHOD me->load_worksheet_drawing + EXPORTING + ip_path = path + io_worksheet = io_worksheet. + + WHEN lc_rel_printer. + " Read Printer settings + + WHEN OTHERS. + ENDCASE. + + node ?= node->get_next( ). + ENDWHILE. + worksheet = me->get_ixml_from_zip_archive( ip_path ). rows = worksheet->get_elements_by_tag_name( name = 'row' ). @@ -1109,7 +1419,7 @@ ENDMETHOD. ). io_worksheet->set_cell( ip_column = cell_column " cell_elem Column - ip_row = cell_row " cell_elem Row + ip_row = cell_row " cell_elem row_elem ip_value = cell_value " cell_elem Value ip_formula = cell_formula ip_data_type = cell-t @@ -1137,7 +1447,17 @@ ENDMETHOD. column_dimension->set_width( column-width ). ADD 1 TO index. ENDWHILE. + ENDIF. + 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. @@ -1180,7 +1500,198 @@ ENDMETHOD. ). ENDWHILE. + " read sheet format properties + sheetformatpr_elem = worksheet->find_from_name( 'sheetFormatPr' ). + IF sheetformatpr_elem IS NOT INITIAL. + fill_struct_from_attributes( EXPORTING ip_element = sheetformatpr_elem CHANGING cp_structure = sheetformatpr ). + IF sheetformatpr-customheight = '1'. + height = sheetformatpr-defaultrowheight. + io_worksheet->get_default_row_dimension( )->set_row_height( height ). + ENDIF. -ENDMETHOD. + " TODO... column + ENDIF. + + " Read in page margins + pagemargins_elem = worksheet->find_from_name( 'pageMargins' ). + IF pagemargins_elem IS NOT INITIAL. + fill_struct_from_attributes( EXPORTING ip_element = pagemargins_elem CHANGING cp_structure = pagemargins ). + io_worksheet->sheet_setup->margin_bottom = pagemargins-bottom. + io_worksheet->sheet_setup->margin_footer = pagemargins-footer. + io_worksheet->sheet_setup->margin_header = pagemargins-header. + io_worksheet->sheet_setup->margin_left = pagemargins-left. + io_worksheet->sheet_setup->margin_right = pagemargins-right. + io_worksheet->sheet_setup->margin_top = pagemargins-top. + ENDIF. + + " Read in page setup + pagesetup_elem = worksheet->find_from_name( 'pageSetup' ). + IF pagesetup_elem IS NOT INITIAL. + fill_struct_from_attributes( EXPORTING ip_element = pagesetup_elem CHANGING cp_structure = pagesetup ). + io_worksheet->sheet_setup->orientation = pagesetup-orientation. + io_worksheet->sheet_setup->scale = pagesetup-scale. + ENDIF. + + " Read header footer + headerfooter_elem = worksheet->find_from_name( 'headerFooter' ). + IF headerfooter_elem IS NOT INITIAL. + fill_struct_from_attributes( EXPORTING ip_element = headerfooter_elem CHANGING cp_structure = headerfooter ). + io_worksheet->sheet_setup->diff_oddeven_headerfooter = headerfooter-differentoddeven. + + hf_value_elem = headerfooter_elem->find_from_name( 'oddFooter' ). + IF hf_value_elem IS NOT INITIAL. + odd_footer-left_value = hf_value_elem->get_value( ). + ENDIF. + + " TODO.. get the rest. + + io_worksheet->sheet_setup->set_header_footer( + ip_odd_header = odd_header + ip_odd_footer = odd_footer + ip_even_header = even_header + ip_even_footer = even_footer ). + + ENDIF. + +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 draw-filep, + file_ext2 TYPE char32. + + " 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 ). + + path2 = path. + CALL FUNCTION 'CV120_SPLIT_FILE' + EXPORTING + pf_file = path2 + IMPORTING + pfx_extension = file_ext2. + rel_drawing-file_ext = file_ext2. + + 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 RESOLVE_PATH. + + DATA: lt_segments TYPE TABLE OF string, + lv_segment TYPE string, + lv_count TYPE i. + + SPLIT ip_path AT '/' INTO TABLE lt_segments. + lv_count = lines( lt_segments ). + + WHILE lv_count > 0. + READ TABLE lt_segments INTO lv_segment INDEX lv_count. + + IF lv_segment = '..'. + SUBTRACT 1 FROM lv_count. + ELSE. + IF strlen( rp_result ) > 0. + CONCATENATE '/' rp_result INTO rp_result. + ENDIF. + CONCATENATE lv_segment rp_result INTO rp_result. + ENDIF. + + SUBTRACT 1 FROM lv_count. + ENDWHILE. + +endmethod. diff --git a/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk b/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk index af9df96..d3d8e9c 100644 --- a/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk +++ b/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk @@ -1,8 +1,8 @@ - + - - - + + + class ZCL_EXCEL_WORKSHEET definition public final @@ -31,6 +31,7 @@ public section. data SHOW_GRIDLINES type ZEXCEL_SHOW_GRIDLINES read-only value ABAP_TRUE. "#EC NOTEXT . data SHOW_ROWCOLHEADERS type ZEXCEL_SHOW_GRIDLINES read-only value ABAP_TRUE. "#EC NOTEXT . data STYLES type ZEXCEL_T_SHEET_STYLE . + data EXCEL type ref to ZCL_EXCEL read-only . methods ADD_DRAWING importing @@ -256,9 +257,13 @@ public section. raising ZCX_EXCEL . methods GET_DRAWINGS + importing + !IP_TYPE type ZEXCEL_DRAWING_TYPE optional returning value(R_DRAWINGS) type ref to ZCL_EXCEL_DRAWINGS . methods GET_DRAWINGS_ITERATOR + importing + !IP_TYPE type ZEXCEL_DRAWING_TYPE returning value(EO_ITERATOR) type ref to CL_OBJECT_COLLECTION_ITERATOR . methods GET_FREEZE_CELL @@ -370,6 +375,8 @@ public section. !IP_TABLE_TITLE type STRING !IP_TOP_LEFT_COLUMN type ZEXCEL_CELL_COLUMN_ALPHA default 'B' !IP_TOP_LEFT_ROW type ZEXCEL_CELL_ROW default 3 + !IP_TRANSPOSE type XFELD optional + !IP_NO_HEADER type XFELD optional raising ZCX_EXCEL . methods SET_TITLE @@ -393,7 +400,6 @@ private section. data DEFAULT_EXCEL_TIME_FORMAT type ZEXCEL_NUMBER_FORMAT . data DEFAULT_ROW_DIMENSION type ref to ZCL_EXCEL_WORKSHEET_ROWDIMENSI . data DRAWINGS type ref to ZCL_EXCEL_DRAWINGS . - data EXCEL type ref to ZCL_EXCEL . data FREEZE_PANE_CELL_COLUMN type ZEXCEL_CELL_COLUMN . data FREEZE_PANE_CELL_ROW type ZEXCEL_CELL_ROW . data GUID type OLTPGUID16 . @@ -403,6 +409,7 @@ private section. data TABLES type ref to CL_OBJECT_COLLECTION . data TITLE type ZEXCEL_SHEET_TITLE value 'Worksheet'. "#EC NOTEXT . data UPPER_CELL type ZEXCEL_S_CELL_DATA . + data CHARTS type ref to ZCL_EXCEL_DRAWINGS . methods CALCULATE_CELL_WIDTH importing @@ -579,9 +586,6 @@ endclass. *"* use this source file for any macro definitions you need *"* in the implementation part of the class - - - @@ -595,39 +599,40 @@ endclass. ABAP SLIS SOI - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + method ZIF_EXCEL_SHEET_PROPERTIES~GET_STYLE. IF zif_excel_sheet_properties~style IS NOT INITIAL. @@ -692,35 +697,40 @@ endmethod. me->zif_excel_sheet_vba_project~codename_pr = ip_codename_pr. endmethod. - - + + method ADD_DRAWING. - drawings->add( ip_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 BIND_ALV. data: lo_converter type ref to zcl_excel_converter. @@ -743,26 +753,26 @@ endmethod. endmethod. - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + method BIND_ALV_OLE2. *--------------------------------------------------------------------* * Method description: @@ -2832,11 +2842,11 @@ endmethod. close_document. endmethod. - - - - - + + + + + method BIND_TABLE. @@ -3007,11 +3017,11 @@ endmethod. endmethod. - - - - - + + + + + method CALCULATE_CELL_WIDTH. DATA: cell_value TYPE zexcel_cell_value, guid TYPE zexcel_cell_style, @@ -3036,7 +3046,7 @@ endmethod. endmethod. - + method CALCULATE_COLUMN_WIDTHS. TYPES: @@ -3115,107 +3125,107 @@ endmethod. endmethod. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + method CHANGE_CELL_STYLE. " issue # 139 DATA: stylemapping TYPE zexcel_s_stylemapping, @@ -3514,10 +3524,10 @@ endmethod. endmethod. - - - - + + + + method CONSTRUCTOR. DATA: lv_title TYPE zexcel_sheet_title. @@ -3542,7 +3552,12 @@ endmethod. CREATE OBJECT conditional_styles. CREATE OBJECT data_validations. CREATE OBJECT tables. - CREATE OBJECT drawings. + 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. @@ -3559,7 +3574,7 @@ endmethod. endmethod. - + method DELETE_MERGE. DELETE sheet_content_merge INDEX 1. @@ -3567,10 +3582,10 @@ endmethod. endmethod. - - - - + + + + method FREEZE_PANES. data: lv_xsplit type i, lv_ysplit type i. @@ -3597,8 +3612,8 @@ endmethod. 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, @@ -3632,8 +3647,8 @@ endmethod. ENDDO. endmethod. - - + + method GET_ACTIVE_CELL. @@ -3648,14 +3663,14 @@ endmethod. endmethod. - - - - - - - - + + + + + + + + method GET_CELL. DATA: lv_column TYPE zexcel_cell_column, @@ -3687,10 +3702,10 @@ endmethod. 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 @@ -3714,40 +3729,48 @@ endmethod. 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'. @@ -3772,8 +3795,8 @@ endmethod. ep_default_excel_date_format = default_excel_date_format. endmethod. - - + + method GET_DEFAULT_EXCEL_TIME_FORMAT. DATA: l_timefm TYPE xutimefm. @@ -3808,14 +3831,18 @@ endmethod. 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. @@ -3834,64 +3861,96 @@ endmethod. endmethod. - - + + + method GET_DRAWINGS. - r_drawings = 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. - eo_iterator = drawings->get_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. @@ -3966,9 +4025,9 @@ endmethod. endmethod. - - - + + + method GET_ROW_DIMENSION. FIELD-SYMBOLS: <fs_row_dimension> LIKE LINE OF row_dimensions. @@ -3988,27 +4047,27 @@ endmethod. endmethod. - - + + method GET_ROW_DIMENSIONS. r_row_dimension[] = me->row_dimensions[]. 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. @@ -4019,10 +4078,10 @@ endmethod. ENDIF. endmethod. - - - - + + + + method GET_VALUE_TYPE. DATA: lo_addit TYPE REF TO cl_abap_elemdescr, ls_dfies TYPE dfies, @@ -4076,16 +4135,16 @@ endmethod. endmethod. - - - - - - - - - - + + + + + + + + + + method SET_CELL. DATA: lv_column TYPE zexcel_cell_column, @@ -4118,12 +4177,17 @@ endmethod. 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 <> 0 OR " No cell found --> use supplied style even if empty - ip_style IS SUPPLIED. " Style provided as method-parameter --> use this - lv_style_guid = ip_style. + 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. -* 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. + " 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 @@ -4297,11 +4361,11 @@ endmethod. endmethod. - - - - - + + + + + method SET_CELL_STYLE. DATA: lv_column TYPE zexcel_cell_column, @@ -4327,11 +4391,11 @@ endmethod. endmethod. - - - - - + + + + + method SET_COLUMN_WIDTH. DATA: column_dimension TYPE REF TO zcl_excel_worksheet_columndime. DATA: width TYPE float. @@ -4363,8 +4427,8 @@ endmethod. endmethod. - - + + method SET_DEFAULT_EXCEL_DATE_FORMAT. @@ -4377,11 +4441,11 @@ endmethod. default_excel_date_format = ip_default_excel_date_format. endmethod. - - - - - + + + + + method SET_MERGE. @@ -4419,16 +4483,16 @@ endmethod. 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. @@ -4456,25 +4520,27 @@ endmethod. 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_TABLE. @@ -4510,31 +4576,49 @@ endmethod. * 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 ). - " 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 ). - ADD 1 TO lv_row_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 = lv_cell_value + ip_value = <fs_fldval> "lv_cell_value ip_style = ip_body_style ). - ADD 1 TO lv_row_int. + IF ip_transpose = abap_true. + ADD 1 TO lv_column_int. + ELSE. + ADD 1 TO lv_row_int. + ENDIF. ENDLOOP. - lv_row_int = ip_top_left_row. - ADD 1 TO lv_column_int. + 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. DATA: lo_worksheets_iterator TYPE REF TO cl_object_collection_iterator, lo_worksheet TYPE REF TO zcl_excel_worksheet, @@ -4568,7 +4652,7 @@ endmethod. me->title = ip_title. endmethod. - + method UPDATE_DIMENSION_RANGE. diff --git a/ZA2X/CLAS/ZCL_EXCEL_WRITER_2007.slnk b/ZA2X/CLAS/ZCL_EXCEL_WRITER_2007.slnk index e25019a..7763838 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 . @@ -10,9 +10,9 @@ public section. *"* do not include other source files here!!! interfaces ZIF_EXCEL_WRITER . - *"* protected components of class ZCL_EXCEL_WRITER_2007 + protected section. +*"* protected components of class ZCL_EXCEL_WRITER_2007 *"* do not include other source files here!!! -protected section. constants C_CONTENT_TYPES type STRING value '[Content_Types].xml'. "#EC NOTEXT constants C_DOCPROPS_APP type STRING value 'docProps/app.xml'. "#EC NOTEXT @@ -29,6 +29,7 @@ protected section. constants C_XL_THEME type STRING value 'xl/theme/theme1.xml'. "#EC NOTEXT constants C_XL_WORKBOOK type STRING value 'xl/workbook.xml'. "#EC NOTEXT data EXCEL type ref to ZCL_EXCEL . + constants C_XL_PRINTERSETTINGS type STRING value 'xl/printerSettings/printerSettings#.bin'. "#EC NOTEXT methods CREATE returning @@ -50,6 +51,13 @@ protected section. !IO_WORKSHEET type ref to ZCL_EXCEL_WORKSHEET returning value(EP_CONTENT) type XSTRING . + methods CREATE_XL_DRAWING_ANCHOR + importing + !IO_DRAWING type ref to ZCL_EXCEL_DRAWING + !IO_DOCUMENT type ref to IF_IXML_DOCUMENT + !IP_INDEX type I + returning + value(EP_ANCHOR) type ref to IF_IXML_ELEMENT . methods CREATE_XL_DRAWINGS_RELS importing !IO_WORKSHEET type ref to ZCL_EXCEL_WORKSHEET @@ -123,26 +131,27 @@ protected section. *"* 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. @@ -150,8 +159,8 @@ protected section. ep_file = me->create( ). endmethod. - - + + method CREATE. * Office 2007 file format is a cab of several xml files with extension .xlsx @@ -177,7 +186,7 @@ endmethod. ********************************************************************** * Start of insertion # issue 139 - Dateretention of cellstyles - me->excel->add_static_styles( ). + me->excel->add_static_styles( ). * End of insertion # issue 139 - Dateretention of cellstyles ********************************************************************** @@ -301,12 +310,12 @@ endmethod. content = lv_content ). ADD 1 TO lv_drawing_index. ENDIF. + ENDWHILE. ********************************************************************** * STEP 11: Add media - lo_iterator = me->excel->get_drawings_iterator( ). - + 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( ). @@ -317,14 +326,27 @@ endmethod. 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 12: Create the final zip ep_excel = lo_zip->save( ). endmethod. - - + + method CREATE_CONTENT_TYPES. @@ -349,6 +371,7 @@ endmethod. 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', @@ -360,7 +383,8 @@ endmethod. 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_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, @@ -525,7 +549,7 @@ endmethod. lv_media_type TYPE mimetypes-extension, lv_mime_type TYPE mimetypes-type. - lo_iterator = me->excel->get_drawings_iterator( ). + 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( ). @@ -551,6 +575,24 @@ endmethod. 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 ). @@ -578,8 +620,8 @@ endmethod. endmethod. - - + + method CREATE_DOCPROPS_APP. @@ -801,8 +843,8 @@ endmethod. endmethod. - - + + method CREATE_DOCPROPS_CORE. @@ -926,8 +968,8 @@ endmethod. endmethod. - - + + method CREATE_RELATIONSHIPS. @@ -1025,43 +1067,16 @@ endmethod. 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', - lc_xml_node_onecellanchor TYPE string VALUE 'xdr:oneCellAnchor', - 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_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'. - + 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'. @@ -1069,25 +1084,14 @@ endmethod. 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_element3 TYPE REF TO if_ixml_element, - lo_element_onecellanchor TYPE REF TO if_ixml_element, - lo_element_from 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, + 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_drawing TYPE REF TO zcl_excel_drawing, - - lv_col TYPE string, " zexcel_cell_column, - lv_row TYPE string, " zexcel_cell_row. - lv_counter TYPE i VALUE 0, - lv_value TYPE string. + lo_drawing TYPE REF TO zcl_excel_drawing. + DATA: lv_rel_id TYPE i. @@ -1115,134 +1119,19 @@ endmethod. ********************************************************************** * STEP 4: Create drawings - lo_iterator = io_worksheet->get_drawings_iterator( ). + CLEAR: lv_rel_id. + + lo_iterator = io_worksheet->get_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( ). - lo_element_onecellanchor = lo_document->create_simple_element( name = lc_xml_node_onecellanchor - parent = lo_document ). + 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 ). -* from cell ****************************** - lo_element_from = lo_document->create_simple_element( name = lc_xml_node_from - parent = lo_document ). - - lv_col = lo_drawing->get_from_col( ). - lv_row = lo_drawing->get_from_row( ). - CONDENSE lv_col NO-GAPS. - CONDENSE lv_row NO-GAPS. - - lo_element = lo_document->create_simple_element( name = lc_xml_node_col - parent = lo_document ). - lo_element->set_value( value = lv_col ). - lo_element_from->append_child( new_child = lo_element ). - - lo_element = lo_document->create_simple_element( name = lc_xml_node_coloff - parent = lo_document ). - lo_element->set_value( value = `0` ). - lo_element_from->append_child( new_child = lo_element ). - - lo_element = lo_document->create_simple_element( name = lc_xml_node_row - parent = lo_document ). - lo_element->set_value( value = lv_row ). - lo_element_from->append_child( new_child = lo_element ). - - lo_element = lo_document->create_simple_element( name = lc_xml_node_rowoff - parent = lo_document ). - lo_element->set_value( value = `1` ). - lo_element_from->append_child( new_child = lo_element ). - -* ext ****************************** - lo_element_ext = lo_document->create_simple_element( name = lc_xml_node_ext - parent = lo_document ). - - lv_value = lo_drawing->get_width_emu_str( ). - lo_element_ext->set_attribute_ns( name = 'cx' - value = lv_value ). - lv_value = lo_drawing->get_height_emu_str( ). - lo_element_ext->set_attribute_ns( name = 'cy' - value = lv_value ). - - -* pic ********************************** - lo_element_pic = lo_document->create_simple_element( name = lc_xml_node_pic - parent = lo_document ). -* nvPicPr - lo_element = lo_document->create_simple_element( name = lc_xml_node_nvpicpr - parent = lo_document ). -* cNvPr - lo_element2 = lo_document->create_simple_element( name = lc_xml_node_cnvpr - parent = lo_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 = 'Image 1' ). - lo_element->append_child( new_child = lo_element2 ). - -* cNvPicPr - lo_element2 = lo_document->create_simple_element( name = lc_xml_node_cnvpicpr - parent = lo_document ). - -* picLocks - lo_element3 = lo_document->create_simple_element( name = lc_xml_node_piclocks - parent = lo_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 - 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_blipfill - parent = lo_document ). - lo_element2 = lo_document->create_simple_element( name = lc_xml_node_ablip - parent = lo_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 = lo_document->create_simple_element( name = lc_xml_node_astretch - parent = lo_document ). - lo_element->append_child( new_child = lo_element2 ). - - lo_element_pic->append_child( new_child = lo_element ). - -* spPr - lo_element = lo_document->create_simple_element( name = lc_xml_node_sppr - parent = lo_document ). - - lo_element2 = lo_document->create_simple_element( name = lc_xml_node_apgeom - parent = lo_document ). - lo_element2->set_attribute_ns( name = 'prst' - value = 'rect' ). - lo_element3 = lo_document->create_simple_element( name = lc_xml_node_aavlst - parent = lo_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 ). - -* client data *************************** - lo_element_clientdata = lo_document->create_simple_element( name = lc_xml_node_clientdata - parent = lo_document ). - - - - - lo_element_onecellanchor->append_child( new_child = lo_element_from ). - lo_element_onecellanchor->append_child( new_child = lo_element_ext ). - lo_element_onecellanchor->append_child( new_child = lo_element_pic ). - lo_element_onecellanchor->append_child( new_child = lo_element_clientdata ). - lo_element_root->append_child( new_child = lo_element_onecellanchor ). + lo_element_root->append_child( new_child = lo_element_cellanchor ). ENDWHILE. @@ -1255,9 +1144,9 @@ endmethod. endmethod. - - - + + + method CREATE_XL_DRAWINGS_RELS. ** Constant node name @@ -1269,7 +1158,8 @@ endmethod. 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_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, @@ -1309,7 +1199,7 @@ endmethod. " Add sheet Relationship nodes here lv_counter = 0. - lo_iterator = io_worksheet->get_drawings_iterator( ). + lo_iterator = io_worksheet->get_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. @@ -1321,17 +1211,27 @@ endmethod. 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_image_tp ). + value = lv_value ). lv_value = lo_drawing->get_media_name( ). - CONCATENATE '../media/' lv_value INTO lv_value. + 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 ). + 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( ). @@ -1341,8 +1241,322 @@ endmethod. 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. @@ -1489,8 +1703,8 @@ endmethod. endmethod. - - + + method CREATE_XL_SHAREDSTRINGS. @@ -1606,11 +1820,11 @@ endmethod. endmethod. - - - - - + + + + + method CREATE_XL_SHEET. TYPES: BEGIN OF cfvo, @@ -3136,10 +3350,10 @@ endmethod. endmethod. - - - - + + + + method CREATE_XL_SHEET_RELS. @@ -3155,6 +3369,7 @@ endmethod. " 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'. @@ -3259,11 +3474,11 @@ endmethod. CONCATENATE 'rId' lv_value INTO lv_value. lo_element = lo_document->create_simple_element( name = lc_xml_node_relationship - parent = lo_document ). + parent = lo_document ). lo_element->set_attribute_ns( name = lc_xml_attr_id - value = lv_value ). + value = lv_value ). lo_element->set_attribute_ns( name = lc_xml_attr_type - value = lc_xml_node_rid_table_tp ). + value = lc_xml_node_rid_table_tp ). lv_value = lo_table->get_name( ). CONCATENATE '../tables/' lv_value '.xml' INTO lv_value. @@ -3272,6 +3487,30 @@ endmethod. 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( ). @@ -3281,9 +3520,9 @@ endmethod. endmethod. - - - METHOD create_xl_styles. + + + method CREATE_XL_STYLES. ** Constant node name @@ -3481,8 +3720,6 @@ endmethod. ls_protection = lo_style->protection->get_structure( ). ls_numfmt = lo_style->number_format->get_structure( ). - - CLEAR ls_cellxfs. @@ -3592,8 +3829,6 @@ endmethod. ls_cellxfs-applyborder = 0. ENDIF. - - * Remap styles READ TABLE lt_cellxfs FROM ls_cellxfs TRANSPORTING NO FIELDS. IF sy-subrc EQ 0. @@ -4203,13 +4438,13 @@ endmethod. lo_renderer = lo_ixml->create_renderer( ostream = lo_ostream document = lo_document ). lo_renderer->render( ). -ENDMETHOD. +endmethod. - - - - - + + + + + method CREATE_XL_STYLES_COLOR_NODE. DATA: lo_sub_element TYPE REF TO if_ixml_element, lv_value TYPE string. @@ -4256,9 +4491,9 @@ ENDMETHOD. io_parent->append_child( new_child = lo_sub_element ). endmethod. - - - + + + method CREATE_XL_TABLE. DATA: lc_xml_node_table TYPE string VALUE 'table', @@ -4427,8 +4662,8 @@ endmethod. endmethod. - - + + method CREATE_XL_THEME. @@ -4516,9 +4751,9 @@ endmethod. endmethod. - - - METHOD create_xl_workbook. + + + method CREATE_XL_WORKBOOK. ** Constant node name DATA: lc_xml_node_workbook TYPE string VALUE 'workbook', @@ -4780,11 +5015,11 @@ endmethod. lo_renderer = lo_ixml->create_renderer( ostream = lo_ostream document = lo_document ). lo_renderer->render( ). -ENDMETHOD. +endmethod. - - - + + + method FLAG2BOOL. @@ -4795,9 +5030,9 @@ ENDMETHOD. ENDIF. endmethod. - - - + + + method GET_SHARED_STRING_INDEX. diff --git a/ZA2X/DOMA/ZEXCEL_DRAWING_ANCHOR.slnk b/ZA2X/DOMA/ZEXCEL_DRAWING_ANCHOR.slnk new file mode 100644 index 0000000..a7cd972 --- /dev/null +++ b/ZA2X/DOMA/ZEXCEL_DRAWING_ANCHOR.slnk @@ -0,0 +1,6 @@ + + + + + + diff --git a/ZA2X/DOMA/ZEXCEL_DRAWING_TYPE.slnk b/ZA2X/DOMA/ZEXCEL_DRAWING_TYPE.slnk new file mode 100644 index 0000000..e5e0b13 --- /dev/null +++ b/ZA2X/DOMA/ZEXCEL_DRAWING_TYPE.slnk @@ -0,0 +1,5 @@ + + + + + diff --git a/ZA2X/DTEL/ZEXCEL_DRAWING_ANCHOR.slnk b/ZA2X/DTEL/ZEXCEL_DRAWING_ANCHOR.slnk new file mode 100644 index 0000000..dfef22c --- /dev/null +++ b/ZA2X/DTEL/ZEXCEL_DRAWING_ANCHOR.slnk @@ -0,0 +1,4 @@ + + + + diff --git a/ZA2X/DTEL/ZEXCEL_DRAWING_TYPE.slnk b/ZA2X/DTEL/ZEXCEL_DRAWING_TYPE.slnk new file mode 100644 index 0000000..6cab8b0 --- /dev/null +++ b/ZA2X/DTEL/ZEXCEL_DRAWING_TYPE.slnk @@ -0,0 +1,4 @@ + + + + diff --git a/ZA2X/TABL/ZEXCEL_DRAWING_LOCATION.slnk b/ZA2X/TABL/ZEXCEL_DRAWING_LOCATION.slnk new file mode 100644 index 0000000..14a75b3 --- /dev/null +++ b/ZA2X/TABL/ZEXCEL_DRAWING_LOCATION.slnk @@ -0,0 +1,8 @@ + + + + + + + +