Update zcl_excel_converter.clas.abap

This commit is contained in:
Bernd 2024-11-18 13:44:19 +01:00 committed by GitHub
parent bae673121b
commit 16fac218f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -133,12 +133,14 @@ CLASS zcl_excel_converter DEFINITION
RAISING RAISING
zcx_excel . zcx_excel .
METHODS clean_fieldcatalog . METHODS clean_fieldcatalog .
METHODS create_color_style methods COMPLETE_CELL
IMPORTING importing
!i_style TYPE zexcel_cell_style !IP_TABLE_ROW type ZEXCEL_CELL_ROW
!is_colors TYPE zexcel_s_converter_col !IP_FIELDNAME type FIELDNAME
RETURNING !IP_COLUMN type SIMPLE
VALUE(ro_style) TYPE REF TO zcl_excel_style . !IP_ROW type ZEXCEL_CELL_ROW
raising
ZCX_EXCEL .
METHODS create_formular_subtotal METHODS create_formular_subtotal
IMPORTING IMPORTING
!i_row_int_start TYPE zexcel_cell_row !i_row_int_start TYPE zexcel_cell_row
@ -206,13 +208,6 @@ CLASS zcl_excel_converter DEFINITION
!it_table TYPE STANDARD TABLE !it_table TYPE STANDARD TABLE
RAISING RAISING
zcx_excel . zcx_excel .
METHODS get_color_style
IMPORTING
!i_row TYPE zexcel_cell_row
!i_fieldname TYPE fieldname
!i_style TYPE zexcel_cell_style
RETURNING
VALUE(r_style) TYPE zexcel_cell_style .
METHODS get_function_number METHODS get_function_number
IMPORTING IMPORTING
!i_totals_function TYPE zexcel_table_totals_function !i_totals_function TYPE zexcel_table_totals_function
@ -348,12 +343,15 @@ CLASS zcl_excel_converter IMPLEMENTATION.
ls_field_catalog TYPE zexcel_s_fieldcatalog, ls_field_catalog TYPE zexcel_s_fieldcatalog,
ls_fcat TYPE zexcel_s_converter_fcat, ls_fcat TYPE zexcel_s_converter_fcat,
lo_column TYPE REF TO zcl_excel_column, lo_column TYPE REF TO zcl_excel_column,
lv_row_int TYPE zexcel_cell_row,
lv_col_int TYPE zexcel_cell_column, lv_col_int TYPE zexcel_cell_column,
lv_col_alpha TYPE zexcel_cell_column_alpha, lv_col_alpha TYPE zexcel_cell_column_alpha,
ls_settings TYPE zexcel_s_table_settings, ls_settings TYPE zexcel_s_table_settings,
lv_tabix TYPE sy-tabix,
lv_line TYPE i. lv_line TYPE i.
FIELD-SYMBOLS: <fs_tab> TYPE ANY TABLE. FIELD-SYMBOLS: <fs_tab> TYPE ANY TABLE,
<fs_stab> TYPE ANY.
ASSIGN wo_data->* TO <fs_tab> . ASSIGN wo_data->* TO <fs_tab> .
@ -386,6 +384,15 @@ CLASS zcl_excel_converter IMPLEMENTATION.
LOOP AT wt_fieldcatalog INTO ls_fcat. LOOP AT wt_fieldcatalog INTO ls_fcat.
lv_col_int = w_col_int + ls_fcat-position - 1. lv_col_int = w_col_int + ls_fcat-position - 1.
lv_col_alpha = zcl_excel_common=>convert_column2alpha( lv_col_int ). lv_col_alpha = zcl_excel_common=>convert_column2alpha( lv_col_int ).
lv_row_int = w_row_int.
LOOP AT <fs_tab> ASSIGNING <fs_stab>.
lv_tabix = sy-tabix.
ADD 1 TO lv_row_int.
complete_cell( ip_table_row = lv_tabix
ip_fieldname = ls_fcat-columnname
ip_column = lv_col_alpha
ip_row = lv_row_int ).
ENDLOOP.
* Freeze panes * Freeze panes
IF ls_fcat-fix_column = abap_true. IF ls_fcat-fix_column = abap_true.
ADD 1 TO r_freeze_col. ADD 1 TO r_freeze_col.
@ -521,22 +528,53 @@ CLASS zcl_excel_converter IMPLEMENTATION.
ENDMETHOD. ENDMETHOD.
METHOD create_color_style. METHOD complete_cell.
DATA: ls_styles TYPE ts_styles.
DATA: lo_style TYPE REF TO zcl_excel_style.
READ TABLE wt_styles INTO ls_styles WITH KEY guid = i_style. * Now let's check for colors
IF sy-subrc = 0. DATA: ls_color TYPE zexcel_s_style_color,
lo_style = wo_excel->add_new_style( ). ls_colors TYPE zexcel_s_converter_col,
lo_style->font->bold = ls_styles-style->font->bold. ls_colors_col LIKE ls_colors,
lo_style->alignment->horizontal = ls_styles-style->alignment->horizontal. ls_fieldcat LIKE LINE OF wt_fieldcatalog,
lo_style->number_format->format_code = ls_styles-style->number_format->format_code. lv_subrc TYPE sy-subrc.
lo_style->font->color-rgb = is_colors-fontcolor. READ TABLE wt_fieldcatalog INTO ls_fieldcat WITH KEY columnname = ip_fieldname.
lo_style->fill->filltype = zcl_excel_style_fill=>c_fill_solid.
lo_style->fill->fgcolor-rgb = is_colors-fillcolor.
ro_style = lo_style. * Gemäss ALV-Logik gilt: Farbe am Feld hat immer oberste Priorität. Sonst gilt:
* Bei Schlüssel-Feldern übersteuert die Spaltenfarbe (dann hellblau) die Zeilenfarbe,
* ausser dies wird durch NOKEYCOL an der Zeile explizit verboten.
* Dann gilt hier wie sonst auch: Zeilenfarbe vor Spaltenfarbe.
IF NOT wt_colors IS INITIAL.
* Field has color
READ TABLE wt_colors INTO ls_colors WITH KEY rownumber = ip_table_row
columnname = ip_fieldname.
IF sy-subrc <> 0.
* Full line has color
READ TABLE wt_colors INTO ls_colors WITH KEY rownumber = ip_table_row
columnname = space.
IF sy-subrc <> 0 OR ls_colors-nokeycol IS INITIAL.
lv_subrc = sy-subrc.
* Fieldcatalog/Column has color
READ TABLE wt_colors INTO ls_colors_col WITH KEY rownumber = 0
columnname = ip_fieldname.
IF sy-subrc = 0 AND
( NOT ls_fieldcat-keyflag IS INITIAL OR "Use key color found
lv_subrc <> 0 ). "Use column color if no line color was found
ls_colors = ls_colors_col.
ENDIF.
ENDIF.
ENDIF.
IF NOT ls_colors IS INITIAL.
ls_color-rgb = zcl_excel_style_color=>c_gray.
ls_color-indexed = zcl_excel_style_color=>c_indexed_not_set.
ls_color-theme = zcl_excel_style_color=>c_theme_not_set.
wo_worksheet->change_cell_style( ip_column = ip_column
ip_row = ip_row
ip_font_color_rgb = ls_colors-fontcolor
ip_fill_filltype = zcl_excel_style_fill=>c_fill_solid
ip_fill_fgcolor_rgb = ls_colors-fillcolor
ip_borders_allborders_style = zcl_excel_style_border=>c_border_thin
ip_borders_allborders_color = ls_color ).
ENDIF.
ENDIF. ENDIF.
ENDMETHOD. ENDMETHOD.
@ -979,64 +1017,6 @@ CLASS zcl_excel_converter IMPLEMENTATION.
ENDMETHOD. ENDMETHOD.
METHOD get_color_style.
DATA: ls_colors TYPE zexcel_s_converter_col,
ls_color_styles TYPE ts_color_styles,
lo_style TYPE REF TO zcl_excel_style.
r_style = i_style. " Default we change nothing
IF wt_colors IS NOT INITIAL.
* Full line has color
READ TABLE wt_colors INTO ls_colors WITH KEY rownumber = i_row
columnname = space.
IF sy-subrc = 0.
READ TABLE wt_color_styles INTO ls_color_styles WITH KEY guid_old = i_style
fontcolor = ls_colors-fontcolor
fillcolor = ls_colors-fillcolor.
IF sy-subrc = 0.
r_style = ls_color_styles-style_new->get_guid( ).
ELSE.
lo_style = create_color_style( i_style = i_style
is_colors = ls_colors ) .
r_style = lo_style->get_guid( ) .
ls_color_styles-guid_old = i_style.
ls_color_styles-fontcolor = ls_colors-fontcolor.
ls_color_styles-fillcolor = ls_colors-fillcolor.
ls_color_styles-style_new = lo_style.
INSERT ls_color_styles INTO TABLE wt_color_styles.
ENDIF.
ELSE.
* Only field has color
READ TABLE wt_colors INTO ls_colors WITH KEY rownumber = i_row
columnname = i_fieldname.
IF sy-subrc = 0.
READ TABLE wt_color_styles INTO ls_color_styles WITH KEY guid_old = i_style
fontcolor = ls_colors-fontcolor
fillcolor = ls_colors-fillcolor.
IF sy-subrc = 0.
r_style = ls_color_styles-style_new->get_guid( ).
ELSE.
lo_style = create_color_style( i_style = i_style
is_colors = ls_colors ) .
ls_color_styles-guid_old = i_style.
ls_color_styles-fontcolor = ls_colors-fontcolor.
ls_color_styles-fillcolor = ls_colors-fillcolor.
ls_color_styles-style_new = lo_style.
INSERT ls_color_styles INTO TABLE wt_color_styles.
r_style = ls_color_styles-style_new->get_guid( ).
ENDIF.
ELSE.
r_style = i_style.
ENDIF.
ENDIF.
ELSE.
r_style = i_style.
ENDIF.
ENDMETHOD.
METHOD get_file. METHOD get_file.
DATA: lo_excel_writer TYPE REF TO zif_excel_writer. DATA: lo_excel_writer TYPE REF TO zif_excel_writer.
@ -1202,7 +1182,6 @@ CLASS zcl_excel_converter IMPLEMENTATION.
l_s_color TYPE abap_bool, l_s_color TYPE abap_bool,
lo_column TYPE REF TO zcl_excel_column, lo_column TYPE REF TO zcl_excel_column,
l_formula TYPE zexcel_cell_formula, l_formula TYPE zexcel_cell_formula,
l_style TYPE zexcel_cell_style,
l_cells TYPE i, l_cells TYPE i,
l_count TYPE i, l_count TYPE i,
l_table_row TYPE i. l_table_row TYPE i.
@ -1247,26 +1226,24 @@ CLASS zcl_excel_converter IMPLEMENTATION.
ASSIGN COMPONENT <fs_sfcat>-columnname OF STRUCTURE <fs_stab> TO <fs_fldval>. ASSIGN COMPONENT <fs_sfcat>-columnname OF STRUCTURE <fs_stab> TO <fs_fldval>.
* Now let's write the cell values * Now let's write the cell values
IF ws_layout-is_stripped = abap_true AND l_s_color = abap_true. IF ws_layout-is_stripped = abap_true AND l_s_color = abap_true.
l_style = get_color_style( i_row = l_table_row
i_fieldname = <fs_sfcat>-columnname
i_style = <fs_sfcat>-style_stripped ).
wo_worksheet->set_cell( ip_column = l_col_alpha wo_worksheet->set_cell( ip_column = l_col_alpha
ip_row = l_row_int ip_row = l_row_int
ip_value = <fs_fldval> ip_value = <fs_fldval>
ip_style = l_style ip_style = <fs_sfcat>-style_stripped
ip_conv_exit_length = ws_option-conv_exit_length ). ip_conv_exit_length = ws_option-conv_exit_length ).
CLEAR l_s_color. CLEAR l_s_color.
ELSE. ELSE.
l_style = get_color_style( i_row = l_table_row
i_fieldname = <fs_sfcat>-columnname
i_style = <fs_sfcat>-style_normal ).
wo_worksheet->set_cell( ip_column = l_col_alpha wo_worksheet->set_cell( ip_column = l_col_alpha
ip_row = l_row_int ip_row = l_row_int
ip_value = <fs_fldval> ip_value = <fs_fldval>
ip_style = l_style ip_style = <fs_sfcat>-style_normal
ip_conv_exit_length = ws_option-conv_exit_length ). ip_conv_exit_length = ws_option-conv_exit_length ).
l_s_color = abap_true. l_s_color = abap_true.
ENDIF. ENDIF.
complete_cell( ip_table_row = l_table_row
ip_fieldname = <fs_sfcat>-columnname
ip_column = l_col_alpha
ip_row = l_row_int ).
READ TABLE wt_filter TRANSPORTING NO FIELDS WITH TABLE KEY rownumber = l_table_row READ TABLE wt_filter TRANSPORTING NO FIELDS WITH TABLE KEY rownumber = l_table_row
columnname = <fs_sfcat>-columnname. columnname = <fs_sfcat>-columnname.
IF sy-subrc = 0. IF sy-subrc = 0.
@ -1319,7 +1296,6 @@ CLASS zcl_excel_converter IMPLEMENTATION.
lo_column TYPE REF TO zcl_excel_column, lo_column TYPE REF TO zcl_excel_column,
lo_row TYPE REF TO zcl_excel_row, lo_row TYPE REF TO zcl_excel_row,
l_formula TYPE zexcel_cell_formula, l_formula TYPE zexcel_cell_formula,
l_style TYPE zexcel_cell_style,
l_text TYPE string, l_text TYPE string,
ls_sort_values TYPE ts_sort_values, ls_sort_values TYPE ts_sort_values,
ls_subtotal_rows TYPE ts_subtotal_rows, ls_subtotal_rows TYPE ts_subtotal_rows,
@ -1547,26 +1523,24 @@ CLASS zcl_excel_converter IMPLEMENTATION.
ENDIF. ENDIF.
* Now let's write the cell values * Now let's write the cell values
IF ws_layout-is_stripped = abap_true AND l_s_color = abap_true. IF ws_layout-is_stripped = abap_true AND l_s_color = abap_true.
l_style = get_color_style( i_row = l_table_row
i_fieldname = <fs_sfcat>-columnname
i_style = <fs_sfcat>-style_stripped ).
wo_worksheet->set_cell( ip_column = l_col_alpha wo_worksheet->set_cell( ip_column = l_col_alpha
ip_row = l_row_int ip_row = l_row_int
ip_value = <fs_fldval> ip_value = <fs_fldval>
ip_style = l_style ip_style = <fs_sfcat>-style_stripped
ip_conv_exit_length = ws_option-conv_exit_length ). ip_conv_exit_length = ws_option-conv_exit_length ).
CLEAR l_s_color. CLEAR l_s_color.
ELSE. ELSE.
l_style = get_color_style( i_row = l_table_row
i_fieldname = <fs_sfcat>-columnname
i_style = <fs_sfcat>-style_normal ).
wo_worksheet->set_cell( ip_column = l_col_alpha wo_worksheet->set_cell( ip_column = l_col_alpha
ip_row = l_row_int ip_row = l_row_int
ip_value = <fs_fldval> ip_value = <fs_fldval>
ip_style = l_style ip_style = <fs_sfcat>-style_normal
ip_conv_exit_length = ws_option-conv_exit_length ). ip_conv_exit_length = ws_option-conv_exit_length ).
l_s_color = abap_true. l_s_color = abap_true.
ENDIF. ENDIF.
complete_cell( ip_table_row = l_table_row
ip_fieldname = <fs_sfcat>-columnname
ip_column = l_col_alpha
ip_row = l_row_int ).
READ TABLE wt_filter TRANSPORTING NO FIELDS WITH TABLE KEY rownumber = l_table_row READ TABLE wt_filter TRANSPORTING NO FIELDS WITH TABLE KEY rownumber = l_table_row
columnname = <fs_sfcat>-columnname. columnname = <fs_sfcat>-columnname.
IF sy-subrc = 0. IF sy-subrc = 0.