Fix issue #819 read/write autofilter values (#820)

* Fix issue #819 read/write autofilter values

Fix issue #819

* Code cleanup

Co-authored-by: sandraros <sandra.rossi@gmail.com>
Co-authored-by: Abo <andrea@borgia.bo.it>
This commit is contained in:
sandraros 2021-10-04 16:47:32 +02:00 committed by GitHub
parent 90992efb50
commit b9a248dcb4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 79 additions and 5 deletions

View File

@ -20,8 +20,7 @@ CLASS zcl_excel_autofilters DEFINITION
METHODS clear .
METHODS get
IMPORTING
!io_worksheet TYPE REF TO zcl_excel_worksheet OPTIONAL
!i_sheet_guid TYPE sysuuid_x16 OPTIONAL
!io_worksheet TYPE REF TO zcl_excel_worksheet
RETURNING
VALUE(ro_autofilter) TYPE REF TO zcl_excel_autofilter .
METHODS is_empty

View File

@ -232,6 +232,10 @@ CLASS zcl_excel_reader_2007 DEFINITION
!io_worksheet TYPE REF TO zcl_excel_worksheet
RAISING
zcx_excel .
METHODS load_worksheet_autofilter
IMPORTING
io_ixml_worksheet TYPE REF TO if_ixml_document
io_worksheet TYPE REF TO zcl_excel_worksheet.
METHODS load_worksheet_pagemargins
IMPORTING
!io_ixml_worksheet TYPE REF TO if_ixml_document
@ -2872,6 +2876,11 @@ CLASS zcl_excel_reader_2007 IMPLEMENTATION.
CATCH zcx_excel. " Ignore pagebreak reading errors - pass everything we were able to identify
ENDTRY.
TRY.
me->load_worksheet_autofilter( io_ixml_worksheet = lo_ixml_worksheet
io_worksheet = io_worksheet ).
CATCH zcx_excel. " Ignore autofilter reading errors - pass everything we were able to identify
ENDTRY.
ENDMETHOD.
@ -3550,6 +3559,74 @@ CLASS zcl_excel_reader_2007 IMPLEMENTATION.
ENDMETHOD.
METHOD load_worksheet_autofilter.
TYPES: BEGIN OF lty_autofilter,
ref TYPE string,
END OF lty_autofilter.
DATA: lo_ixml_autofilter_elem TYPE REF TO if_ixml_element,
lv_ref TYPE string,
lo_ixml_filter_column_coll TYPE REF TO if_ixml_node_collection,
lo_ixml_filter_column_iter TYPE REF TO if_ixml_node_iterator,
lo_ixml_filter_column TYPE REF TO if_ixml_element,
lv_col_id TYPE i,
lv_column TYPE zexcel_cell_column,
lo_ixml_filters_coll TYPE REF TO if_ixml_node_collection,
lo_ixml_filters_iter TYPE REF TO if_ixml_node_iterator,
lo_ixml_filters TYPE REF TO if_ixml_element,
lo_ixml_filter_coll TYPE REF TO if_ixml_node_collection,
lo_ixml_filter_iter TYPE REF TO if_ixml_node_iterator,
lo_ixml_filter TYPE REF TO if_ixml_element,
lv_val TYPE string,
lo_autofilters TYPE REF TO zcl_excel_autofilters,
lo_autofilter TYPE REF TO zcl_excel_autofilter.
lo_autofilters = io_worksheet->excel->get_autofilters_reference( ).
lo_ixml_autofilter_elem = io_ixml_worksheet->find_from_name( 'autoFilter' ).
IF lo_ixml_autofilter_elem IS BOUND.
lv_ref = lo_ixml_autofilter_elem->get_attribute_ns( 'ref' ).
lo_ixml_filter_column_coll = lo_ixml_autofilter_elem->get_elements_by_tag_name( name = 'filterColumn' ).
lo_ixml_filter_column_iter = lo_ixml_filter_column_coll->create_iterator( ).
lo_ixml_filter_column ?= lo_ixml_filter_column_iter->get_next( ).
WHILE lo_ixml_filter_column IS BOUND.
lv_col_id = lo_ixml_filter_column->get_attribute_ns( 'colId' ).
lv_column = lv_col_id + 1.
lo_ixml_filters_coll = lo_ixml_filter_column->get_elements_by_tag_name( name = 'filters' ).
lo_ixml_filters_iter = lo_ixml_filters_coll->create_iterator( ).
lo_ixml_filters ?= lo_ixml_filters_iter->get_next( ).
WHILE lo_ixml_filters IS BOUND.
lo_ixml_filter_coll = lo_ixml_filter_column->get_elements_by_tag_name( name = 'filter' ).
lo_ixml_filter_iter = lo_ixml_filter_coll->create_iterator( ).
lo_ixml_filter ?= lo_ixml_filter_iter->get_next( ).
WHILE lo_ixml_filter IS BOUND.
lv_val = lo_ixml_filter->get_attribute_ns( 'val' ).
lo_autofilter = lo_autofilters->get( io_worksheet = io_worksheet ).
IF lo_autofilter IS NOT BOUND.
lo_autofilter = lo_autofilters->add( io_sheet = io_worksheet ).
ENDIF.
lo_autofilter->set_value(
i_column = lv_column
i_value = lv_val ).
lo_ixml_filter ?= lo_ixml_filter_iter->get_next( ).
ENDWHILE.
lo_ixml_filters ?= lo_ixml_filters_iter->get_next( ).
ENDWHILE.
lo_ixml_filter_column ?= lo_ixml_filter_column_iter->get_next( ).
ENDWHILE.
ENDIF.
ENDMETHOD.
METHOD load_worksheet_pagemargins.
TYPES: BEGIN OF lty_page_margins,

View File

@ -7284,7 +7284,6 @@ CLASS zcl_excel_writer_2007 IMPLEMENTATION.
DATA: lv_xml_node_ridx_id TYPE string,
lv_value TYPE string,
lv_syindex TYPE string,
l_guid TYPE sysuuid_x16,
lv_active_sheet TYPE zexcel_active_worksheet.
**********************************************************************
@ -7485,8 +7484,7 @@ CLASS zcl_excel_writer_2007 IMPLEMENTATION.
lo_worksheet ?= lo_iterator->get_next( ).
lv_syindex = sy-index - 1 .
l_guid = lo_worksheet->get_guid( ).
lo_autofilter = lo_autofilters->get( i_sheet_guid = l_guid ) .
lo_autofilter = lo_autofilters->get( io_worksheet = lo_worksheet ).
IF lo_autofilter IS BOUND.
lo_sub_element = lo_document->create_simple_element_ns( name = lc_xml_node_definedname
parent = lo_document ).