class ZCL_EXCEL_TABLE definition public final create public . *"* public components of class ZCL_EXCEL_TABLE *"* do not include other source files here!!! public section. type-pools ABAP . constants BUILTINSTYLE_DARK1 type ZEXCEL_TABLE_STYLE value 'TableStyleDark1'. "#EC NOTEXT constants BUILTINSTYLE_DARK2 type ZEXCEL_TABLE_STYLE value 'TableStyleDark2'. "#EC NOTEXT constants BUILTINSTYLE_DARK3 type ZEXCEL_TABLE_STYLE value 'TableStyleDark3'. "#EC NOTEXT constants BUILTINSTYLE_DARK4 type ZEXCEL_TABLE_STYLE value 'TableStyleDark4'. "#EC NOTEXT constants BUILTINSTYLE_DARK5 type ZEXCEL_TABLE_STYLE value 'TableStyleDark5'. "#EC NOTEXT constants BUILTINSTYLE_LIGHT1 type ZEXCEL_TABLE_STYLE value 'TableStyleLight1'. "#EC NOTEXT constants BUILTINSTYLE_LIGHT2 type ZEXCEL_TABLE_STYLE value 'TableStyleLight2'. "#EC NOTEXT constants BUILTINSTYLE_LIGHT3 type ZEXCEL_TABLE_STYLE value 'TableStyleLight3'. "#EC NOTEXT constants BUILTINSTYLE_LIGHT4 type ZEXCEL_TABLE_STYLE value 'TableStyleLight4'. "#EC NOTEXT constants BUILTINSTYLE_LIGHT5 type ZEXCEL_TABLE_STYLE value 'TableStyleLight5'. "#EC NOTEXT constants BUILTINSTYLE_MEDIUM1 type ZEXCEL_TABLE_STYLE value 'TableStyleMedium1'. "#EC NOTEXT constants BUILTINSTYLE_MEDIUM2 type ZEXCEL_TABLE_STYLE value 'TableStyleMedium2'. "#EC NOTEXT constants BUILTINSTYLE_MEDIUM3 type ZEXCEL_TABLE_STYLE value 'TableStyleMedium3'. "#EC NOTEXT constants BUILTINSTYLE_MEDIUM4 type ZEXCEL_TABLE_STYLE value 'TableStyleMedium4'. "#EC NOTEXT constants BUILTINSTYLE_MEDIUM5 type ZEXCEL_TABLE_STYLE value 'TableStyleMedium5'. "#EC NOTEXT constants BUILTINSTYLE_MEDIUM9 type ZEXCEL_TABLE_STYLE value 'TableStyleMedium9'. "#EC NOTEXT constants BUILTINSTYLE_PIVOT_LIGHT16 type ZEXCEL_TABLE_STYLE value 'PivotStyleLight16'. "#EC NOTEXT data FIELDCAT type ZEXCEL_T_FIELDCATALOG . data SETTINGS type ZEXCEL_S_TABLE_SETTINGS . constants TOTALS_FUNCTION_AVERAGE type ZEXCEL_TABLE_TOTALS_FUNCTION value 'average'. "#EC NOTEXT constants TOTALS_FUNCTION_COUNT type ZEXCEL_TABLE_TOTALS_FUNCTION value 'count'. "#EC NOTEXT constants TOTALS_FUNCTION_MAX type ZEXCEL_TABLE_TOTALS_FUNCTION value 'max'. "#EC NOTEXT constants TOTALS_FUNCTION_MIN type ZEXCEL_TABLE_TOTALS_FUNCTION value 'min'. "#EC NOTEXT constants TOTALS_FUNCTION_SUM type ZEXCEL_TABLE_TOTALS_FUNCTION value 'sum'. "#EC NOTEXT methods GET_TOTALS_FORMULA importing !IP_COLUMN type CLIKE !IP_FUNCTION type ZEXCEL_TABLE_TOTALS_FUNCTION returning value(EP_FORMULA) type STRING . methods HAS_TOTALS returning value(EP_RESULT) type ABAP_BOOL . methods SET_DATA importing !IR_DATA type STANDARD TABLE . methods GET_ID returning value(OV_ID) type I . methods SET_ID importing !IV_ID type I . methods CONSTRUCTOR . methods GET_NAME returning value(OV_NAME) type STRING . methods GET_REFERENCE importing !IP_INCLUDE_TOTALS_ROW type ABAP_BOOL default ABAP_TRUE returning value(OV_REFERENCE) type STRING . *"* protected components of class ZCL_EXCEL_TABLE *"* do not include other source files here!!! protected section. *"* private components of class ZCL_EXCEL_TABLE *"* do not include other source files here!!! private section. data ID type I . data NAME type STRING . data TABLE_DATA type ref to DATA . *"* local class implementation for public class *"* use this source file for the implementation part of *"* local helper classes *"* use this source file for any type declarations (class *"* definitions, interfaces or data types) you need for method *"* implementation or private method's signature *"* use this source file for any macro definitions you need *"* in the implementation part of the class ABAP method CONSTRUCTOR. endmethod. method GET_ID. ov_id = id. endmethod. method GET_NAME. IF me->name IS INITIAL. me->name = zcl_excel_common=>number_to_excel_string( ip_value = me->id ). CONCATENATE 'table' me->name INTO me->name. ENDIF. ov_name = me->name. endmethod. method GET_REFERENCE. DATA: lv_column TYPE zexcel_cell_column, lv_table_lines TYPE i, lv_right_column TYPE zexcel_cell_column_alpha, ls_field_catalog TYPE zexcel_s_fieldcatalog, lv_bottom_row TYPE zexcel_cell_row, lv_top_row_string(10) TYPE c, lv_bottom_row_string(10) TYPE c. FIELD-SYMBOLS: <fs_table> TYPE STANDARD TABLE. *column lv_column = zcl_excel_common=>convert_column2int( settings-top_left_column ). lv_table_lines = 0. LOOP AT fieldcat INTO ls_field_catalog WHERE dynpfld EQ abap_true. ADD 1 TO lv_table_lines. ENDLOOP. lv_column = lv_column + lv_table_lines - 1. lv_right_column = zcl_excel_common=>convert_column2alpha( lv_column ). *row ASSIGN table_data->* TO <fs_table>. DESCRIBE TABLE <fs_table> LINES lv_table_lines. lv_bottom_row = settings-top_left_row + lv_table_lines . IF me->has_totals( ) = abap_true AND ip_include_totals_row = abap_true. add 1 to lv_bottom_row. ENDIF. WRITE settings-top_left_row TO lv_top_row_string. CONDENSE lv_top_row_string. WRITE lv_bottom_row TO lv_bottom_row_string. CONDENSE lv_bottom_row_string. CONCATENATE settings-top_left_column lv_top_row_string ':' lv_right_column lv_bottom_row_string INTO ov_reference. endmethod. method GET_TOTALS_FORMULA. CONSTANTS: lc_function_id_sum TYPE string VALUE '109', lc_function_id_min TYPE string VALUE '105', lc_function_id_max TYPE string VALUE '104', lc_function_id_count TYPE string VALUE '103', lc_function_id_average TYPE string VALUE '101'. DATA: lv_function_id TYPE string. CASE ip_function. WHEN zcl_excel_table=>totals_function_sum. lv_function_id = lc_function_id_sum. WHEN zcl_excel_table=>totals_function_min. lv_function_id = lc_function_id_min. WHEN zcl_excel_table=>totals_function_max. lv_function_id = lc_function_id_max. WHEN zcl_excel_table=>totals_function_count. lv_function_id = lc_function_id_count. WHEN zcl_excel_table=>totals_function_average. lv_function_id = lc_function_id_average. WHEN OTHERS. RAISE EXCEPTION TYPE zcx_excel EXPORTING error = 'Invalid totals formula. See ZCL_ for possible values'. ENDCASE. CONCATENATE 'SUBTOTAL(' lv_function_id ',[' ip_column '])' INTO ep_formula. endmethod. method HAS_TOTALS. DATA: ls_field_catalog TYPE zexcel_s_fieldcatalog. ep_result = abap_false. LOOP AT fieldcat INTO ls_field_catalog. IF ls_field_catalog-totals_function IS NOT INITIAL. ep_result = abap_true. EXIT. ENDIF. ENDLOOP. endmethod. method SET_DATA. GET REFERENCE OF ir_data INTO me->table_data. endmethod. method SET_ID. id = iv_id. endmethod.