From 8e2fee33891ee7ce19a2f90cbe384db4fe8f1c57 Mon Sep 17 00:00:00 2001 From: Rene Turnheim Date: Thu, 9 Feb 2012 12:20:48 +0000 Subject: [PATCH] New method get_value_type created and it will get executed in set_cell, if ip_abap_type is not supplied. git-svn-id: https://subversion.assembla.com/svn/abap2xlsx/trunk@255 b7d68dce-7c3c-4a99-8ce0-9ea847f5d049 --- ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk | 468 ++++++++++++++++------------- 1 file changed, 267 insertions(+), 201 deletions(-) diff --git a/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk b/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk index 6fbb088..20e380c 100644 --- a/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk +++ b/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk @@ -1,23 +1,19 @@ - - - - + + + + class ZCL_EXCEL_WORKSHEET definition public final create public . -public section. *"* public components of class ZCL_EXCEL_WORKSHEET *"* do not include other source files here!!! +public section. type-pools ABAP . - interfaces ZIF_EXCEL_SHEET_PROPERTIES - data values ZOOMSCALE = 100 - ZOOMSCALE_NORMAL = 100 - ZOOMSCALE_PAGELAYOUTVIEW = 100 - ZOOMSCALE_SHEETLAYOUTVIEW = 100 . + interfaces ZIF_EXCEL_SHEET_PROPERTIES . interfaces ZIF_EXCEL_SHEET_PROTECTION . interfaces ZIF_EXCEL_SHEET_VBA_PROJECT . @@ -193,7 +189,9 @@ public section. !IP_STYLE type ZEXCEL_CELL_STYLE optional !IP_HYPERLINK type ref to ZCL_EXCEL_HYPERLINK optional !IP_DATA_TYPE type ZEXCEL_CELL_DATA_TYPE optional - !IP_ABAP_TYPE type ABAP_TYPEKIND optional . + !IP_ABAP_TYPE type ABAP_TYPEKIND optional + raising + ZCX_EXCEL . methods SET_CELL_STYLE importing !IP_COLUMN type ZEXCEL_CELL_COLUMN_ALPHA @@ -233,9 +231,9 @@ public section. *"* protected components of class ZCL_EXCEL_WORKSHEET *"* do not include other source files here!!! protected section. - private section. -*"* private components of class ZCL_EXCEL_WORKSHEET + *"* private components of class ZCL_EXCEL_WORKSHEET *"* do not include other source files here!!! +private section. data ACTIVE_CELL type ZEXCEL_S_CELL_DATA . data COLUMN_DIMENSIONS type ZEXCEL_T_WORKSHEET_COLUMNDIME . @@ -256,6 +254,12 @@ protected section. data TITLE type ZEXCEL_SHEET_TITLE value 'Worksheet'. "#EC NOTEXT . data UPPER_CELL type ZEXCEL_S_CELL_DATA . + methods GET_VALUE_TYPE + importing + !IP_VALUE type SIMPLE + exporting + !EP_VALUE type SIMPLE + !EP_VALUE_TYPE type ABAP_TYPEKIND . methods UPDATE_DIMENSION_RANGE . *"* local class implementation for public class *"* use this source file for the implementation part of @@ -417,38 +421,38 @@ endclass. ABAP SLIS SOI - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + method ZIF_EXCEL_SHEET_PROPERTIES~GET_STYLE. ep_style = zif_excel_sheet_properties~style. @@ -502,35 +506,35 @@ endmethod. me->zif_excel_sheet_vba_project~codename_pr = ip_codename_pr. endmethod. - - + + method ADD_DRAWING. drawings->add( ip_drawing ). 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. @@ -553,26 +557,26 @@ endmethod. endmethod. - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + method BIND_ALV_OLE2. *--------------------------------------------------------------------* * Method description: @@ -2142,8 +2146,8 @@ endmethod. set country space. * Hier wird nur die korrekte Kommaseparatierung gemacht, wenn die * Zeichen einer -* Zahl enthalten sind. Das ist für Timestamps, die auch ":" enthalten. -* Für die +* Zahl enthalten sind. Das ist für Timestamps, die auch ":" enthalten. +* Für die * darf keine Kommaseparierung stattfinden. * Changing for correction request - Y6BK041073 if contentsitem-value co '0123456789.,-+E '. @@ -2642,11 +2646,11 @@ endmethod. close_document. endmethod. - - - - - + + + + + method BIND_TABLE. DATA: @@ -2816,7 +2820,7 @@ endmethod. endmethod. - + method CALCULATE_COLUMN_WIDTHS. TYPES: BEGIN OF t_auto_size, @@ -2870,7 +2874,7 @@ endmethod. ). " For an easy start we just take the number of characters as the width width = strlen( cell_value ). - " Addition to solve issue #120, contribution by Stefan Schmöcker + " Addition to solve issue #120, contribution by Stefan Schmöcker " Calculate width using Font Size and Font Type IF cell_style IS BOUND AND cell_style->font IS BOUND. @@ -2888,9 +2892,9 @@ endmethod. endmethod. - - - + + + method CONSTRUCTOR. DATA: lv_title TYPE zexcel_sheet_title. @@ -2930,7 +2934,7 @@ endmethod. upper_cell-cell_column = 1. endmethod. - + method DELETE_MERGE. DELETE sheet_content_merge INDEX 1. @@ -2938,10 +2942,10 @@ endmethod. endmethod. - - - - + + + + method FREEZE_PANES. data: lv_xsplit type i, lv_ysplit type i. @@ -2968,8 +2972,8 @@ endmethod. freeze_pane_cell_row = ip_num_rows + 1. endmethod. - - + + method GET_ACTIVE_CELL. DATA: lv_active_column TYPE zexcel_cell_column_alpha, @@ -2983,12 +2987,12 @@ endmethod. endmethod. - - - - - - + + + + + + method GET_CELL. DATA: lv_column TYPE zexcel_cell_column, @@ -3004,7 +3008,7 @@ endmethod. ep_rc = sy-subrc. ep_value = ls_sheet_content-cell_value. - " Addition to solve issue #120, contribution by Stefan Schmöcker + " Addition to solve issue #120, contribution by Stefan Schmöcker DATA: style_iterator TYPE REF TO cl_object_collection_iterator, style TYPE REF TO zcl_excel_style. IF ep_style IS REQUESTED. @@ -3019,9 +3023,9 @@ endmethod. ENDIF. endmethod. - - - + + + method GET_COLUMN_DIMENSION. FIELD-SYMBOLS: <fs_column_dimension> LIKE LINE OF column_dimensions. @@ -3041,40 +3045,40 @@ 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. r_column_dimension = me->default_column_dimension. endmethod. - - + + method GET_DEFAULT_EXCEL_DATE_FORMAT. CONSTANTS: c_lang_e TYPE lang VALUE 'E'. @@ -3099,14 +3103,14 @@ endmethod. ep_default_excel_date_format = default_excel_date_format. endmethod. - - + + method GET_DEFAULT_ROW_DIMENSION. r_row_dimension = me->default_row_dimension. endmethod. - - + + method GET_DIMENSION_RANGE. me->update_dimension_range( ). @@ -3123,62 +3127,62 @@ endmethod. endmethod. - - + + method GET_DRAWINGS. r_drawings = drawings. endmethod. - - + + method GET_DRAWINGS_ITERATOR. eo_iterator = drawings->get_iterator( ). 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. DATA: lv_column_start TYPE string, @@ -3252,9 +3256,9 @@ endmethod. endmethod. - - - + + + method GET_ROW_DIMENSION. FIELD-SYMBOLS: <fs_row_dimension> LIKE LINE OF row_dimensions. @@ -3274,27 +3278,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. @@ -3305,16 +3309,66 @@ endmethod. ENDIF. endmethod. - - - - - - - - - - method SET_CELL. + + + + + method GET_VALUE_TYPE. + DATA: lo_addit TYPE REF TO cl_abap_elemdescr, + ls_dfies TYPE dfies, + l_function TYPE funcname. + + ep_value = ip_value. + ep_value_type = cl_abap_typedescr=>typekind_string. " Thats our default if something goes wrong. + + TRY. + lo_addit ?= cl_abap_typedescr=>describe_by_data( ip_value ). + CATCH cx_sy_move_cast_error. + CLEAR lo_addit. + ENDTRY. + IF lo_addit IS BOUND. + ls_dfies = lo_addit->get_ddic_field( ) . + + ep_value_type = ls_dfies-inttype. + + IF ls_dfies-convexit IS NOT INITIAL. +* We need to convert with output conversion function + CONCATENATE 'CONVERSION_EXIT_' ls_dfies-convexit '_OUTPUT' INTO l_function. + SELECT SINGLE funcname INTO l_function + FROM tfdir + WHERE funcname = l_function. + IF sy-subrc = 0. + CALL FUNCTION l_function + EXPORTING + input = ip_value + IMPORTING +* LONG_TEXT = + output = ep_value +* SHORT_TEXT = + EXCEPTIONS + OTHERS = 1 + . + IF sy-subrc <> 0. +* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO +* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. + ENDIF. + ENDIF. + ENDIF. + ENDIF. + +endmethod. + + + + + + + + + + + + METHOD set_cell. DATA: lv_column TYPE zexcel_cell_column, ls_sheet_content TYPE zexcel_s_cell_data, @@ -3323,9 +3377,11 @@ endmethod. lv_data_type TYPE zexcel_cell_data_type, lv_value_type TYPE abap_typekind, lo_style TYPE REF TO zcl_excel_style, - lv_style_guid TYPE zexcel_cell_style. + lv_style_guid TYPE zexcel_cell_style, + lo_value TYPE REF TO data. - FIELD-SYMBOLS: <fs_sheet_content> TYPE zexcel_s_cell_data. + FIELD-SYMBOLS: <fs_sheet_content> TYPE zexcel_s_cell_data, + <fs_value> TYPE simple. IF ip_value IS NOT SUPPLIED AND ip_formula IS NOT SUPPLIED. RAISE EXCEPTION TYPE zcx_excel @@ -3338,26 +3394,36 @@ endmethod. IF ip_value IS SUPPLIED. "if data type is passed just write the value. Otherwise map abap type to excel and perform conversion "IP_DATA_TYPE is passed by excel reader so source types are preserved +*First we get reference into local var. + CREATE DATA lo_value LIKE ip_value. + ASSIGN lo_value->* TO <fs_value>. + <fs_value> = ip_value. IF ip_data_type IS SUPPLIED. - lv_value = ip_value. + IF ip_abap_type IS NOT SUPPLIED. + get_value_type( EXPORTING ip_value = ip_value + IMPORTING ep_value = <fs_value> ). + endif. + lv_value = <fs_value>. lv_data_type = ip_data_type. ELSE. IF ip_abap_type IS SUPPLIED. lv_value_type = ip_abap_type. ELSE. - DESCRIBE FIELD ip_value TYPE lv_value_type. + get_value_type( EXPORTING ip_value = ip_value + IMPORTING ep_value = <fs_value> + ep_value_type = lv_value_type ). ENDIF. CASE lv_value_type. WHEN cl_abap_typedescr=>typekind_int OR cl_abap_typedescr=>typekind_int1 OR cl_abap_typedescr=>typekind_int2 OR cl_abap_typedescr=>typekind_float OR cl_abap_typedescr=>typekind_packed. - lv_value = zcl_excel_common=>number_to_excel_string( ip_value = ip_value ). + lv_value = zcl_excel_common=>number_to_excel_string( ip_value = <fs_value> ). WHEN cl_abap_typedescr=>typekind_char OR cl_abap_typedescr=>typekind_string OR cl_abap_typedescr=>typekind_num. - lv_value = ip_value. + lv_value = <fs_value>. lv_data_type = 's'. WHEN cl_abap_typedescr=>typekind_date. - lv_value = zcl_excel_common=>date_to_excel_string( ip_value = ip_value ). + lv_value = zcl_excel_common=>date_to_excel_string( ip_value = <fs_value> ). IF ip_style IS NOT SUPPLIED. "get default date format in case parameter is initial lo_style = excel->add_new_style( ). @@ -3366,7 +3432,7 @@ endmethod. ENDIF. WHEN cl_abap_typedescr=>typekind_time. - lv_value = zcl_excel_common=>time_to_excel_string( ip_value = ip_value ). + lv_value = zcl_excel_common=>time_to_excel_string( ip_value = <fs_value> ). IF ip_style IS NOT SUPPLIED. "get default time format for user in case parameter is initial lo_style = excel->add_new_style( ). @@ -3417,13 +3483,13 @@ endmethod. ENDIF. -endmethod. +ENDMETHOD. - - - - - + + + + + method SET_CELL_STYLE. DATA: lv_column TYPE zexcel_cell_column, @@ -3449,8 +3515,8 @@ endmethod. endmethod. - - + + method SET_DEFAULT_EXCEL_DATE_FORMAT. IF ip_default_excel_date_format IS INITIAL. @@ -3462,11 +3528,11 @@ endmethod. default_excel_date_format = ip_default_excel_date_format. endmethod. - - - - - + + + + + method SET_MERGE. DATA: lv_column_start TYPE zexcel_cell_column, @@ -3503,31 +3569,31 @@ endmethod. endmethod. - - + + method SET_PRINT_GRIDLINES. me->print_gridlines = i_print_gridlines. 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. DATA: lo_tabdescr TYPE REF TO cl_abap_structdescr, @@ -3584,13 +3650,13 @@ endmethod. endmethod. - - + + method SET_TITLE. me->title = ip_title. endmethod. - + method UPDATE_DIMENSION_RANGE. DATA: ls_sheet_content TYPE zexcel_s_cell_data,