From d8b2efe17def1dff6172f027a77c138298678ef8 Mon Sep 17 00:00:00 2001 From: Ivan Femia Date: Thu, 11 Nov 2010 22:16:57 +0000 Subject: [PATCH] Missing object git-svn-id: https://subversion.assembla.com/svn/abap2xlsx/trunk@44 b7d68dce-7c3c-4a99-8ce0-9ea847f5d049 --- ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk | 331 +++++++++++++++++------------ 1 file changed, 197 insertions(+), 134 deletions(-) diff --git a/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk b/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk index fa630e4..1c30020 100644 --- a/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk +++ b/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk @@ -1,6 +1,6 @@ - - + + class ZCL_EXCEL_WORKSHEET definition public final @@ -39,6 +39,7 @@ public section. !IP_TABLE type STANDARD TABLE !IT_FIELD_CATALOG type ZEXCEL_T_FIELDCATALOG optional !IS_TABLE_SETTINGS type ZEXCEL_S_TABLE_SETTINGS optional . + methods CALCULATE_COLUMN_WIDTHS . methods CONSTRUCTOR importing !IP_EXCEL type ref to ZCL_EXCEL @@ -105,6 +106,12 @@ public section. methods GET_HIGHEST_ROW returning value(R_HIGHEST_ROW) type INT4 . + methods GET_HYPERLINKS_ITERATOR + returning + value(EO_ITERATOR) type ref to CL_OBJECT_COLLECTION_ITERATOR . + methods GET_HYPERLINKS_SIZE + returning + value(EP_SIZE) type I . methods GET_MERGE returning value(MERGE_RANGE) type STRING_TABLE . @@ -149,13 +156,7 @@ public section. !IP_BODY_STYLE type ZEXCEL_CELL_STYLE optional !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 . - methods GET_HYPERLINKS_SIZE - returning - value(EP_SIZE) type I . - methods GET_HYPERLINKS_ITERATOR - returning - value(EO_ITERATOR) type ref to CL_OBJECT_COLLECTION_ITERATOR . + !IP_TOP_LEFT_ROW type ZEXCEL_CELL_ROW default 3 . *"* protected components of class ZCL_EXCEL_WORKSHEET *"* do not include other source files here!!! protected section. @@ -191,35 +192,35 @@ private section. *"* in the implementation part of the class ABAP - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + - METHOD zif_excel_sheet_protection~initialize. + method ZIF_EXCEL_SHEET_PROTECTION~INITIALIZE. me->zif_excel_sheet_protection~protected = zif_excel_sheet_protection=>c_unprotected. CLEAR me->zif_excel_sheet_protection~password. @@ -242,34 +243,34 @@ private section. me->zif_excel_sheet_protection~sheet = zif_excel_sheet_protection=>c_noactive. me->zif_excel_sheet_protection~sort = zif_excel_sheet_protection=>c_noactive. -ENDMETHOD. +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_TABLE. DATA: @@ -392,9 +393,71 @@ endmethod. endmethod. - - - + + method CALCULATE_COLUMN_WIDTHS. + TYPES: + BEGIN OF t_auto_size, + col_index TYPE int4, + width TYPE float, + END OF t_auto_size. + TYPES: tt_auto_size TYPE TABLE OF t_auto_size. + + DATA: column_dimensions TYPE zexcel_t_worksheet_columndime. + DATA: column_dimension TYPE REF TO zcl_excel_worksheet_columndime. + + DATA: auto_size TYPE flag. + DATA: auto_sizes TYPE tt_auto_size. + DATA: col_alpha TYPE zexcel_cell_column_alpha. + DATA: cell_value TYPE zexcel_cell_value. + DATA: count TYPE int4. + DATA: highest_row TYPE int4. + DATA: width TYPE i. + + FIELD-SYMBOLS: <column_dimension> LIKE LINE OF column_dimensions. + FIELD-SYMBOLS: <auto_size> LIKE LINE OF auto_sizes. + + column_dimensions[] = me->get_column_dimensions( ). + LOOP AT column_dimensions ASSIGNING <column_dimension>. + auto_size = <column_dimension>-column_dimension->get_auto_size( ). + IF auto_size = abap_true. + APPEND INITIAL LINE TO auto_sizes ASSIGNING <auto_size>. + <auto_size>-col_index = <column_dimension>-column_dimension->get_column_index( ). + <auto_size>-width = -1. + ENDIF. + ENDLOOP. + + " There is only something to do if there are some auto-size columns + IF NOT auto_sizes IS INITIAL. + highest_row = me->get_highest_row( ). + LOOP AT auto_sizes ASSIGNING <auto_size>. + col_alpha = zcl_excel_common=>convert_column2alpha( <auto_size>-col_index ). + count = 1. + WHILE count <= highest_row. + me->get_cell( + EXPORTING + ip_column = col_alpha " Cell Column + ip_row = count " Cell Row + IMPORTING + ep_value = cell_value " Cell Value + ). + " For an easy start we just take the number of characters as the width + " TODO: Calculate width using Font Size and Font Type + width = STRLEN( cell_value ). + IF width > <auto_size>-width. + <auto_size>-width = width. + ENDIF. + count = count + 1. + ENDWHILE. + column_dimension = me->get_column_dimension( col_alpha ). + column_dimension->set_width( <auto_size>-width ). + ENDLOOP. + ENDIF. + +endmethod. + + + + method CONSTRUCTOR. me->excel = ip_excel. @@ -430,7 +493,7 @@ endmethod. upper_cell-cell_column = 1. endmethod. - + method DELETE_MERGE. DELETE sheet_content_merge INDEX 1. @@ -438,10 +501,10 @@ endmethod. endmethod. - - - - + + + + method FREEZE_PANES. data: lv_xsplit type i, lv_ysplit type i. @@ -468,8 +531,8 @@ endmethod. freeze_pane_cell_row = ip_num_rows + 1. endmethod. - - + + method GET_ACTIVE_CELL. DATA: lv_active_column TYPE zexcel_cell_column_alpha, @@ -483,11 +546,11 @@ endmethod. endmethod. - - - - - + + + + + method GET_CELL. DATA: lv_column TYPE zexcel_cell_column, @@ -504,9 +567,9 @@ endmethod. ep_value = ls_sheet_content-cell_value. endmethod. - - - + + + method GET_COLUMN_DIMENSION. FIELD-SYMBOLS: <fs_column_dimension> LIKE LINE OF column_dimensions. @@ -526,46 +589,46 @@ 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_ROW_DIMENSION. r_row_dimension = me->default_row_dimension. endmethod. - - + + method GET_DIMENSION_RANGE. me->update_dimension_range( ). @@ -577,62 +640,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, @@ -703,9 +766,9 @@ endmethod. endmethod. - - - + + + method GET_ROW_DIMENSION. FIELD-SYMBOLS: <fs_row_dimension> LIKE LINE OF row_dimensions. @@ -725,32 +788,32 @@ 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 set_cell. + + + + + + + + method SET_CELL. DATA: lv_column TYPE zexcel_cell_column, ls_sheet_content TYPE zexcel_s_cell_data, @@ -841,13 +904,13 @@ endmethod. ENDIF. -ENDMETHOD. +endmethod. - - - - - + + + + + method SET_CELL_STYLE. DATA: lv_column TYPE zexcel_cell_column, @@ -875,10 +938,10 @@ ENDMETHOD. endmethod. - - - - + + + + method SET_MERGE. DATA: lv_column_start TYPE zexcel_cell_column, @@ -909,13 +972,13 @@ endmethod. endmethod. - - - - - - - + + + + + + + method SET_TABLE. DATA: lo_tabdescr TYPE REF TO cl_abap_structdescr, @@ -972,7 +1035,7 @@ endmethod. endmethod. - + method UPDATE_DIMENSION_RANGE. DATA: ls_sheet_content TYPE zexcel_s_cell_data,