mirror of
https://github.com/abap2xlsx/abap2xlsx.git
synced 2025-05-05 14:06:24 +08:00
Update zcl_excel_converter.clas.abap
This commit is contained in:
parent
bae673121b
commit
16fac218f7
|
@ -133,12 +133,14 @@ CLASS zcl_excel_converter DEFINITION
|
|||
RAISING
|
||||
zcx_excel .
|
||||
METHODS clean_fieldcatalog .
|
||||
METHODS create_color_style
|
||||
IMPORTING
|
||||
!i_style TYPE zexcel_cell_style
|
||||
!is_colors TYPE zexcel_s_converter_col
|
||||
RETURNING
|
||||
VALUE(ro_style) TYPE REF TO zcl_excel_style .
|
||||
methods COMPLETE_CELL
|
||||
importing
|
||||
!IP_TABLE_ROW type ZEXCEL_CELL_ROW
|
||||
!IP_FIELDNAME type FIELDNAME
|
||||
!IP_COLUMN type SIMPLE
|
||||
!IP_ROW type ZEXCEL_CELL_ROW
|
||||
raising
|
||||
ZCX_EXCEL .
|
||||
METHODS create_formular_subtotal
|
||||
IMPORTING
|
||||
!i_row_int_start TYPE zexcel_cell_row
|
||||
|
@ -206,13 +208,6 @@ CLASS zcl_excel_converter DEFINITION
|
|||
!it_table TYPE STANDARD TABLE
|
||||
RAISING
|
||||
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
|
||||
IMPORTING
|
||||
!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_fcat TYPE zexcel_s_converter_fcat,
|
||||
lo_column TYPE REF TO zcl_excel_column,
|
||||
lv_row_int TYPE zexcel_cell_row,
|
||||
lv_col_int TYPE zexcel_cell_column,
|
||||
lv_col_alpha TYPE zexcel_cell_column_alpha,
|
||||
ls_settings TYPE zexcel_s_table_settings,
|
||||
lv_tabix TYPE sy-tabix,
|
||||
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> .
|
||||
|
||||
|
@ -386,6 +384,15 @@ CLASS zcl_excel_converter IMPLEMENTATION.
|
|||
LOOP AT wt_fieldcatalog INTO ls_fcat.
|
||||
lv_col_int = w_col_int + ls_fcat-position - 1.
|
||||
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
|
||||
IF ls_fcat-fix_column = abap_true.
|
||||
ADD 1 TO r_freeze_col.
|
||||
|
@ -521,22 +528,53 @@ CLASS zcl_excel_converter IMPLEMENTATION.
|
|||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD create_color_style.
|
||||
DATA: ls_styles TYPE ts_styles.
|
||||
DATA: lo_style TYPE REF TO zcl_excel_style.
|
||||
METHOD complete_cell.
|
||||
|
||||
READ TABLE wt_styles INTO ls_styles WITH KEY guid = i_style.
|
||||
IF sy-subrc = 0.
|
||||
lo_style = wo_excel->add_new_style( ).
|
||||
lo_style->font->bold = ls_styles-style->font->bold.
|
||||
lo_style->alignment->horizontal = ls_styles-style->alignment->horizontal.
|
||||
lo_style->number_format->format_code = ls_styles-style->number_format->format_code.
|
||||
* Now let's check for colors
|
||||
DATA: ls_color TYPE zexcel_s_style_color,
|
||||
ls_colors TYPE zexcel_s_converter_col,
|
||||
ls_colors_col LIKE ls_colors,
|
||||
ls_fieldcat LIKE LINE OF wt_fieldcatalog,
|
||||
lv_subrc TYPE sy-subrc.
|
||||
|
||||
lo_style->font->color-rgb = is_colors-fontcolor.
|
||||
lo_style->fill->filltype = zcl_excel_style_fill=>c_fill_solid.
|
||||
lo_style->fill->fgcolor-rgb = is_colors-fillcolor.
|
||||
READ TABLE wt_fieldcatalog INTO ls_fieldcat WITH KEY columnname = ip_fieldname.
|
||||
|
||||
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.
|
||||
ENDMETHOD.
|
||||
|
||||
|
@ -979,64 +1017,6 @@ CLASS zcl_excel_converter IMPLEMENTATION.
|
|||
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.
|
||||
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,
|
||||
lo_column TYPE REF TO zcl_excel_column,
|
||||
l_formula TYPE zexcel_cell_formula,
|
||||
l_style TYPE zexcel_cell_style,
|
||||
l_cells TYPE i,
|
||||
l_count 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>.
|
||||
* Now let's write the cell values
|
||||
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
|
||||
ip_row = l_row_int
|
||||
ip_value = <fs_fldval>
|
||||
ip_style = l_style
|
||||
ip_style = <fs_sfcat>-style_stripped
|
||||
ip_conv_exit_length = ws_option-conv_exit_length ).
|
||||
CLEAR l_s_color.
|
||||
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
|
||||
ip_row = l_row_int
|
||||
ip_value = <fs_fldval>
|
||||
ip_style = l_style
|
||||
ip_style = <fs_sfcat>-style_normal
|
||||
ip_conv_exit_length = ws_option-conv_exit_length ).
|
||||
l_s_color = abap_true.
|
||||
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
|
||||
columnname = <fs_sfcat>-columnname.
|
||||
IF sy-subrc = 0.
|
||||
|
@ -1319,7 +1296,6 @@ CLASS zcl_excel_converter IMPLEMENTATION.
|
|||
lo_column TYPE REF TO zcl_excel_column,
|
||||
lo_row TYPE REF TO zcl_excel_row,
|
||||
l_formula TYPE zexcel_cell_formula,
|
||||
l_style TYPE zexcel_cell_style,
|
||||
l_text TYPE string,
|
||||
ls_sort_values TYPE ts_sort_values,
|
||||
ls_subtotal_rows TYPE ts_subtotal_rows,
|
||||
|
@ -1547,26 +1523,24 @@ CLASS zcl_excel_converter IMPLEMENTATION.
|
|||
ENDIF.
|
||||
* Now let's write the cell values
|
||||
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
|
||||
ip_row = l_row_int
|
||||
ip_value = <fs_fldval>
|
||||
ip_style = l_style
|
||||
ip_style = <fs_sfcat>-style_stripped
|
||||
ip_conv_exit_length = ws_option-conv_exit_length ).
|
||||
CLEAR l_s_color.
|
||||
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
|
||||
ip_row = l_row_int
|
||||
ip_value = <fs_fldval>
|
||||
ip_style = l_style
|
||||
ip_style = <fs_sfcat>-style_normal
|
||||
ip_conv_exit_length = ws_option-conv_exit_length ).
|
||||
l_s_color = abap_true.
|
||||
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
|
||||
columnname = <fs_sfcat>-columnname.
|
||||
IF sy-subrc = 0.
|
||||
|
|
Loading…
Reference in New Issue
Block a user