From bcec07b41a7664430e098f2d04499c167c3c6bbe Mon Sep 17 00:00:00 2001 From: Lars Hvam Date: Sun, 5 Nov 2023 11:18:36 +0100 Subject: [PATCH 1/5] fix syntax warning (#1155) --- src/zcl_excel_theme_color_scheme.clas.abap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/zcl_excel_theme_color_scheme.clas.abap b/src/zcl_excel_theme_color_scheme.clas.abap index c5b2222..daba628 100644 --- a/src/zcl_excel_theme_color_scheme.clas.abap +++ b/src/zcl_excel_theme_color_scheme.clas.abap @@ -100,7 +100,7 @@ CLASS zcl_excel_theme_color_scheme IMPLEMENTATION. parent = lo_elements ). lo_scheme_element->set_attribute( name = c_name value = name ). - "! Adding colors to scheme + " Adding colors to scheme lo_color ?= io_document->create_simple_element_ns( prefix = zcl_excel_theme=>c_theme_prefix name = c_dark1 parent = lo_scheme_element ). From a6176d7f1769f95d1a9ce2dc7cd6bda616c53a44 Mon Sep 17 00:00:00 2001 From: Lars Hvam Date: Sun, 5 Nov 2023 11:21:52 +0100 Subject: [PATCH 2/5] replace use of REFFIELD (#1154) --- src/zexcel_s_fieldcatalog.tabl.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/zexcel_s_fieldcatalog.tabl.xml b/src/zexcel_s_fieldcatalog.tabl.xml index f723983..8bdbe28 100644 --- a/src/zexcel_s_fieldcatalog.tabl.xml +++ b/src/zexcel_s_fieldcatalog.tabl.xml @@ -119,7 +119,7 @@ CURRENCY_COLUMN - REFFIELD + ZEXCEL_FIELDNAME 0 E From 1c2607f655548e5afaef7e36e88172e4a888877b Mon Sep 17 00:00:00 2001 From: Lars Hvam Date: Sun, 24 Dec 2023 20:28:06 +0100 Subject: [PATCH 3/5] move ZEXCEL_TR_DOCPROPS_CORE to demos (#1165) --- src/zexcel_tr_docprops_core.xslt.source.xml | 19 ------------------- src/zexcel_tr_docprops_core.xslt.xml | 12 ------------ 2 files changed, 31 deletions(-) delete mode 100644 src/zexcel_tr_docprops_core.xslt.source.xml delete mode 100644 src/zexcel_tr_docprops_core.xslt.xml diff --git a/src/zexcel_tr_docprops_core.xslt.source.xml b/src/zexcel_tr_docprops_core.xslt.source.xml deleted file mode 100644 index 674d63a..0000000 --- a/src/zexcel_tr_docprops_core.xslt.source.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/src/zexcel_tr_docprops_core.xslt.xml b/src/zexcel_tr_docprops_core.xslt.xml deleted file mode 100644 index 0cb8203..0000000 --- a/src/zexcel_tr_docprops_core.xslt.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - ZEXCEL_TR_DOCPROPS_CORE - E - docProps/core.xml - - - - From 76a39a7819d03e15ab362841b93445d9b3054c76 Mon Sep 17 00:00:00 2001 From: sandraros <34005250+sandraros@users.noreply.github.com> Date: Mon, 25 Dec 2023 16:36:58 +0100 Subject: [PATCH 4/5] Make the reader get the Tables (#1159) Fix #1158 Fix #1168 --- src/zcl_excel_reader_2007.clas.abap | 157 ++++++++++++++++++++++++++++ src/zcl_excel_reader_2007.clas.xml | 5 + 2 files changed, 162 insertions(+) diff --git a/src/zcl_excel_reader_2007.clas.abap b/src/zcl_excel_reader_2007.clas.abap index 1c89b39..edbf1de 100644 --- a/src/zcl_excel_reader_2007.clas.abap +++ b/src/zcl_excel_reader_2007.clas.abap @@ -106,6 +106,13 @@ CLASS zcl_excel_reader_2007 DEFINITION END OF t_shared_string . TYPES: t_shared_strings TYPE STANDARD TABLE OF t_shared_string WITH DEFAULT KEY . + TYPES: + BEGIN OF t_table, + id TYPE string, + target TYPE string, + END OF t_table . + TYPES: + t_tables TYPE HASHED TABLE OF t_table WITH UNIQUE KEY id . DATA shared_strings TYPE t_shared_strings . DATA styles TYPE t_style_refs . @@ -268,6 +275,15 @@ CLASS zcl_excel_reader_2007 DEFINITION !io_worksheet TYPE REF TO zcl_excel_worksheet RAISING zcx_excel . + "!

Load worksheet tables

+ METHODS load_worksheet_tables + IMPORTING + io_ixml_worksheet TYPE REF TO if_ixml_document + io_worksheet TYPE REF TO zcl_excel_worksheet + iv_dirname TYPE string + it_tables TYPE t_tables + RAISING + zcx_excel . CLASS-METHODS resolve_path IMPORTING !ip_path TYPE string @@ -2314,6 +2330,7 @@ CLASS zcl_excel_reader_2007 IMPLEMENTATION. 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'. + CONSTANTS lc_rel_table TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/table'. DATA: lo_ixml_worksheet TYPE REF TO if_ixml_document, lo_ixml_cells TYPE REF TO if_ixml_node_collection, @@ -2408,6 +2425,8 @@ CLASS zcl_excel_reader_2007 IMPLEMENTATION. lt_datavalidation_range TYPE TABLE OF string, lt_rtf TYPE zexcel_t_rtf, ex TYPE REF TO cx_root. + DATA lt_tables TYPE t_tables. + DATA ls_table TYPE t_table. FIELD-SYMBOLS: TYPE t_shared_string. @@ -2478,6 +2497,10 @@ CLASS zcl_excel_reader_2007 IMPLEMENTATION. CATCH zcx_excel. ENDTRY. + WHEN lc_rel_table. + MOVE-CORRESPONDING ls_relationship TO ls_table. + INSERT ls_table INTO TABLE lt_tables. + WHEN OTHERS. ENDCASE. @@ -2501,6 +2524,16 @@ CLASS zcl_excel_reader_2007 IMPLEMENTATION. ENDIF. ENDIF. + " Read tables (must be done before loading sheet contents) + TRY. + me->load_worksheet_tables( io_ixml_worksheet = lo_ixml_worksheet + io_worksheet = io_worksheet + iv_dirname = lv_dirname + it_tables = lt_tables ). + CATCH zcx_excel. " Ignore reading errors - pass everything we were able to identify + ENDTRY. + + " Sheet contents lo_ixml_rows = lo_ixml_worksheet->get_elements_by_tag_name_ns( name = 'row' uri = namespace-main ). lo_ixml_iterator = lo_ixml_rows->create_iterator( ). lo_ixml_row_elem ?= lo_ixml_iterator->get_next( ). @@ -3885,6 +3918,130 @@ CLASS zcl_excel_reader_2007 IMPLEMENTATION. ENDMETHOD. + METHOD load_worksheet_tables. + + DATA lo_ixml_table_columns TYPE REF TO if_ixml_node_collection. + DATA lo_ixml_table_column TYPE REF TO if_ixml_element. + DATA lo_ixml_table TYPE REF TO if_ixml_element. + DATA lo_ixml_table_style TYPE REF TO if_ixml_element. + DATA lt_field_catalog TYPE zexcel_t_fieldcatalog. + DATA ls_field_catalog TYPE zexcel_s_fieldcatalog. + DATA lo_ixml_iterator TYPE REF TO if_ixml_node_iterator. + DATA ls_table_settings TYPE zexcel_s_table_settings. + DATA lv_path TYPE string. + DATA lt_components TYPE abap_component_tab. + DATA ls_component TYPE abap_componentdescr. + DATA lo_rtti_table TYPE REF TO cl_abap_tabledescr. + DATA lv_dref_table TYPE REF TO data. + DATA lv_num_lines TYPE i. + DATA lo_line_type TYPE REF TO cl_abap_structdescr. + + DATA: BEGIN OF ls_table, + id TYPE string, + name TYPE string, + displayname TYPE string, + ref TYPE string, + totalsrowshown TYPE string, + END OF ls_table. + + DATA: BEGIN OF ls_table_style, + name TYPE string, + showrowstripes TYPE string, + showcolumnstripes TYPE string, + END OF ls_table_style. + + DATA: BEGIN OF ls_table_column, + id TYPE string, + name TYPE string, + END OF ls_table_column. + + FIELD-SYMBOLS LIKE LINE OF it_tables. + FIELD-SYMBOLS TYPE STANDARD TABLE. + FIELD-SYMBOLS TYPE zexcel_s_fieldcatalog. + + LOOP AT it_tables ASSIGNING . + + CONCATENATE iv_dirname -target INTO lv_path. + lv_path = resolve_path( lv_path ). + + lo_ixml_table = me->get_ixml_from_zip_archive( lv_path )->get_root_element( ). + fill_struct_from_attributes( EXPORTING + ip_element = lo_ixml_table + CHANGING + cp_structure = ls_table ). + + lo_ixml_table_style ?= lo_ixml_table->find_from_name( 'tableStyleInfo' ). + fill_struct_from_attributes( EXPORTING + ip_element = lo_ixml_table_style + CHANGING + cp_structure = ls_table_style ). + + ls_table_settings-table_name = ls_table-name. + ls_table_settings-table_style = ls_table_style-name. + ls_table_settings-show_column_stripes = boolc( ls_table_style-showcolumnstripes = '1' ). + ls_table_settings-show_row_stripes = boolc( ls_table_style-showrowstripes = '1' ). + + zcl_excel_common=>convert_range2column_a_row( + EXPORTING + i_range = ls_table-ref + IMPORTING + e_column_start = ls_table_settings-top_left_column + e_column_end = ls_table_settings-bottom_right_column + e_row_start = ls_table_settings-top_left_row + e_row_end = ls_table_settings-bottom_right_row ). + + lo_ixml_table_columns = lo_ixml_table->get_elements_by_tag_name( name = 'tableColumn' ). + lo_ixml_iterator = lo_ixml_table_columns->create_iterator( ). + lo_ixml_table_column ?= lo_ixml_iterator->get_next( ). + CLEAR lt_field_catalog. + WHILE lo_ixml_table_column IS BOUND. + + CLEAR ls_table_column. + fill_struct_from_attributes( EXPORTING + ip_element = lo_ixml_table_column + CHANGING + cp_structure = ls_table_column ). + + ls_field_catalog-position = lines( lt_field_catalog ) + 1. + ls_field_catalog-fieldname = |COMP_{ ls_field_catalog-position PAD = '0' ALIGN = RIGHT WIDTH = 4 }|. + ls_field_catalog-scrtext_l = ls_table_column-name. + ls_field_catalog-dynpfld = abap_true. + ls_field_catalog-abap_type = cl_abap_typedescr=>typekind_string. + APPEND ls_field_catalog TO lt_field_catalog. + + lo_ixml_table_column ?= lo_ixml_iterator->get_next( ). + + ENDWHILE. + + CLEAR lt_components. + LOOP AT lt_field_catalog ASSIGNING . + CLEAR ls_component. + ls_component-name = -fieldname. + ls_component-type = cl_abap_elemdescr=>get_string( ). + APPEND ls_component TO lt_components. + ENDLOOP. + + lo_line_type = cl_abap_structdescr=>get( lt_components ). + lo_rtti_table = cl_abap_tabledescr=>get( lo_line_type ). + CREATE DATA lv_dref_table TYPE HANDLE lo_rtti_table. + ASSIGN lv_dref_table->* TO . + + lv_num_lines = ls_table_settings-bottom_right_row - ls_table_settings-top_left_row. + DO lv_num_lines TIMES. + APPEND INITIAL LINE TO . + ENDDO. + + io_worksheet->bind_table( + EXPORTING + ip_table = + it_field_catalog = lt_field_catalog + is_table_settings = ls_table_settings ). + + ENDLOOP. + + ENDMETHOD. + + METHOD read_from_applserver. DATA: lv_filelength TYPE i, diff --git a/src/zcl_excel_reader_2007.clas.xml b/src/zcl_excel_reader_2007.clas.xml index d7843d3..e03ffa7 100644 --- a/src/zcl_excel_reader_2007.clas.xml +++ b/src/zcl_excel_reader_2007.clas.xml @@ -253,6 +253,11 @@ E Loads pagemargings of worksheet + + LOAD_WORKSHEET_TABLES + E + Load worksheet tables + MT_DXF_STYLES E From 92809a41e342db00dca2031ef2cdd1597f98e7bf Mon Sep 17 00:00:00 2001 From: HuprichTo <45813255+HuprichT@users.noreply.github.com> Date: Thu, 11 Jan 2024 17:35:46 +0100 Subject: [PATCH 5/5] Fix unescape string value when not escpaped (#1160) * BUGFIX: Skip Input without escaped Character Some special Values, e.g. "TEST_X" were handled like it was an escaped Character, thats because it was not checked if the second conition, an "_" behind it was there * Adjust Package Description to its Original * Remove commented Code Was there for testing, not needed anymore * Downport to 7.02 Adjust Method Call to apply 7.02 Syntax * Fix abaplint Issues * Fix abaplint Issues (again) --------- Fix #1122 Co-authored-by: sandraros <34005250+sandraros@users.noreply.github.com> --- src/zcl_excel_reader_2007.clas.abap | 51 ++++++++++++++----- ...cl_excel_reader_2007.clas.testclasses.abap | 15 ++++++ 2 files changed, 53 insertions(+), 13 deletions(-) diff --git a/src/zcl_excel_reader_2007.clas.abap b/src/zcl_excel_reader_2007.clas.abap index edbf1de..9eef36a 100644 --- a/src/zcl_excel_reader_2007.clas.abap +++ b/src/zcl_excel_reader_2007.clas.abap @@ -306,7 +306,12 @@ CLASS zcl_excel_reader_2007 DEFINITION iv_path TYPE string !ip_excel TYPE REF TO zcl_excel RAISING - zcx_excel . + zcx_excel. + METHODS provided_string_is_escaped + IMPORTING + !value TYPE string + RETURNING + VALUE(is_escaped) TYPE abap_bool. CONSTANTS: BEGIN OF namespace, x14ac TYPE string VALUE 'http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac', @@ -4280,17 +4285,21 @@ CLASS zcl_excel_reader_2007 IMPLEMENTATION. METHOD unescape_string_value. - DATA: lt_character_positions TYPE TABLE OF i, - lv_character_position TYPE i, - lv_character_position_plus_2 TYPE i, - lv_character_position_plus_6 TYPE i, - lv_unescaped_value TYPE string. + DATA: + "Marks the Position before the searched Pattern occurs in the String + "For example in String A_X_TEST_X, the Table is filled with 1 and 8 + lt_character_positions TYPE TABLE OF i, + lv_character_position TYPE i, + lv_character_position_plus_2 TYPE i, + lv_character_position_plus_6 TYPE i, + lv_unescaped_value TYPE string. - " The text "_x...._", with "_x" not "_X", with exactly 4 ".", each being 0-9 a-f or A-F (case insensitive), is interpreted - " like Unicode character U+.... (e.g. "_x0041_" is rendered like "A") is for characters. + " The text "_x...._", with "_x" not "_X". Each "." represents one character, being 0-9 a-f or A-F (case insensitive), + " is interpreted like Unicode character U+.... (e.g. "_x0041_" is rendered like "A") is for characters. " To not interpret it, Excel replaces the first "_" with "_x005f_". result = i_value. - IF result CS '_x'. + + IF provided_string_is_escaped( i_value ) = abap_true. CLEAR lt_character_positions. APPEND sy-fdpos TO lt_character_positions. lv_character_position = sy-fdpos + 1. @@ -4303,10 +4312,11 @@ CLASS zcl_excel_reader_2007 IMPLEMENTATION. LOOP AT lt_character_positions INTO lv_character_position. lv_character_position_plus_2 = lv_character_position + 2. lv_character_position_plus_6 = lv_character_position + 6. - IF substring( val = result off = lv_character_position_plus_2 len = 4 ) CO '0123456789ABCDEFGHIJKLMNOPQRSTUVWabcdefghijklmnopqrstuvw' - AND substring( val = result off = lv_character_position_plus_6 len = 1 ) = '_'. - lv_unescaped_value = cl_abap_conv_in_ce=>uccp( to_upper( substring( val = result off = lv_character_position_plus_2 len = 4 ) ) ). - REPLACE SECTION OFFSET lv_character_position LENGTH 7 OF result WITH lv_unescaped_value. + IF substring( val = result off = lv_character_position_plus_2 len = 4 ) CO '0123456789ABCDEFabcdef'. + IF substring( val = result off = lv_character_position_plus_6 len = 1 ) = '_'. + lv_unescaped_value = cl_abap_conv_in_ce=>uccp( to_upper( substring( val = result off = lv_character_position_plus_2 len = 4 ) ) ). + REPLACE SECTION OFFSET lv_character_position LENGTH 7 OF result WITH lv_unescaped_value. + ENDIF. ENDIF. ENDLOOP. ENDIF. @@ -4429,4 +4439,19 @@ CLASS zcl_excel_reader_2007 IMPLEMENTATION. iv_zcl_excel_classname = iv_zcl_excel_classname ). ENDMETHOD. + METHOD provided_string_is_escaped. + + "Check if passed value is really an escaped Character + IF value CS '_x'. + is_escaped = abap_true. + TRY. + IF substring( val = value off = sy-fdpos + 6 len = 1 ) <> '_'. + is_escaped = abap_false. + ENDIF. + CATCH cx_sy_range_out_of_bounds. + is_escaped = abap_false. + ENDTRY. + ENDIF. + ENDMETHOD. + ENDCLASS. diff --git a/src/zcl_excel_reader_2007.clas.testclasses.abap b/src/zcl_excel_reader_2007.clas.testclasses.abap index 8d0f7a9..9d47491 100644 --- a/src/zcl_excel_reader_2007.clas.testclasses.abap +++ b/src/zcl_excel_reader_2007.clas.testclasses.abap @@ -15,6 +15,7 @@ CLASS ltc_unescape_string_value DEFINITION METHODS no_escaping FOR TESTING. METHODS one_escaped_character FOR TESTING. METHODS two_escaped_characters FOR TESTING. + METHODS skip_when_not_escaped FOR TESTING RAISING cx_static_check. METHODS run_cut IMPORTING @@ -52,4 +53,18 @@ CLASS ltc_unescape_string_value IMPLEMENTATION. run_cut( input = '_x0000_ and _xFFFF_' exp = |{ cl_abap_conv_in_ce=>uccp( '0000' ) } and { cl_abap_conv_in_ce=>uccp( 'FFFF' ) }| ). ENDMETHOD. + METHOD skip_when_not_escaped. + DATA: lo_excel TYPE REF TO zcl_excel_reader_2007, + value TYPE string VALUE 'TEST_X'. + + CREATE OBJECT lo_excel. + + "Method is used to check for "_x", but its not an escaped charcater, output should input. + lo_excel->unescape_string_value( i_value = value ). + + cl_abap_unit_assert=>assert_equals( + exp = value + act = value ). + ENDMETHOD. + ENDCLASS.