mirror of
https://github.com/abap2xlsx/abap2xlsx.git
synced 2025-05-05 22:07:30 +08:00
Merge branch 'main' into hvam/font2907
This commit is contained in:
commit
204a96546d
|
@ -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 .
|
||||
"! <p class="shorttext synchronized" lang="en">Load worksheet tables</p>
|
||||
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
|
||||
|
@ -290,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',
|
||||
|
@ -2314,6 +2335,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 +2430,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:
|
||||
<ls_shared_string> TYPE t_shared_string.
|
||||
|
@ -2478,6 +2502,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 +2529,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 +3923,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 <ls_table> LIKE LINE OF it_tables.
|
||||
FIELD-SYMBOLS <lt_table> TYPE STANDARD TABLE.
|
||||
FIELD-SYMBOLS <ls_field> TYPE zexcel_s_fieldcatalog.
|
||||
|
||||
LOOP AT it_tables ASSIGNING <ls_table>.
|
||||
|
||||
CONCATENATE iv_dirname <ls_table>-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 <ls_field>.
|
||||
CLEAR ls_component.
|
||||
ls_component-name = <ls_field>-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 <lt_table>.
|
||||
|
||||
lv_num_lines = ls_table_settings-bottom_right_row - ls_table_settings-top_left_row.
|
||||
DO lv_num_lines TIMES.
|
||||
APPEND INITIAL LINE TO <lt_table>.
|
||||
ENDDO.
|
||||
|
||||
io_worksheet->bind_table(
|
||||
EXPORTING
|
||||
ip_table = <lt_table>
|
||||
it_field_catalog = lt_field_catalog
|
||||
is_table_settings = ls_table_settings ).
|
||||
|
||||
ENDLOOP.
|
||||
|
||||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD read_from_applserver.
|
||||
|
||||
DATA: lv_filelength TYPE i,
|
||||
|
@ -4123,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.
|
||||
|
@ -4146,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.
|
||||
|
@ -4272,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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -253,6 +253,11 @@
|
|||
<LANGU>E</LANGU>
|
||||
<DESCRIPT>Loads pagemargings of worksheet</DESCRIPT>
|
||||
</SEOCOMPOTX>
|
||||
<SEOCOMPOTX>
|
||||
<CMPNAME>LOAD_WORKSHEET_TABLES</CMPNAME>
|
||||
<LANGU>E</LANGU>
|
||||
<DESCRIPT>Load worksheet tables</DESCRIPT>
|
||||
</SEOCOMPOTX>
|
||||
<SEOCOMPOTX>
|
||||
<CMPNAME>MT_DXF_STYLES</CMPNAME>
|
||||
<LANGU>E</LANGU>
|
||||
|
|
|
@ -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 ).
|
||||
|
|
|
@ -119,7 +119,7 @@
|
|||
</DD03P>
|
||||
<DD03P>
|
||||
<FIELDNAME>CURRENCY_COLUMN</FIELDNAME>
|
||||
<ROLLNAME>REFFIELD</ROLLNAME>
|
||||
<ROLLNAME>ZEXCEL_FIELDNAME</ROLLNAME>
|
||||
<ADMINFIELD>0</ADMINFIELD>
|
||||
<COMPTYPE>E</COMPTYPE>
|
||||
</DD03P>
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
<?sap.transform simple?>
|
||||
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
|
||||
|
||||
<tt:root name="ROOT"/>
|
||||
|
||||
<tt:template>
|
||||
|
||||
<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi=
|
||||
"http://www.w3.org/2001/XMLSchema-instance" tt:ref="ROOT" tt:extensible="deep-dynamic">
|
||||
<dc:creator tt:value-ref="CREATOR"/>
|
||||
<dc:description tt:value-ref="DESCRIPTION"/>
|
||||
<cp:lastModifiedBy tt:value-ref="LAST_MODIFIED_BY"/>
|
||||
<dcterms:created tt:value-ref="CREATED" xsi:type="dcterms:W3CDTF"/>
|
||||
<dcterms:modified tt:value-ref="MODIFIED" xsi:type="dcterms:W3CDTF"/>
|
||||
</cp:coreProperties>
|
||||
|
||||
</tt:template>
|
||||
|
||||
</tt:transform>
|
|
@ -1,12 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<abapGit version="v1.0.0" serializer="LCL_OBJECT_XSLT" serializer_version="v1.0.0">
|
||||
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
|
||||
<asx:values>
|
||||
<ATTRIBUTES>
|
||||
<XSLTDESC>ZEXCEL_TR_DOCPROPS_CORE</XSLTDESC>
|
||||
<LANGU>E</LANGU>
|
||||
<DESCRIPT>docProps/core.xml</DESCRIPT>
|
||||
</ATTRIBUTES>
|
||||
</asx:values>
|
||||
</asx:abap>
|
||||
</abapGit>
|
Loading…
Reference in New Issue
Block a user