Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read XLSX from third-party providers (namespaces) #935

Merged
merged 10 commits into from
Jan 15, 2022
31 changes: 31 additions & 0 deletions src/zcl_excel_common.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ CLASS zcl_excel_common DEFINITION
EXPORTING
!e_column TYPE zexcel_cell_column_alpha
!e_row TYPE zexcel_cell_row .
CLASS-METHODS clone_ixml_with_namespaces
IMPORTING
element TYPE REF TO if_ixml_element
RETURNING
VALUE(result) TYPE REF TO if_ixml_element.
CLASS-METHODS date_to_excel_string
IMPORTING
!ip_value TYPE d
Expand Down Expand Up @@ -625,6 +630,32 @@ CLASS zcl_excel_common IMPLEMENTATION.
ENDMETHOD.


METHOD clone_ixml_with_namespaces.

DATA: iterator TYPE REF TO if_ixml_node_iterator,
node TYPE REF TO if_ixml_node,
xmlns TYPE ihttpnvp,
xmlns_table TYPE TABLE OF ihttpnvp.
FIELD-SYMBOLS:
<xmlns> TYPE ihttpnvp.

iterator = element->create_iterator( ).
result ?= element->clone( ).
node = iterator->get_next( ).
WHILE node IS BOUND.
xmlns-name = node->get_namespace_prefix( ).
xmlns-value = node->get_namespace_uri( ).
COLLECT xmlns INTO xmlns_table.
node = iterator->get_next( ).
ENDWHILE.

LOOP AT xmlns_table ASSIGNING <xmlns>.
result->set_attribute_ns( prefix = 'xmlns' name = <xmlns>-name value = <xmlns>-value ).
ENDLOOP.

ENDMETHOD.


METHOD date_to_excel_string.
DATA: lv_date_diff TYPE i.

Expand Down
277 changes: 142 additions & 135 deletions src/zcl_excel_drawing.clas.abap

Large diffs are not rendered by default.

246 changes: 136 additions & 110 deletions src/zcl_excel_reader_2007.clas.abap

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/zcl_excel_reader_xlsm.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ CLASS zcl_excel_reader_xlsm IMPLEMENTATION.

rels_workbook = me->get_ixml_from_zip_archive( rels_workbook_path ).

node ?= rels_workbook->find_from_name( 'Relationship' ).
node ?= rels_workbook->find_from_name_ns( name = 'Relationship' uri = namespace-relationships ).
WHILE node IS BOUND.
me->fill_struct_from_attributes( EXPORTING ip_element = node CHANGING cp_structure = relationship ).

Expand All @@ -91,7 +91,7 @@ CLASS zcl_excel_reader_xlsm IMPLEMENTATION.

" Read Workbook codeName
workbook = me->get_ixml_from_zip_archive( iv_workbook_full_filename ).
node ?= workbook->find_from_name( 'fileVersion' ).
node ?= workbook->find_from_name_ns( name = 'fileVersion' uri = namespace-main ).
IF node IS BOUND.

fill_struct_from_attributes( EXPORTING ip_element = node
Expand All @@ -102,7 +102,7 @@ CLASS zcl_excel_reader_xlsm IMPLEMENTATION.

" Read Workbook codeName
workbook = me->get_ixml_from_zip_archive( iv_workbook_full_filename ).
node ?= workbook->find_from_name( 'workbookPr' ).
node ?= workbook->find_from_name_ns( name = 'workbookPr' uri = namespace-main ).
IF node IS BOUND.

fill_struct_from_attributes( EXPORTING ip_element = node
Expand All @@ -125,7 +125,7 @@ CLASS zcl_excel_reader_xlsm IMPLEMENTATION.

" Read Workbook codeName
worksheet = me->get_ixml_from_zip_archive( ip_path ).
node ?= worksheet->find_from_name( 'sheetPr' ).
node ?= worksheet->find_from_name_ns( name = 'sheetPr' uri = namespace-main ).
IF node IS BOUND.

fill_struct_from_attributes( EXPORTING ip_element = node
Expand Down
3 changes: 1 addition & 2 deletions src/zcl_excel_theme_eclrschemelst.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ CLASS zcl_excel_theme_eclrschemelst IMPLEMENTATION.


METHOD load.
"! so far copy only existing values
extracolor ?= io_extra_color.
extracolor = zcl_excel_common=>clone_ixml_with_namespaces( io_extra_color ).
ENDMETHOD. "load
ENDCLASS.
3 changes: 1 addition & 2 deletions src/zcl_excel_theme_extlst.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ CLASS zcl_excel_theme_extlst IMPLEMENTATION.


METHOD load.
"! so far copy only existing values
extlst ?= io_extlst.
extlst = zcl_excel_common=>clone_ixml_with_namespaces( io_extlst ).
ENDMETHOD. "load
ENDCLASS.
3 changes: 1 addition & 2 deletions src/zcl_excel_theme_fmt_scheme.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ CLASS zcl_excel_theme_fmt_scheme IMPLEMENTATION.


METHOD load.
"! so far copy only existing values
fmt_scheme ?= io_fmt_scheme.
fmt_scheme = zcl_excel_common=>clone_ixml_with_namespaces( io_fmt_scheme ).
ENDMETHOD. "load
ENDCLASS.
3 changes: 1 addition & 2 deletions src/zcl_excel_theme_objectdefaults.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ CLASS zcl_excel_theme_objectdefaults IMPLEMENTATION.


METHOD load.
"! so far copy only existing values
objectdefaults ?= io_object_def.
objectdefaults = zcl_excel_common=>clone_ixml_with_namespaces( io_object_def ).
ENDMETHOD. "load
ENDCLASS.