comments support in reader, initial version (#976)

* comments support in reader, initial version

* fixes formatting for unmodified section

* remove spurious cast

hopefully fixes linter complaint

* handle raw text comments

* removed raw text handling (unused)
This commit is contained in:
Abo 2022-01-23 16:41:47 +01:00 committed by GitHub
parent 66ed127cb8
commit bffb01c7b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -231,6 +231,12 @@ CLASS zcl_excel_reader_2007 DEFINITION
!io_worksheet TYPE REF TO zcl_excel_worksheet
RAISING
zcx_excel .
METHODS load_comments
IMPORTING
ip_path TYPE string
io_worksheet TYPE REF TO zcl_excel_worksheet
RAISING
zcx_excel .
METHODS load_worksheet_hyperlinks
IMPORTING
!io_ixml_worksheet TYPE REF TO if_ixml_document
@ -2299,6 +2305,7 @@ CLASS zcl_excel_reader_2007 IMPLEMENTATION.
lc_xml_attr_true_int TYPE string VALUE '1',
lc_rel_drawing TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing',
lc_rel_hyperlink TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink',
lc_rel_comments TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments',
lc_rel_printer TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/printerSettings'.
DATA: lo_ixml_worksheet TYPE REF TO if_ixml_document,
@ -2457,6 +2464,13 @@ CLASS zcl_excel_reader_2007 IMPLEMENTATION.
MOVE-CORRESPONDING ls_relationship TO ls_external_hyperlink.
INSERT ls_external_hyperlink INTO TABLE lt_external_hyperlinks.
WHEN lc_rel_comments.
TRY.
me->load_comments( ip_path = lv_path
io_worksheet = io_worksheet ).
CATCH zcx_excel.
ENDTRY.
WHEN OTHERS.
ENDCASE.
@ -3573,6 +3587,47 @@ CLASS zcl_excel_reader_2007 IMPLEMENTATION.
ENDMETHOD.
METHOD load_comments.
DATA: lo_comments_xml TYPE REF TO if_ixml_document,
lo_node_comment TYPE REF TO if_ixml_element,
lo_node_comment_child TYPE REF TO if_ixml_element,
lo_node_r_child_t TYPE REF TO if_ixml_element,
lo_attr TYPE REF TO if_ixml_attribute,
lo_comment TYPE REF TO zcl_excel_comment,
lv_comment_text TYPE string,
lv_node_value TYPE string,
lv_attr_value TYPE string.
lo_comments_xml = me->get_ixml_from_zip_archive( ip_path ).
lo_node_comment ?= lo_comments_xml->find_from_name_ns( name = 'comment' uri = namespace-main ).
WHILE lo_node_comment IS BOUND.
CLEAR lv_comment_text.
lo_attr = lo_node_comment->get_attribute_node_ns( name = 'ref' ).
lv_attr_value = lo_attr->get_value( ).
lo_node_comment_child ?= lo_node_comment->get_first_child( ).
WHILE lo_node_comment_child IS BOUND.
" There will be rPr nodes here, but we do not support them
" in comments right now; see 'load_shared_strings' for handling.
" Extract the <t>...</t> part of each <r>-tag
lo_node_r_child_t ?= lo_node_comment_child->find_from_name_ns( name = 't' uri = namespace-main ).
IF lo_node_r_child_t IS BOUND.
lv_node_value = lo_node_r_child_t->get_value( ).
CONCATENATE lv_comment_text lv_node_value INTO lv_comment_text RESPECTING BLANKS.
ENDIF.
lo_node_comment_child ?= lo_node_comment_child->get_next( ).
ENDWHILE.
CREATE OBJECT lo_comment.
lo_comment->set_text( ip_ref = lv_attr_value ip_text = lv_comment_text ).
io_worksheet->add_comment( lo_comment ).
lo_node_comment ?= lo_node_comment->get_next( ).
ENDWHILE.
ENDMETHOD.
METHOD load_worksheet_hyperlinks.