improve handling of multiple CF rules and ranges (#682)

This commit is contained in:
Domi Bigl 2020-07-21 22:22:20 +02:00 committed by GitHub
parent 5a33253f0e
commit 37ad2fd68a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 51 additions and 24 deletions

View File

@ -2912,11 +2912,10 @@ METHOD load_worksheet_cond_format.
lo_ixml_rule,
lo_style_cond.
*--------------------------------------------------------------------*
* Get type of rule
*--------------------------------------------------------------------*
lo_ixml_rules = io_ixml_worksheet->get_elements_by_tag_name( name = 'cfRule' ).
lo_ixml_rules = lo_ixml_cond_format->get_elements_by_tag_name( name = 'cfRule' ).
lo_ixml_iterator2 = lo_ixml_rules->create_iterator( ).
lo_ixml_rule ?= lo_ixml_iterator2->get_next( ).
@ -2930,37 +2929,37 @@ METHOD load_worksheet_cond_format.
CASE lv_rule.
WHEN zcl_excel_style_cond=>c_rule_cellis.
lo_style_cond = io_worksheet->add_new_style_cond( ).
lo_style_cond = io_worksheet->add_new_style_cond( '' ).
load_worksheet_cond_format_ci( io_ixml_rule = lo_ixml_rule
io_style_cond = lo_style_cond ).
WHEN zcl_excel_style_cond=>c_rule_databar.
lo_style_cond = io_worksheet->add_new_style_cond( ).
lo_style_cond = io_worksheet->add_new_style_cond( '' ).
load_worksheet_cond_format_db( io_ixml_rule = lo_ixml_rule
io_style_cond = lo_style_cond ).
WHEN zcl_excel_style_cond=>c_rule_expression.
lo_style_cond = io_worksheet->add_new_style_cond( ).
lo_style_cond = io_worksheet->add_new_style_cond( '' ).
load_worksheet_cond_format_ex( io_ixml_rule = lo_ixml_rule
io_style_cond = lo_style_cond ).
WHEN zcl_excel_style_cond=>c_rule_iconset.
lo_style_cond = io_worksheet->add_new_style_cond( ).
lo_style_cond = io_worksheet->add_new_style_cond( '' ).
load_worksheet_cond_format_is( io_ixml_rule = lo_ixml_rule
io_style_cond = lo_style_cond ).
WHEN zcl_excel_style_cond=>c_rule_colorscale.
lo_style_cond = io_worksheet->add_new_style_cond( ).
lo_style_cond = io_worksheet->add_new_style_cond( '' ).
load_worksheet_cond_format_cs( io_ixml_rule = lo_ixml_rule
io_style_cond = lo_style_cond ).
WHEN zcl_excel_style_cond=>c_rule_top10.
lo_style_cond = io_worksheet->add_new_style_cond( ).
lo_style_cond = io_worksheet->add_new_style_cond( '' ).
load_worksheet_cond_format_t10( io_ixml_rule = lo_ixml_rule
io_style_cond = lo_style_cond ).
WHEN zcl_excel_style_cond=>c_rule_above_average.
lo_style_cond = io_worksheet->add_new_style_cond( ).
lo_style_cond = io_worksheet->add_new_style_cond( '' ).
load_worksheet_cond_format_aa( io_ixml_rule = lo_ixml_rule
io_style_cond = lo_style_cond ).
WHEN OTHERS.

View File

@ -64,9 +64,10 @@ public section.
data PRIORITY type ZEXCEL_STYLE_PRIORITY value 1. "#EC NOTEXT . . . . . . . . . . . . . . . . . . . . " .
data RULE type ZEXCEL_CONDITION_RULE .
methods CONSTRUCTOR
importing
!IP_GUID type ZEXCEL_CELL_STYLE optional .
METHODS constructor
IMPORTING
!ip_guid TYPE zexcel_cell_style OPTIONAL
!ip_dimension_range TYPE string.
methods GET_DIMENSION_RANGE
returning
value(EP_DIMENSION_RANGE) type STRING .
@ -191,7 +192,7 @@ METHOD constructor.
me->priority = 1.
* inizialize dimension range
me->mv_rule_range = 'A1'.
me->mv_rule_range = ip_dimension_range.
IF ip_guid IS NOT INITIAL.
me->guid = ip_guid.

View File

@ -56,8 +56,10 @@ CLASS zcl_excel_worksheet DEFINITION
RETURNING
VALUE(eo_column) TYPE REF TO zcl_excel_column .
METHODS add_new_style_cond
IMPORTING
!ip_dimension_range TYPE string DEFAULT 'A1'
RETURNING
VALUE(eo_style_cond) TYPE REF TO zcl_excel_style_cond .
VALUE(eo_style_cond) TYPE REF TO zcl_excel_style_cond.
METHODS add_new_data_validation
RETURNING
VALUE(eo_data_validation) TYPE REF TO zcl_excel_data_validation .
@ -691,7 +693,7 @@ CLASS zcl_excel_worksheet IMPLEMENTATION.
METHOD add_new_style_cond.
CREATE OBJECT eo_style_cond.
CREATE OBJECT eo_style_cond EXPORTING ip_dimension_range = ip_dimension_range.
styles_cond->add( eo_style_cond ).
ENDMETHOD. "ADD_NEW_STYLE_COND

View File

@ -3644,6 +3644,12 @@ METHOD create_xl_sheet.
* issue #220 - If cell in tables-area don't use default from row or column or sheet - Declarations 1 - end
*--------------------------------------------------------------------*
TYPES: BEGIN OF ty_condformating_range,
dimension_range TYPE string,
condformatting_node TYPE REF TO if_ixml_element,
END OF ty_condformating_range,
ty_condformating_ranges TYPE STANDARD TABLE OF ty_condformating_range.
** Constant node name
DATA: lc_xml_node_worksheet TYPE string VALUE 'worksheet',
lc_xml_node_sheetpr TYPE string VALUE 'sheetPr',
@ -3838,11 +3844,14 @@ METHOD create_xl_sheet.
ls_values TYPE zexcel_s_autofilter_values,
lo_autofilters TYPE REF TO zcl_excel_autofilters,
lo_autofilter TYPE REF TO zcl_excel_autofilter,
lv_ref TYPE string.
lv_ref TYPE string,
lt_condformating_ranges TYPE ty_condformating_ranges,
ls_condformating_range TYPE ty_condformating_range.
FIELD-SYMBOLS: <ls_sheet_content> TYPE zexcel_s_cell_data,
<fs_range_merge> LIKE LINE OF lt_range_merge,
<ls_row_outline> LIKE LINE OF lts_row_outlines.
FIELD-SYMBOLS: <ls_sheet_content> TYPE zexcel_s_cell_data,
<fs_range_merge> LIKE LINE OF lt_range_merge,
<ls_row_outline> LIKE LINE OF lts_row_outlines,
<ls_condformating_range> TYPE ty_condformating_range.
*--------------------------------------------------------------------*
* issue #220 - If cell in tables-area don't use default from row or column or sheet - Declarations 2 - start
@ -4514,11 +4523,23 @@ METHOD create_xl_sheet.
IF lo_style_cond->rule IS INITIAL.
CONTINUE.
ENDIF.
lo_element = lo_document->create_simple_element( name = lc_xml_node_condformatting
parent = lo_document ).
lv_value = lo_style_cond->get_dimension_range( ) .
lo_element->set_attribute_ns( name = lc_xml_attr_sqref
value = lv_value ).
lv_value = lo_style_cond->get_dimension_range( ).
READ TABLE lt_condformating_ranges WITH KEY dimension_range = lv_value ASSIGNING <ls_condformating_range>.
IF sy-subrc = 0.
lo_element = <ls_condformating_range>-condformatting_node.
ELSE.
lo_element = lo_document->create_simple_element( name = lc_xml_node_condformatting
parent = lo_document ).
lo_element->set_attribute_ns( name = lc_xml_attr_sqref
value = lv_value ).
ls_condformating_range-dimension_range = lv_value.
ls_condformating_range-condformatting_node = lo_element.
INSERT ls_condformating_range INTO TABLE lt_condformating_ranges.
ENDIF.
" cfRule node
lo_element_2 = lo_document->create_simple_element( name = lc_xml_node_cfrule

View File

@ -72,6 +72,10 @@ INITIALIZATION.
APPEND INITIAL LINE TO lt_files ASSIGNING <wa_files>.
<wa_files>-input = '04_Sheets.xlsx'.
APPEND INITIAL LINE TO lt_files ASSIGNING <wa_files>.
<wa_files>-input = '05_Conditional.xlsx'.
APPEND INITIAL LINE TO lt_files ASSIGNING <wa_files>.
<wa_files>-input = '07_ConditionalAll.xlsx'.
APPEND INITIAL LINE TO lt_files ASSIGNING <wa_files>.
<wa_files>-input = '08_Range.xlsx'.
APPEND INITIAL LINE TO lt_files ASSIGNING <wa_files>.
<wa_files>-input = '13_MergedCells.xlsx'.