From a9e1068e44feca4a6999f01677231f9d09a8e65c Mon Sep 17 00:00:00 2001 From: RixarSAP <168567887+RixarSAP@users.noreply.github.com> Date: Mon, 6 May 2024 08:42:16 +0200 Subject: [PATCH] Add possibility to change the size of the comments. (#1219) Fix #1221 --- src/zcl_excel_comment.clas.abap | 45 ++++++++++++++++++++++++++--- src/zcl_excel_writer_2007.clas.abap | 27 ++++++++++++++++- 2 files changed, 67 insertions(+), 5 deletions(-) diff --git a/src/zcl_excel_comment.clas.abap b/src/zcl_excel_comment.clas.abap index d25310e..a285701 100644 --- a/src/zcl_excel_comment.clas.abap +++ b/src/zcl_excel_comment.clas.abap @@ -5,28 +5,42 @@ CLASS zcl_excel_comment DEFINITION PUBLIC SECTION. + CONSTANTS default_right_column TYPE i VALUE 4. "#EC NOTEXT + CONSTANTS default_bottom_row TYPE i VALUE 15. "#EC NOTEXT + METHODS constructor . - METHODS get_name + METHODS get_bottom_row RETURNING - VALUE(r_name) TYPE string . + VALUE(rp_result) TYPE i . METHODS get_index RETURNING VALUE(rp_index) TYPE string . + METHODS get_name + RETURNING + VALUE(r_name) TYPE string . METHODS get_ref RETURNING VALUE(rp_ref) TYPE string . + METHODS get_right_column + RETURNING + VALUE(rp_result) TYPE i . METHODS get_text RETURNING VALUE(rp_text) TYPE string . METHODS set_text IMPORTING - !ip_text TYPE string - !ip_ref TYPE string OPTIONAL . + !ip_text TYPE string + !ip_ref TYPE string OPTIONAL + !ip_right_column TYPE i OPTIONAL + !ip_bottom_row TYPE i OPTIONAL . + PROTECTED SECTION. PRIVATE SECTION. + DATA bottom_row TYPE i . DATA index TYPE string . DATA ref TYPE string . + DATA right_column TYPE i . DATA text TYPE string . ENDCLASS. @@ -40,6 +54,11 @@ CLASS zcl_excel_comment IMPLEMENTATION. ENDMETHOD. + METHOD get_bottom_row. + rp_result = bottom_row. + ENDMETHOD. + + METHOD get_index. rp_index = me->index. ENDMETHOD. @@ -55,6 +74,11 @@ CLASS zcl_excel_comment IMPLEMENTATION. ENDMETHOD. + METHOD get_right_column. + rp_result = right_column. + ENDMETHOD. + + METHOD get_text. rp_text = me->text. ENDMETHOD. @@ -66,5 +90,18 @@ CLASS zcl_excel_comment IMPLEMENTATION. IF ip_ref IS SUPPLIED. me->ref = ip_ref. ENDIF. + + IF ip_right_column IS NOT INITIAL. + me->right_column = ip_right_column. + ELSE. + me->right_column = default_right_column. + ENDIF. + + IF ip_bottom_row IS NOT INITIAL. + me->bottom_row = ip_bottom_row. + ELSE. + me->bottom_row = default_bottom_row. + ENDIF. ENDMETHOD. + ENDCLASS. diff --git a/src/zcl_excel_writer_2007.clas.abap b/src/zcl_excel_writer_2007.clas.abap index b532db4..958e639 100644 --- a/src/zcl_excel_writer_2007.clas.abap +++ b/src/zcl_excel_writer_2007.clas.abap @@ -3139,6 +3139,7 @@ CLASS zcl_excel_writer_2007 IMPLEMENTATION. lc_xml_attr_val_none TYPE string VALUE 'none', lc_xml_attr_val_msodir TYPE string VALUE 'mso-direction-alt:auto', lc_xml_attr_val_note TYPE string VALUE 'Note'. + CONSTANTS lc_anchor_init TYPE string VALUE '2, 15, 11, 10, &right_column&, 31, &bottom_row&, 9'. DATA: lo_document TYPE REF TO if_ixml_document, @@ -3175,6 +3176,11 @@ CLASS zcl_excel_writer_2007 IMPLEMENTATION. lv_int_value TYPE i, lv_int_value_string TYPE string. DATA: lv_rel_id TYPE i. + DATA lv_anchor TYPE string. + DATA lv_bottom_row TYPE i. + DATA lv_right_column TYPE i. + DATA lv_bottom_row_str TYPE string. + DATA lv_right_column_str TYPE string. ********************************************************************** @@ -3297,7 +3303,26 @@ CLASS zcl_excel_writer_2007 IMPLEMENTATION. lo_element_clientdata->append_child( new_child = lo_element_sizewithcells ). lo_element_anchor = lo_document->create_simple_element( name = lc_xml_node_anchor parent = lo_document ). - lo_element_anchor->set_value( '2, 15, 11, 10, 4, 31, 15, 9' ). + + " Anchor represents 4 pairs of numbers: + " ( left column, left offset ), ( top row, top offset ), + " ( right column, right offset ), ( bottom row, botton offset ) + " Offsets are a number of pixels. + " Reference: Anchor Class at + " https://learn.microsoft.com/en-us/dotnet/api/documentformat.openxml.vml.spreadsheet.anchor?view=openxml-3.0.1 + lv_right_column = lo_comment->get_right_column( ). + lv_bottom_row = lo_comment->get_bottom_row( ). + + lv_right_column_str = lv_right_column. + CONDENSE lv_right_column_str. + lv_bottom_row_str = lv_bottom_row. + CONDENSE lv_bottom_row_str. + + lv_anchor = lc_anchor_init. + REPLACE '&right_column&' WITH lv_right_column_str INTO lv_anchor. + REPLACE '&bottom_row&' WITH lv_bottom_row_str INTO lv_anchor. + lo_element_anchor->set_value( lv_anchor ). + lo_element_clientdata->append_child( new_child = lo_element_anchor ). lo_element_autofill = lo_document->create_simple_element( name = lc_xml_node_autofill parent = lo_document ).