class ZCL_EXCEL_COMMON definition public final create public . *"* public components of class ZCL_EXCEL_COMMON *"* do not include other source files here!!! public section. class-data C_EXCEL_NUMFMT_OFFSET type INT1 value 164. "#EC NOTEXT . class-data C_SPRAS_EN type SPRAS value 'EN'. "#EC NOTEXT . class-methods GET_FIELDCATALOG importing !IP_TABLE type STANDARD TABLE returning value(EP_FIELDCATALOG) type ZEXCEL_T_FIELDCATALOG . class-methods CONVERT_COLUMN2ALPHA importing !IP_COLUMN type ZEXCEL_CELL_COLUMN returning value(EP_COLUMN) type ZEXCEL_CELL_COLUMN_ALPHA . class-methods CONVERT_COLUMN2INT importing !IP_COLUMN type ZEXCEL_CELL_COLUMN_ALPHA returning value(EP_COLUMN) type ZEXCEL_CELL_COLUMN . class-methods NUMBER_TO_EXCEL_STRING importing value(IP_VALUE) type NUMERIC returning value(EP_VALUE) type ZEXCEL_CELL_VALUE . class-methods DATE_TO_EXCEL_STRING importing !IP_VALUE type D returning value(EP_VALUE) type ZEXCEL_CELL_VALUE . class-methods TIME_TO_EXCEL_STRING importing !IP_VALUE type T returning value(EP_VALUE) type ZEXCEL_CELL_VALUE . *"* protected components of class ZCL_EXCEL_COMMON *"* do not include other source files here!!! protected section. *"* private components of class ZCL_EXCEL_COMMON *"* do not include other source files here!!! private section. class-data C_EXCEL_COL_MODULE type INT2 value 64. "#EC NOTEXT . *"* local class implementation for public class *"* use this source file for the implementation part of *"* local helper classes *"* use this source file for any type declarations (class *"* definitions, interfaces or data types) you need for method *"* implementation or private method's signature *"* use this source file for any macro definitions you need *"* in the implementation part of the class method CONVERT_COLUMN2ALPHA. DATA: lo_conv TYPE REF TO cl_abap_conv_in_ce, lv_uccpi TYPE i, lv_text TYPE sychar02, lv_module TYPE int4, lv_column TYPE zexcel_cell_column. lv_column = ip_column. WHILE lv_column GT 0. lv_module = ( lv_column - 1 ) MOD 26. lv_uccpi = 65 + lv_module. lv_column = ( lv_column - lv_module ) / 26. lv_text = cl_abap_conv_in_ce=>uccpi( lv_uccpi ). CONCATENATE lv_text ep_column INTO ep_column. ENDWHILE. endmethod. method CONVERT_COLUMN2INT. DATA: lv_uccpi TYPE i, lv_char TYPE c, lv_column(2) TYPE c. * Calculate most significant letter lv_char = ip_column+1(1). IF lv_char IS NOT INITIAL. "To avoid the first 26 column that have only a char in first position ep_column = cl_abap_conv_out_ce=>uccpi( lv_char ). ep_column = ep_column MOD ( zcl_excel_common=>c_excel_col_module ). lv_char = ip_column(1). lv_uccpi = cl_abap_conv_out_ce=>uccpi( lv_char ). lv_uccpi = ( lv_uccpi MOD ( zcl_excel_common=>c_excel_col_module ) ) * 26. ep_column = ep_column + lv_uccpi. ELSE. lv_char = ip_column(1). ep_column = cl_abap_conv_out_ce=>uccpi( lv_char ). ep_column = ep_column - zcl_excel_common=>c_excel_col_module. ENDIF. endmethod. method DATE_TO_EXCEL_STRING. DATA: lv_date_diff TYPE i, lc_date_baseline TYPE d VALUE '19000101'. lv_date_diff = ip_value - lc_date_baseline + 2. ep_value = zcl_excel_common=>number_to_excel_string( ip_value = lv_date_diff ). endmethod. method GET_FIELDCATALOG. DATA: lr_data TYPE REF TO data, lo_tabdescr TYPE REF TO cl_abap_structdescr, ls_header TYPE x030l, lt_dfies TYPE ddfields, ls_dfies TYPE dfies, ls_fieldcatalog TYPE zexcel_s_fieldcatalog. CREATE DATA lr_data LIKE LINE OF ip_table. lo_tabdescr ?= cl_abap_structdescr=>describe_by_data_ref( lr_data ). ls_header = lo_tabdescr->get_ddic_header( ). lt_dfies = lo_tabdescr->get_ddic_field_list( ). LOOP AT lt_dfies INTO ls_dfies. MOVE-CORRESPONDING ls_dfies TO ls_fieldcatalog. APPEND ls_fieldcatalog TO ep_fieldcatalog. ENDLOOP. endmethod. method NUMBER_TO_EXCEL_STRING. DATA: lv_value_c TYPE c LENGTH 100. WRITE ip_value TO lv_value_c EXPONENT 0 NO-GROUPING NO-SIGN. REPLACE ALL OCCURRENCES OF ',' IN lv_value_c WITH '.'. ep_value = lv_value_c. CONDENSE ep_value. IF ip_value < 0. CONCATENATE '-' ep_value INTO ep_value. ENDIF. endmethod. method TIME_TO_EXCEL_STRING. DATA: lv_seconds_in_day TYPE i, lv_day_fraction TYPE f, lc_time_baseline TYPE t VALUE '000000', lc_seconds_in_day TYPE i VALUE 86400. lv_seconds_in_day = ip_value - lc_time_baseline. lv_day_fraction = lv_seconds_in_day / lc_seconds_in_day. ep_value = zcl_excel_common=>number_to_excel_string( ip_value = lv_day_fraction ). endmethod.