abap2xlsx/ZA2X/CLAS/ZCL_EXCEL_READER_2007.slnk
2012-12-02 09:46:47 +00:00

2793 lines
140 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<CLAS CLSNAME="ZCL_EXCEL_READER_2007" VERSION="1" LANGU="E" DESCRIPT="Read Excel 2007 into ZCL_EXCEL" UUID="DFAC2E4C81CE84F1B39B000C29B7D360" CATEGORY="00" EXPOSURE="2" STATE="1" RELEASE="0" CLSCCINCL="X" FIXPT="X" UNICODE="X" CLSBCCAT="00" DURATION_TYPE="0 " RISK_LEVEL="0 ">
<types CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="T_RELATIONSHIP" VERSION="1" LANGU="E" EXPOSURE="1" STATE="1" EDITORDER="1 " TYPTYPE="4" SRCROW1="6 " SRCCOLUMN1="4 " SRCROW2="12 " SRCCOLUMN2="29 " TYPESRC_LENG="326 " TYPESRC='BEGIN OF t_relationship,
id TYPE string,
type TYPE string,
target TYPE string,
worksheet TYPE REF TO zcl_excel_worksheet,
sheetid type string, &quot;ins #235 - repeat rows/cols - needed to identify correct sheet
END OF t_relationship
'/>
<types CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="T_FILEVERSION" VERSION="1" LANGU="E" EXPOSURE="1" STATE="1" EDITORDER="2 " TYPTYPE="4" SRCROW1="14 " SRCCOLUMN1="4 " SRCROW2="20 " SRCCOLUMN2="26 " TYPESRC_LENG="254 " TYPESRC="BEGIN OF t_fileversion,
appname TYPE string,
lastedited TYPE string,
lowestedited TYPE string,
rupbuild TYPE string,
codename TYPE string,
END OF t_fileversion
"/>
<types CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="T_SHEET" VERSION="1" LANGU="E" EXPOSURE="1" STATE="1" EDITORDER="3 " TYPTYPE="4" SRCROW1="22 " SRCCOLUMN1="4 " SRCROW2="27 " SRCCOLUMN2="22 " TYPESRC_LENG="188 " TYPESRC="BEGIN OF t_sheet,
name TYPE string,
sheetid TYPE string,
id TYPE string,
state TYPE string,
END OF t_sheet
"/>
<types CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="T_WORKBOOKPR" VERSION="1" LANGU="E" EXPOSURE="1" STATE="1" EDITORDER="4 " TYPTYPE="4" SRCROW1="29 " SRCCOLUMN1="4 " SRCROW2="32 " SRCCOLUMN2="27 " TYPESRC_LENG="150 " TYPESRC="BEGIN OF t_workbookpr,
codename TYPE string,
defaultthemeversion TYPE string,
END OF t_workbookpr
"/>
<types CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="T_SHEETPR" VERSION="1" LANGU="E" EXPOSURE="1" STATE="1" EDITORDER="5 " TYPTYPE="4" SRCROW1="34 " SRCCOLUMN1="4 " SRCROW2="36 " SRCCOLUMN2="24 " TYPESRC_LENG="96 " TYPESRC="BEGIN OF t_sheetpr,
codename TYPE string,
END OF t_sheetpr
"/>
<types CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="T_RANGE" VERSION="1" LANGU="E" EXPOSURE="1" STATE="1" EDITORDER="6 " TYPTYPE="4" SRCROW1="38 " SRCCOLUMN1="4 " SRCROW2="42 " SRCCOLUMN2="22 " TYPESRC_LENG="266 " TYPESRC="BEGIN OF t_range,
name TYPE string,
hidden type string, &quot;inserted with issue #235 because Autofilters didn&apos;t passthrough
localsheetid TYPE string, &quot; issue #163
END OF t_range
"/>
<types CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="T_FILLS" VERSION="1" LANGU="E" EXPOSURE="1" STATE="1" EDITORDER="7 " TYPTYPE="4" SRCROW1="44 " SRCCOLUMN1="4 " SRCROW2="44 " SRCCOLUMN2="91 " TYPESRC_LENG="90 " TYPESRC="t_fills TYPE STANDARD TABLE OF REF TO zcl_excel_style_fill WITH NON-UNIQUE DEFAULT KEY
"/>
<types CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="T_BORDERS" VERSION="1" LANGU="E" EXPOSURE="1" STATE="1" EDITORDER="8 " TYPTYPE="4" SRCROW1="46 " SRCCOLUMN1="4 " SRCROW2="46 " SRCCOLUMN2="94 " TYPESRC_LENG="93 " TYPESRC="t_borders TYPE STANDARD TABLE OF REF TO zcl_excel_style_borders WITH NON-UNIQUE DEFAULT KEY
"/>
<types CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="T_FONTS" VERSION="1" LANGU="E" EXPOSURE="1" STATE="1" EDITORDER="9 " TYPTYPE="4" SRCROW1="48 " SRCCOLUMN1="4 " SRCROW2="48 " SRCCOLUMN2="91 " TYPESRC_LENG="90 " TYPESRC="t_fonts TYPE STANDARD TABLE OF REF TO zcl_excel_style_font WITH NON-UNIQUE DEFAULT KEY
"/>
<types CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="T_STYLE_REFS" VERSION="1" LANGU="E" EXPOSURE="1" STATE="1" EDITORDER="10 " TYPTYPE="4" SRCROW1="50 " SRCCOLUMN1="4 " SRCROW2="50 " SRCCOLUMN2="89 " TYPESRC_LENG="88 " TYPESRC="t_style_refs TYPE STANDARD TABLE OF REF TO zcl_excel_style WITH NON-UNIQUE DEFAULT KEY
"/>
<types CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="T_NUM_FORMAT" VERSION="1" LANGU="E" EXPOSURE="1" STATE="1" EDITORDER="11 " TYPTYPE="4" SRCROW1="52 " SRCCOLUMN1="4 " SRCROW2="55 " SRCCOLUMN2="20 " TYPESRC_LENG="123 " TYPESRC="BEGIN OF t_num_format,
id TYPE string,
format TYPE REF TO zcl_excel_style_number_format,
END OF t_num_format
"/>
<types CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="T_NUM_FORMATS" VERSION="1" LANGU="E" EXPOSURE="1" STATE="1" EDITORDER="12 " TYPTYPE="4" SRCROW1="57 " SRCCOLUMN1="4 " SRCROW2="57 " SRCCOLUMN2="69 " TYPESRC_LENG="68 " TYPESRC="t_num_formats TYPE HASHED TABLE OF t_num_format WITH UNIQUE KEY id
"/>
<types CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="T_COLOR" VERSION="1" LANGU="E" EXPOSURE="1" STATE="1" EDITORDER="13 " TYPTYPE="4" SRCROW1="59 " SRCCOLUMN1="4 " SRCROW2="64 " SRCCOLUMN2="15 " TYPESRC_LENG="132 " TYPESRC="BEGIN OF t_color,
indexed TYPE string,
rgb TYPE string,
theme TYPE string,
tint TYPE string,
END OF t_color
"/>
<types CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="T_REL_DRAWING" VERSION="1" LANGU="E" EXPOSURE="1" STATE="1" EDITORDER="14 " TYPTYPE="4" SRCROW1="66 " SRCCOLUMN1="4 " SRCROW2="71 " SRCCOLUMN2="23 " TYPESRC_LENG="181 " TYPESRC="BEGIN OF t_rel_drawing,
id TYPE string,
content TYPE xstring,
file_ext TYPE string,
content_xml TYPE REF TO IF_IXML_DOCUMENT,
END OF t_rel_drawing
"/>
<types CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="T_REL_DRAWINGS" VERSION="1" LANGU="E" EXPOSURE="1" STATE="1" EDITORDER="15 " TYPTYPE="4" SRCROW1="73 " SRCCOLUMN1="4 " SRCROW2="73 " SRCCOLUMN2="82 " TYPESRC_LENG="81 " TYPESRC="t_rel_drawings TYPE STANDARD TABLE OF t_rel_drawing WITH NON-UNIQUE DEFAULT KEY
"/>
<implementing CLSNAME="ZCL_EXCEL_READER_2007" REFCLSNAME="ZIF_EXCEL_READER" VERSION="1" EXPOSURE="2" STATE="1" RELTYPE="1"/>
<publicSection>class ZCL_EXCEL_READER_2007 definition
public
create public .
public section.
*&quot;* public components of class ZCL_EXCEL_READER_2007
*&quot;* do not include other source files here!!!
type-pools IXML .
interfaces ZIF_EXCEL_READER .
class-methods FILL_STRUCT_FROM_ATTRIBUTES
importing
!IP_ELEMENT type ref to IF_IXML_ELEMENT
changing
!CP_STRUCTURE type ANY .</publicSection>
<protectedSection>protected section.
*&quot;* protected components of class ZCL_EXCEL_READER_2007
*&quot;* do not include other source files here!!!
types:
BEGIN OF t_relationship,
id TYPE string,
type TYPE string,
target TYPE string,
worksheet TYPE REF TO zcl_excel_worksheet,
sheetid type string, &quot;ins #235 - repeat rows/cols - needed to identify correct sheet
END OF t_relationship .
types:
BEGIN OF t_fileversion,
appname TYPE string,
lastedited TYPE string,
lowestedited TYPE string,
rupbuild TYPE string,
codename TYPE string,
END OF t_fileversion .
types:
BEGIN OF t_sheet,
name TYPE string,
sheetid TYPE string,
id TYPE string,
state TYPE string,
END OF t_sheet .
types:
BEGIN OF t_workbookpr,
codename TYPE string,
defaultthemeversion TYPE string,
END OF t_workbookpr .
types:
BEGIN OF t_sheetpr,
codename TYPE string,
END OF t_sheetpr .
types:
BEGIN OF t_range,
name TYPE string,
hidden type string, &quot;inserted with issue #235 because Autofilters didn&apos;t passthrough
localsheetid TYPE string, &quot; issue #163
END OF t_range .
types:
t_fills TYPE STANDARD TABLE OF REF TO zcl_excel_style_fill WITH NON-UNIQUE DEFAULT KEY .
types:
t_borders TYPE STANDARD TABLE OF REF TO zcl_excel_style_borders WITH NON-UNIQUE DEFAULT KEY .
types:
t_fonts TYPE STANDARD TABLE OF REF TO zcl_excel_style_font WITH NON-UNIQUE DEFAULT KEY .
types:
t_style_refs TYPE STANDARD TABLE OF REF TO zcl_excel_style WITH NON-UNIQUE DEFAULT KEY .
types:
BEGIN OF t_num_format,
id TYPE string,
format TYPE REF TO zcl_excel_style_number_format,
END OF t_num_format .
types:
t_num_formats TYPE HASHED TABLE OF t_num_format WITH UNIQUE KEY id .
types:
BEGIN OF t_color,
indexed TYPE string,
rgb TYPE string,
theme TYPE string,
tint TYPE string,
END OF t_color .
types:
BEGIN OF t_rel_drawing,
id TYPE string,
content TYPE xstring,
file_ext TYPE string,
content_xml TYPE REF TO IF_IXML_DOCUMENT,
END OF t_rel_drawing .
types:
t_rel_drawings TYPE STANDARD TABLE OF t_rel_drawing WITH NON-UNIQUE DEFAULT KEY .
class-methods RESOLVE_PATH
importing
!IP_PATH type STRING
returning
value(RP_RESULT) type STRING .
methods GET_FROM_ZIP_ARCHIVE
importing
!I_FILENAME type STRING
returning
value(R_CONTENT) type XSTRING
raising
ZCX_EXCEL .
methods GET_IXML_FROM_ZIP_ARCHIVE
importing
!I_FILENAME type STRING
!IS_NORMALIZING type BOOLEAN default &apos;X&apos;
returning
value(R_IXML) type ref to IF_IXML_DOCUMENT
raising
ZCX_EXCEL .
methods LOAD_WORKBOOK
importing
!IV_WORKBOOK_FULL_FILENAME type STRING
!IO_EXCEL type ref to ZCL_EXCEL
raising
ZCX_EXCEL .
methods LOAD_DRAWING_ANCHOR
importing
!IO_ANCHOR_ELEMENT type ref to IF_IXML_ELEMENT
!IO_WORKSHEET type ref to ZCL_EXCEL_WORKSHEET
!IT_RELATED_DRAWINGS type T_REL_DRAWINGS .
methods LOAD_WORKSHEET
importing
!IP_PATH type STRING
!IO_WORKSHEET type ref to ZCL_EXCEL_WORKSHEET
raising
ZCX_EXCEL .
methods LOAD_WORKSHEET_DRAWING
importing
!IP_PATH type STRING
!IO_WORKSHEET type ref to ZCL_EXCEL_WORKSHEET
raising
ZCX_EXCEL .
methods LOAD_SHARED_STRINGS
importing
!IP_PATH type STRING
raising
ZCX_EXCEL .
methods LOAD_STYLES
importing
!IP_PATH type STRING
!IP_EXCEL type ref to ZCL_EXCEL
raising
ZCX_EXCEL .
methods LOAD_STYLE_BORDERS
importing
!IP_XML type ref to IF_IXML_DOCUMENT
returning
value(EP_BORDERS) type T_BORDERS .
methods LOAD_STYLE_FILLS
importing
!IP_XML type ref to IF_IXML_DOCUMENT
returning
value(EP_FILLS) type T_FILLS .
methods LOAD_STYLE_FONTS
importing
!IP_XML type ref to IF_IXML_DOCUMENT
returning
value(EP_FONTS) type T_FONTS .
methods LOAD_STYLE_NUM_FORMATS
importing
!IP_XML type ref to IF_IXML_DOCUMENT
returning
value(EP_NUM_FORMATS) type T_NUM_FORMATS .</protectedSection>
<privateSection>*&quot;* private components of class ZCL_EXCEL_READER_2007
*&quot;* do not include other source files here!!!
private section.
data EXCEL2007 type XSTRING .
data ZIP type ref to CL_ABAP_ZIP .
data ALTERNATE_ZIP type ref to OBJECT .
data SHARED_STRINGS type STRINGTAB .
data STYLES type T_STYLE_REFS .</privateSection>
<localImplementation>*&quot;* local class implementation for public class
*&quot;* use this source file for the implementation part of
*&quot;* local helper classes
TYPES: BEGIN OF t_relationship,
id TYPE string,
type TYPE string,
target TYPE string,
END OF t_relationship.</localImplementation>
<localTypes>*&quot;* use this source file for any type declarations (class
*&quot;* definitions, interfaces or data types) you need for method
*&quot;* implementation or private method&apos;s signature</localTypes>
<localMacros>*&quot;* use this source file for any macro definitions you need
*&quot;* in the implementation part of the class</localMacros>
<textPool>
<language SPRAS="E">
<textElement ID="I" KEY="001" ENTRY="A problem occured when reading the file" LENGTH="60 "/>
<textElement ID="I" KEY="002" ENTRY="ZIP parse error" LENGTH="60 "/>
<textElement ID="I" KEY="003" ENTRY="File not found in zip-archive" LENGTH="60 "/>
</language>
</textPool>
<typeUsage CLSNAME="ZCL_EXCEL_READER_2007" TYPEGROUP="IXML" VERSION="1" TPUTYPE="0" EXPLICIT="X"/>
<forwardDeclaration>IXML</forwardDeclaration>
<attribute CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="ALTERNATE_ZIP" VERSION="1" LANGU="E" DESCRIPT="Alternate Zip Utility" EXPOSURE="0" STATE="1" EDITORDER="3 " ATTDECLTYP="0" ATTEXPVIRT="0" TYPTYPE="3" TYPE="OBJECT" SRCROW1="0 " SRCCOLUMN1="0 " SRCROW2="0 " SRCCOLUMN2="0 " TYPESRC_LENG="0 "/>
<attribute CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="EXCEL2007" VERSION="1" LANGU="E" DESCRIPT="Excel 2007 data" EXPOSURE="0" STATE="1" EDITORDER="1 " ATTDECLTYP="0" ATTEXPVIRT="0" TYPTYPE="1" TYPE="XSTRING" SRCROW1="0 " SRCCOLUMN1="0 " SRCROW2="0 " SRCCOLUMN2="0 " TYPESRC_LENG="0 "/>
<attribute CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="SHARED_STRINGS" VERSION="1" LANGU="E" DESCRIPT="Table with Strings" EXPOSURE="0" STATE="1" EDITORDER="4 " ATTDECLTYP="0" ATTEXPVIRT="0" TYPTYPE="1" TYPE="STRINGTAB" SRCROW1="0 " SRCCOLUMN1="0 " SRCROW2="0 " SRCCOLUMN2="0 " TYPESRC_LENG="0 "/>
<attribute CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="STYLES" VERSION="1" LANGU="E" EXPOSURE="0" STATE="1" EDITORDER="5 " ATTDECLTYP="0" ATTEXPVIRT="0" TYPTYPE="1" TYPE="T_STYLE_REFS" SRCROW1="0 " SRCCOLUMN1="0 " SRCROW2="0 " SRCCOLUMN2="0 " TYPESRC_LENG="0 "/>
<attribute CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="ZIP" VERSION="1" LANGU="E" DESCRIPT="Zip Utility" EXPOSURE="0" STATE="1" EDITORDER="2 " ATTDECLTYP="0" ATTEXPVIRT="0" TYPTYPE="3" TYPE="CL_ABAP_ZIP" SRCROW1="0 " SRCCOLUMN1="0 " SRCROW2="0 " SRCCOLUMN2="0 " TYPESRC_LENG="0 "/>
<interfaceMethod CLSNAME="ZCL_EXCEL_READER_2007" CPDNAME="ZIF_EXCEL_READER~CAN_READ_FILE">
<source>method ZIF_EXCEL_READER~CAN_READ_FILE.
*--------------------------------------------------------------------*
* issue #230 - Pimp my Code
* - Stefan Schmöcker, (done) 2012-11-07
* - ...
* changes: nothing done in code
* but started discussion about killing this method
*--------------------------------------------------------------------*
* For now always Unknown
r_readable = abap_undefined.
endmethod.</source>
</interfaceMethod>
<interfaceMethod CLSNAME="ZCL_EXCEL_READER_2007" CPDNAME="ZIF_EXCEL_READER~LOAD">
<source>method ZIF_EXCEL_READER~LOAD.
*--------------------------------------------------------------------*
* ToDos:
* 2do§1 Map Document Properties to ZCL_EXCEL
*--------------------------------------------------------------------*
*--------------------------------------------------------------------*
* issue #230 - Pimp my Code
* - Stefan Schmöcker, (done) 2012-11-07
* - ...
* changes: renaming variables to naming conventions
* removing unused variables
* aligning code
* adding comments to explain what we are trying to achieve
* commenting on problems/future enhancements/todos we already know of or should decide upon
* adding me-&gt; where possible
*--------------------------------------------------------------------*
* issue#234 - error reading xlsx written by libre office
* - Stefan Schmöcker, 2012-11-07
* changes: passing new optional input parameter to private attribute
*--------------------------------------------------------------------*
CONSTANTS: lcv_core_properties TYPE string VALUE &apos;http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties&apos;,
lcv_office_document TYPE string VALUE &apos;http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument&apos;.
DATA: lo_rels TYPE REF TO if_ixml_document,
lo_node TYPE REF TO if_ixml_element,
ls_relationship TYPE t_relationship.
*--------------------------------------------------------------------*
* §1 Create EXCEL-Object we want to return to caller
* §2 We need to read the the file &quot;\\_rels\.rels&quot; because it tells
* us where in this folder structure the data for the workbook
* is located in the xlsx zip-archive
*
* The xlsx Zip-archive has generally the following folder structure:
* &lt;root&gt; |
* |--&gt; _rels
* |--&gt; doc_Props
* |--&gt; xl |
* |--&gt; _rels
* |--&gt; theme
* |--&gt; worksheets
* §3 Extracting from this the path&amp;file where the workbook is located
* Following is an example how this file could be set up
* &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;true&quot;?&gt;
* &lt;Relationships xmlns=&quot;http://schemas.openxmlformats.org/package/2006/relationships&quot;&gt;
* &lt;Relationship Target=&quot;docProps/app.xml&quot; Type=&quot;http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties&quot; Id=&quot;rId3&quot;/&gt;
* &lt;Relationship Target=&quot;docProps/core.xml&quot; Type=&quot;http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties&quot; Id=&quot;rId2&quot;/&gt;
* &lt;Relationship Target=&quot;xl/workbook.xml&quot; Type=&quot;http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument&quot; Id=&quot;rId1&quot;/&gt;
* &lt;/Relationships&gt;
*--------------------------------------------------------------------*
*--------------------------------------------------------------------*
* §1 Create EXCEL-Object we want to return to caller
*--------------------------------------------------------------------*
CREATE OBJECT r_excel.
*--------------------------------------------------------------------*
* issue#234 - error reading xlsx written by libre office
me-&gt;zif_excel_reader~gv_use_alternate_zip = iv_use_alternate_zip.
*--------------------------------------------------------------------*
*--------------------------------------------------------------------*
* §2 Get file in folderstructure
*--------------------------------------------------------------------*
me-&gt;excel2007 = i_excel2007.
lo_rels = me-&gt;get_ixml_from_zip_archive( &apos;_rels/.rels&apos; ).
*--------------------------------------------------------------------*
* §3 Cycle through the Relationship Tags and use the ones we need
*--------------------------------------------------------------------*
lo_node ?= lo_rels-&gt;find_from_name( &apos;Relationship&apos; ). &quot;#EC NOTEXT
WHILE lo_node IS BOUND.
me-&gt;fill_struct_from_attributes( EXPORTING
ip_element = lo_node
CHANGING
cp_structure = ls_relationship ).
CASE ls_relationship-type.
WHEN lcv_core_properties.
&quot; 2do§1 Map Document Properties to ZCL_EXCEL
WHEN lcv_office_document.
me-&gt;load_workbook( iv_workbook_full_filename = ls_relationship-target
io_excel = r_excel ).
WHEN OTHERS.
ENDCASE.
lo_node ?= lo_node-&gt;get_next( ).
ENDWHILE.
endmethod.</source>
</interfaceMethod>
<interfaceMethod CLSNAME="ZCL_EXCEL_READER_2007" CPDNAME="ZIF_EXCEL_READER~LOAD_FILE">
<source>method ZIF_EXCEL_READER~LOAD_FILE.
*--------------------------------------------------------------------*
* ToDos:
* 2do§1 decision whether to load from frontend or backend
* current behavior ( autodecide ) should be default
* add optional parameter to allow user to choose
* to load from backend even when online
* 2do§2 loosen typing of i_filename to CLIKE
*--------------------------------------------------------------------*
*--------------------------------------------------------------------*
* issue #230 - Pimp my Code
* - Stefan Schmöcker, (done) 2012-11-05
* - ...
* changes: renaming variables to naming conventions
* renaming variables to indicate what they are used for
* adding comments to explain what we are trying to achieve
* message made to support multilinguality
* aligning code
* commenting on problems/future enhancements/todos we already know of or should decide upon
* adding issue # that has initiated the change - date provided to allow cleaning of code after a certain period
* explicit declaration of type of table instead of implicit declaration
* added errorhandling for open dataset
*--------------------------------------------------------------------*
* issue#234 - error reading xlsx written by libre office
* - Stefan Schmöcker, 2012-11-07
* changes: passing new optional input parameter to private attribute
*--------------------------------------------------------------------**--------------------------------------------------------------------*
CONSTANTS: lcv_load_from_frontend TYPE char1 VALUE &apos;F&apos;,
lcv_load_from_backend TYPE char1 VALUE &apos;B&apos;.
DATA: lv_load_from_source TYPE char1,
lv_filelength TYPE i,
lt_binary_data TYPE STANDARD TABLE OF x255 WITH NON-UNIQUE DEFAULT KEY,
ls_binary_data LIKE LINE OF lt_binary_data,
* Background processing
lv_max_length_line TYPE i,
lv_actual_length_line TYPE i,
lv_errormessage TYPE string, &quot; Can&apos;t pass &apos;...&apos;(abc) to exception-class
lv_excel_data TYPE xstring. &quot; Binary content of .xlsx file
*--------------------------------------------------------------------*
* ToDos: 2do§1 Decision whether to load from frontend or backend
*--------------------------------------------------------------------*
*--------------------------------------------------------------------*
* issue#234 - error reading xlsx written by libre office
me-&gt;zif_excel_reader~gv_use_alternate_zip = iv_use_alternate_zip.
*--------------------------------------------------------------------*
*--------------------------------------------------------------------*
* Autodecide on frontend or backend reading
* Background-processing --&gt; backend reading
* Online-processing --&gt; frontend reading
*--------------------------------------------------------------------*
IF sy-batch = abap_true.
lv_load_from_source = lcv_load_from_backend.
ELSE.
lv_load_from_source = lcv_load_from_frontend.
ENDIF.
CASE lv_load_from_source.
*--------------------------------------------------------------------*
* Read from backend
*--------------------------------------------------------------------*
WHEN lcv_load_from_backend.
DESCRIBE FIELD ls_binary_data LENGTH lv_max_length_line IN BYTE MODE.
OPEN DATASET i_filename FOR INPUT IN BINARY MODE.
IF sy-subrc &lt;&gt; 0.
lv_errormessage = &apos;A problem occured when reading the file&apos;(001).
RAISE EXCEPTION TYPE zcx_excel
EXPORTING
error = lv_errormessage.
ENDIF.
WHILE sy-subrc = 0.
READ DATASET i_filename INTO ls_binary_data MAXIMUM LENGTH lv_max_length_line ACTUAL LENGTH lv_actual_length_line.
APPEND ls_binary_data TO lt_binary_data.
lv_filelength = lv_filelength + lv_actual_length_line.
ENDWHILE.
CLOSE DATASET i_filename.
*--------------------------------------------------------------------*
* Read from frontend
*--------------------------------------------------------------------*
WHEN lcv_load_from_frontend.
cl_gui_frontend_services=&gt;gui_upload( EXPORTING
filename = i_filename
filetype = &apos;BIN&apos; &quot; We are basically working with zipped directories --&gt; force binary read
IMPORTING
filelength = lv_filelength
CHANGING
data_tab = lt_binary_data
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
not_supported_by_gui = 17
error_no_gui = 18
OTHERS = 19 ).
IF sy-subrc &lt;&gt; 0.
lv_errormessage = &apos;A problem occured when reading the file&apos;(001).
RAISE EXCEPTION TYPE zcx_excel
EXPORTING
error = lv_errormessage.
ENDIF.
ENDCASE.
*--------------------------------------------------------------------*
* Binary data needs to be provided as XSTRING for further processing
*--------------------------------------------------------------------*
CALL FUNCTION &apos;SCMS_BINARY_TO_XSTRING&apos;
EXPORTING
input_length = lv_filelength
IMPORTING
buffer = lv_excel_data
TABLES
binary_tab = lt_binary_data.
*--------------------------------------------------------------------*
* issue#234 - error reading xlsx written by libre office
r_excel = me-&gt;zif_excel_reader~load( i_excel2007 = lv_excel_data
iv_use_alternate_zip = iv_use_alternate_zip ).
*--------------------------------------------------------------------*
endmethod.</source>
</interfaceMethod>
<method CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="FILL_STRUCT_FROM_ATTRIBUTES" VERSION="1" LANGU="E" DESCRIPT="Fills structure fields based on XML node attributes" EXPOSURE="2" STATE="1" EDITORDER="2 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="1" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="FILL_STRUCT_FROM_ATTRIBUTES" SCONAME="IP_ELEMENT" VERSION="1" LANGU="E" DESCRIPT="IF_IXML_ELEMENT" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="3" TYPE="IF_IXML_ELEMENT"/>
<parameter CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="FILL_STRUCT_FROM_ATTRIBUTES" SCONAME="CP_STRUCTURE" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="2 " DISPID="0 " PARDECLTYP="2" PARPASSTYP="1" TYPTYPE="1" TYPE="ANY"/>
<source>method FILL_STRUCT_FROM_ATTRIBUTES.
*--------------------------------------------------------------------*
* issue #230 - Pimp my Code
* - Stefan Schmöcker, (done) 2012-11-07
* - ...
* changes: renaming variables to naming conventions
* aligning code
* adding comments to explain what we are trying to achieve
*--------------------------------------------------------------------*
DATA: lv_name TYPE string,
lo_attributes TYPE REF TO if_ixml_named_node_map,
lo_attribute TYPE REF TO if_ixml_attribute,
lo_iterator TYPE REF TO if_ixml_node_iterator.
FIELD-SYMBOLS: &lt;component&gt; TYPE ANY.
*--------------------------------------------------------------------*
* The values of named attributes of a tag are being read and moved into corresponding
* fields of given structure
* Behaves like move-corresonding tag to structure
* Example:
* &lt;Relationship Target=&quot;docProps/app.xml&quot; Type=&quot;http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties&quot; Id=&quot;rId3&quot;/&gt;
* Here the attributes are Target, Type and Id. Thus if the passed
* structure has fieldnames Id and Target these would be filled with
* &quot;rId3&quot; and &quot;docProps/app.xml&quot; respectively
*--------------------------------------------------------------------*
CLEAR cp_structure.
lo_attributes = ip_element-&gt;get_attributes( ).
lo_iterator = lo_attributes-&gt;create_iterator( ).
lo_attribute ?= lo_iterator-&gt;get_next( ).
WHILE lo_attribute IS BOUND.
lv_name = lo_attribute-&gt;get_name( ).
TRANSLATE lv_name TO UPPER CASE.
ASSIGN COMPONENT lv_name OF STRUCTURE cp_structure TO &lt;component&gt;.
IF sy-subrc = 0.
&lt;component&gt; = lo_attribute-&gt;get_value( ).
ENDIF.
lo_attribute ?= lo_iterator-&gt;get_next( ).
ENDWHILE.
endmethod.</source>
</method>
<method CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="GET_FROM_ZIP_ARCHIVE" VERSION="1" LANGU="E" DESCRIPT="Read file from ZIP Archive" EXPOSURE="1" STATE="1" EDITORDER="2 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="0" MTDNEWEXC="X" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="GET_FROM_ZIP_ARCHIVE" SCONAME="I_FILENAME" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="STRING"/>
<parameter CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="GET_FROM_ZIP_ARCHIVE" SCONAME="R_CONTENT" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="2 " DISPID="0 " PARDECLTYP="3" PARPASSTYP="0" TYPTYPE="1" TYPE="XSTRING"/>
<exception CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="GET_FROM_ZIP_ARCHIVE" SCONAME="ZCX_EXCEL" VERSION="1" LANGU="E" DESCRIPT="Exceptions for ABAP2XLSX" MTDTYPE="0" EDITORDER="1 "/>
<source>method GET_FROM_ZIP_ARCHIVE.
*--------------------------------------------------------------------*
* issue #230 - Pimp my Code
* - Stefan Schmöcker, (done) 2012-11-07
* - ...
* changes: aligning code
* adding comments to explain what we are trying to achieve
* changed message passed with exception
* message made to support multilinguality
*--------------------------------------------------------------------**--------------------------------------------------------------------*
* issue#234 - error reading xlsx written by libre office
* - Stefan Schmöcker, 2012-11-07
* changes: copying coding and using ALTERNATE_ZIP in ELSE-Branch
*--------------------------------------------------------------------*
DATA: lv_errormessage TYPE string. &quot; Can&apos;t pass &apos;...&apos;(abc) to exception-class
*--------------------------------------------------------------------*
* An xlsx-file is basically a zip-archive
* From this zip-archive we need to extract one file in binary form
*--------------------------------------------------------------------*
IF me-&gt;zif_excel_reader~gv_use_alternate_zip IS INITIAL. &quot;+#234
*--------------------------------------------------------------------*
* Setup ABAP zip-class with binary exceldata if not done already
*--------------------------------------------------------------------*
IF me-&gt;zip IS NOT BOUND.
CREATE OBJECT me-&gt;zip.
zip-&gt;load( EXPORTING
zip = me-&gt;excel2007
EXCEPTIONS
zip_parse_error = 1
OTHERS = 2 ).
IF sy-subrc &lt;&gt; 0.
lv_errormessage = &apos;ZIP parse error&apos;(002).
RAISE EXCEPTION TYPE zcx_excel
EXPORTING
error = lv_errormessage.
ENDIF.
ENDIF.
*--------------------------------------------------------------------*
* Extract requested filename from archive if possible
*--------------------------------------------------------------------*
zip-&gt;get( EXPORTING
name = i_filename
IMPORTING
content = r_content &quot; Contents
EXCEPTIONS
zip_index_error = 1
zip_decompression_error = 2
OTHERS = 3 ).
IF sy-subrc &lt;&gt; 0.
lv_errormessage = &apos;File not found in zip-archive&apos;(003).
RAISE EXCEPTION TYPE zcx_excel
EXPORTING
error = lv_errormessage.
ENDIF.
*--------------------------------------------------------------------*
* issue#234 - begin of insertion
*--------------------------------------------------------------------*
ELSE.
*--------------------------------------------------------------------*
* Setup alternate ABAP zip-class with binary exceldata if not done already
* May become obsolete if SAP fixes standard CL_ABAP_ZIP
*--------------------------------------------------------------------*
IF me-&gt;alternate_zip IS NOT BOUND.
CREATE OBJECT me-&gt;alternate_zip TYPE (zif_excel_reader~gv_use_alternate_zip).
TRY.
CALL METHOD me-&gt;alternate_zip-&gt;(&apos;LOAD&apos;)
EXPORTING
zip = me-&gt;excel2007
EXCEPTIONS
zip_parse_error = 1
OTHERS = 2.
CATCH cx_sy_dyn_call_illegal_method.
lv_errormessage = &apos;Method LOAD missing in alternative zipclass&apos;. &quot;#EC NOTEXT This is a workaround until class CL_ABAP_ZIP is fixed
RAISE EXCEPTION TYPE zcx_excel
EXPORTING
error = lv_errormessage.
ENDTRY.
IF sy-subrc &lt;&gt; 0.
lv_errormessage = &apos;ZIP parse error&apos;(002).
RAISE EXCEPTION TYPE zcx_excel
EXPORTING
error = lv_errormessage.
ENDIF.
ENDIF.
*--------------------------------------------------------------------*
* Extract requested filename from archive if possible
*--------------------------------------------------------------------*
TRY.
CALL METHOD me-&gt;alternate_zip-&gt;(&apos;GET&apos;)
EXPORTING
name = i_filename
IMPORTING
content = r_content &quot; Contents
EXCEPTIONS
zip_index_error = 1
zip_decompression_error = 2
OTHERS = 3.
CATCH cx_sy_dyn_call_illegal_method.
lv_errormessage = &apos;Method GET missing in alternative zipclass&apos;. &quot;#EC NOTEXT This is a workaround until class CL_ABAP_ZIP is fixed
RAISE EXCEPTION TYPE zcx_excel
EXPORTING
error = lv_errormessage.
ENDTRY.
IF sy-subrc &lt;&gt; 0.
lv_errormessage = &apos;File not found in zip-archive&apos;(003).
RAISE EXCEPTION TYPE zcx_excel
EXPORTING
error = lv_errormessage.
ENDIF.
ENDIF.
*--------------------------------------------------------------------*
* issue#234 - end of insertion
*--------------------------------------------------------------------*
endmethod.</source>
</method>
<method CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="GET_IXML_FROM_ZIP_ARCHIVE" VERSION="1" LANGU="E" DESCRIPT="Read file from ZIP Archive" EXPOSURE="1" STATE="1" EDITORDER="3 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="0" MTDNEWEXC="X" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="GET_IXML_FROM_ZIP_ARCHIVE" SCONAME="I_FILENAME" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="STRING"/>
<parameter CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="GET_IXML_FROM_ZIP_ARCHIVE" SCONAME="IS_NORMALIZING" VERSION="1" LANGU="E" DESCRIPT="Boolean Variable (X=True, -=False, Space=Unknown)" CMPTYPE="1" MTDTYPE="0" EDITORDER="2 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="BOOLEAN" PARVALUE="&apos;X&apos;" PAROPTIONL="X"/>
<parameter CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="GET_IXML_FROM_ZIP_ARCHIVE" SCONAME="R_IXML" VERSION="1" LANGU="E" DESCRIPT="IF_IXML_DOCUMENT" CMPTYPE="1" MTDTYPE="0" EDITORDER="3 " DISPID="0 " PARDECLTYP="3" PARPASSTYP="0" TYPTYPE="3" TYPE="IF_IXML_DOCUMENT"/>
<exception CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="GET_IXML_FROM_ZIP_ARCHIVE" SCONAME="ZCX_EXCEL" VERSION="1" LANGU="E" DESCRIPT="Exceptions for ABAP2XLSX" MTDTYPE="0" EDITORDER="1 "/>
<source>method GET_IXML_FROM_ZIP_ARCHIVE.
*--------------------------------------------------------------------*
* ToDos:
* 2do§1 Add comment what is being achieved here
*--------------------------------------------------------------------*
*--------------------------------------------------------------------*
* issue #230 - Pimp my Code
* - Stefan Schmöcker, (done) 2012-11-07
* - ...
* changes: renaming variables to naming conventions
* removing unnecessary type-pool
* aligning code
*--------------------------------------------------------------------*
DATA: lv_content TYPE xstring,
lo_ixml TYPE REF TO if_ixml,
lo_streamfactory TYPE REF TO if_ixml_stream_factory,
lo_istream TYPE REF TO if_ixml_istream,
lo_parser TYPE REF TO if_ixml_parser.
*--------------------------------------------------------------------*
* 2do§1 ???? Something happens here ???
*--------------------------------------------------------------------*
lv_content = me-&gt;get_from_zip_archive( i_filename ).
lo_ixml = cl_ixml=&gt;create( ).
lo_streamfactory = lo_ixml-&gt;create_stream_factory( ).
lo_istream = lo_streamfactory-&gt;create_istream_xstring( lv_content ).
r_ixml = lo_ixml-&gt;create_document( ).
lo_parser = lo_ixml-&gt;create_parser( stream_factory = lo_streamfactory
istream = lo_istream
document = r_ixml ).
lo_parser-&gt;set_normalizing( is_normalizing ).
lo_parser-&gt;set_validating( mode = if_ixml_parser=&gt;co_no_validation ).
lo_parser-&gt;parse( ).
endmethod.</source>
</method>
<method CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_DRAWING_ANCHOR" VERSION="1" LANGU="E" DESCRIPT="Loads worksheet" EXPOSURE="1" STATE="1" EDITORDER="5 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="0" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_DRAWING_ANCHOR" SCONAME="IO_ANCHOR_ELEMENT" VERSION="1" LANGU="E" DESCRIPT="IF_IXML_ELEMENT" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="3" TYPE="IF_IXML_ELEMENT"/>
<parameter CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_DRAWING_ANCHOR" SCONAME="IO_WORKSHEET" VERSION="1" LANGU="E" DESCRIPT="Excel creator" CMPTYPE="1" MTDTYPE="0" EDITORDER="2 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="3" TYPE="ZCL_EXCEL_WORKSHEET"/>
<parameter CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_DRAWING_ANCHOR" SCONAME="IT_RELATED_DRAWINGS" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="3 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="T_REL_DRAWINGS"/>
<source>method LOAD_DRAWING_ANCHOR.
TYPES: BEGIN OF t_c_nv_pr,
name TYPE string,
id TYPE string,
END OF t_c_nv_pr.
TYPES: BEGIN OF t_blip,
cstate TYPE string,
embed TYPE string,
END OF t_blip.
TYPES: BEGIN OF t_chart,
id TYPE string,
END OF t_chart.
TYPES: BEGIN OF t_ext,
cx TYPE string,
cy TYPE string,
END OF t_ext.
CONSTANTS: lc_xml_attr_true TYPE string VALUE &apos;true&apos;,
lc_xml_attr_true_int TYPE string VALUE &apos;1&apos;.
CONSTANTS: lc_rel_chart TYPE string VALUE &apos;http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart&apos;,
lc_rel_image TYPE string VALUE &apos;http://schemas.openxmlformats.org/officeDocument/2006/relationships/image&apos;.
DATA: lo_drawing TYPE REF TO zcl_excel_drawing,
node TYPE REF TO if_ixml_element,
node2 TYPE REF TO if_ixml_element,
node3 TYPE REF TO if_ixml_element,
node4 TYPE REF TO if_ixml_element,
ls_upper TYPE zexcel_drawing_location,
ls_lower TYPE zexcel_drawing_location,
ls_size TYPE zexcel_drawing_size,
ext TYPE t_ext,
lv_content TYPE xstring,
lv_relation_id TYPE string,
lv_title TYPE zexcel_sheet_title,
cnvpr TYPE t_c_nv_pr,
blip TYPE t_blip,
chart TYPE t_chart,
drawing_type TYPE zexcel_drawing_type,
rel_drawing TYPE t_rel_drawing.
node ?= io_anchor_element-&gt;find_from_name( name = &apos;from&apos; namespace = &apos;xdr&apos; ).
CHECK node IS NOT INITIAL.
node2 ?= node-&gt;find_from_name( name = &apos;col&apos; namespace = &apos;xdr&apos; ).
ls_upper-col = node2-&gt;get_value( ).
node2 ?= node-&gt;find_from_name( name = &apos;row&apos; namespace = &apos;xdr&apos; ).
ls_upper-row = node2-&gt;get_value( ).
node2 ?= node-&gt;find_from_name( name = &apos;colOff&apos; namespace = &apos;xdr&apos; ).
ls_upper-col_offset = node2-&gt;get_value( ).
node2 ?= node-&gt;find_from_name( name = &apos;rowOff&apos; namespace = &apos;xdr&apos; ).
ls_upper-row_offset = node2-&gt;get_value( ).
node ?= io_anchor_element-&gt;find_from_name( name = &apos;ext&apos; namespace = &apos;xdr&apos; ).
IF node IS INITIAL.
CLEAR ls_size.
ELSE.
me-&gt;fill_struct_from_attributes( EXPORTING ip_element = node CHANGING cp_structure = ext ).
ls_size-width = ext-cx.
ls_size-height = ext-cy.
ENDIF.
node ?= io_anchor_element-&gt;find_from_name( name = &apos;to&apos; namespace = &apos;xdr&apos; ).
IF node IS INITIAL.
CLEAR ls_lower.
ELSE.
node2 ?= node-&gt;find_from_name( name = &apos;col&apos; namespace = &apos;xdr&apos; ).
ls_lower-col = node2-&gt;get_value( ).
node2 ?= node-&gt;find_from_name( name = &apos;row&apos; namespace = &apos;xdr&apos; ).
ls_lower-row = node2-&gt;get_value( ).
node2 ?= node-&gt;find_from_name( name = &apos;colOff&apos; namespace = &apos;xdr&apos; ).
ls_lower-col_offset = node2-&gt;get_value( ).
node2 ?= node-&gt;find_from_name( name = &apos;rowOff&apos; namespace = &apos;xdr&apos; ).
ls_lower-row_offset = node2-&gt;get_value( ).
ENDIF.
node ?= io_anchor_element-&gt;find_from_name( name = &apos;pic&apos; namespace = &apos;xdr&apos; ).
IF node IS NOT INITIAL.
node2 ?= node-&gt;find_from_name( name = &apos;nvPicPr&apos; namespace = &apos;xdr&apos; ).
CHECK node2 IS NOT INITIAL.
node3 ?= node2-&gt;find_from_name( name = &apos;cNvPr&apos; namespace = &apos;xdr&apos; ).
CHECK node3 IS NOT INITIAL.
me-&gt;fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = cnvpr ).
lv_title = cnvpr-name.
node2 ?= node-&gt;find_from_name( name = &apos;blipFill&apos; namespace = &apos;xdr&apos; ).
CHECK node2 IS NOT INITIAL.
node3 ?= node2-&gt;find_from_name( name = &apos;blip&apos; namespace = &apos;a&apos; ).
CHECK node3 IS NOT INITIAL.
me-&gt;fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = blip ).
lv_relation_id = blip-embed.
drawing_type = zcl_excel_drawing=&gt;type_image.
ENDIF.
node ?= io_anchor_element-&gt;find_from_name( name = &apos;graphicFrame&apos; namespace = &apos;xdr&apos; ).
IF node IS NOT INITIAL.
node2 ?= node-&gt;find_from_name( name = &apos;nvGraphicFramePr&apos; namespace = &apos;xdr&apos; ).
CHECK node2 IS NOT INITIAL.
node3 ?= node2-&gt;find_from_name( name = &apos;cNvPr&apos; namespace = &apos;xdr&apos; ).
CHECK node3 IS NOT INITIAL.
me-&gt;fill_struct_from_attributes( EXPORTING ip_element = node3 CHANGING cp_structure = cnvpr ).
lv_title = cnvpr-name.
node2 ?= node-&gt;find_from_name( name = &apos;graphic&apos; namespace = &apos;a&apos; ).
CHECK node2 IS NOT INITIAL.
node3 ?= node2-&gt;find_from_name( name = &apos;graphicData&apos; namespace = &apos;a&apos; ).
CHECK node3 IS NOT INITIAL.
node4 ?= node2-&gt;find_from_name( name = &apos;chart&apos; namespace = &apos;c&apos; ).
CHECK node4 IS NOT INITIAL.
me-&gt;fill_struct_from_attributes( EXPORTING ip_element = node4 CHANGING cp_structure = chart ).
lv_relation_id = chart-id.
drawing_type = zcl_excel_drawing=&gt;type_chart.
ENDIF.
lo_drawing = io_worksheet-&gt;excel-&gt;add_new_drawing(
ip_type = drawing_type
ip_title = lv_title ).
io_worksheet-&gt;add_drawing( lo_drawing ).
lo_drawing-&gt;set_position2(
EXPORTING
ip_from = ls_upper
ip_to = ls_lower ).
READ TABLE it_related_drawings INTO rel_drawing
WITH KEY id = lv_relation_id.
lo_drawing-&gt;set_media(
EXPORTING
ip_media = rel_drawing-content
ip_media_type = rel_drawing-file_ext
ip_width = ls_size-width
ip_height = ls_size-height ).
if drawing_type = zcl_excel_drawing=&gt;type_chart.
&quot;-------------Added by Alessandro Iannacci - Should load chart attributes
lo_drawing-&gt;load_chart_attributes( rel_drawing-content_xml ).
endif.
endmethod.</source>
</method>
<method CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_SHARED_STRINGS" VERSION="1" LANGU="E" DESCRIPT="Loads shared strings table" EXPOSURE="1" STATE="1" EDITORDER="8 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="0" MTDNEWEXC="X" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_SHARED_STRINGS" SCONAME="IP_PATH" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="STRING"/>
<exception CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_SHARED_STRINGS" SCONAME="ZCX_EXCEL" VERSION="1" LANGU="E" DESCRIPT="Exceptions for ABAP2XLSX" MTDTYPE="0" EDITORDER="1 "/>
<source>method LOAD_SHARED_STRINGS.
*--------------------------------------------------------------------*
* ToDos:
* 2do§1 Support partial formatting of strings in cells
*--------------------------------------------------------------------*
*--------------------------------------------------------------------*
* issue #230 - Pimp my Code
* - Stefan Schmöcker, (done) 2012-11-11
* - ...
* changes: renaming variables to naming conventions
* renaming variables to indicate what they are used for
* aligning code
* adding comments to explain what we are trying to achieve
* rewriting code for better readibility
*--------------------------------------------------------------------*
DATA:
lo_shared_strings_xml TYPE REF TO if_ixml_document,
lo_node_si TYPE REF TO if_ixml_element,
lo_node_si_child TYPE REF TO if_ixml_element,
lo_node_r_child_t TYPE REF TO if_ixml_element,
lv_tag_name TYPE string,
lv_node_value TYPE string.
FIELD-SYMBOLS: &lt;lv_shared_string&gt; LIKE LINE OF me-&gt;shared_strings.
*--------------------------------------------------------------------*
* §1 Parse shared strings file and get into internal table
* So far I have encountered 2 ways how a string can be represented in the shared strings file
* §1.1 - &quot;simple&quot; strings
* §1.2 - rich text formatted strings
* Following is an example how this file could be set up; 2 strings in simple formatting, 3rd string rich textformatted
* &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;true&quot;?&gt;
* &lt;sst uniqueCount=&quot;6&quot; count=&quot;6&quot; xmlns=&quot;http://schemas.openxmlformats.org/spreadsheetml/2006/main&quot;&gt;
* &lt;si&gt;
* &lt;t&gt;This is a teststring 1&lt;/t&gt;
* &lt;/si&gt;
* &lt;si&gt;
* &lt;t&gt;This is a teststring 2&lt;/t&gt;
* &lt;/si&gt;
* &lt;si&gt;
* &lt;r&gt;
* &lt;t&gt;T&lt;/t&gt;
* &lt;/r&gt;
* &lt;r&gt;
* &lt;rPr&gt;
* &lt;sz val=&quot;11&quot;/&gt;
* &lt;color rgb=&quot;FFFF0000&quot;/&gt;
* &lt;rFont val=&quot;Calibri&quot;/&gt;
* &lt;family val=&quot;2&quot;/&gt;
* &lt;scheme val=&quot;minor&quot;/&gt;
* &lt;/rPr&gt;
* &lt;t xml:space=&quot;preserve&quot;&gt;his is a &lt;/t&gt;
* &lt;/r&gt;
* &lt;r&gt;
* &lt;rPr&gt;
* &lt;sz val=&quot;11&quot;/&gt;
* &lt;color theme=&quot;1&quot;/&gt;
* &lt;rFont val=&quot;Calibri&quot;/&gt;
* &lt;family val=&quot;2&quot;/&gt;
* &lt;scheme val=&quot;minor&quot;/&gt;
* &lt;/rPr&gt;
* &lt;t&gt;teststring 3&lt;/t&gt;
* &lt;/r&gt;
* &lt;/si&gt;
* &lt;/sst&gt;
*--------------------------------------------------------------------*
lo_shared_strings_xml = me-&gt;get_ixml_from_zip_archive( i_filename = ip_path
is_normalizing = space ). &quot; NO!!! normalizing - otherwise leading blanks will be omitted and that is not really desired for the stringtable
lo_node_si ?= lo_shared_strings_xml-&gt;find_from_name( &apos;si&apos; ).
WHILE lo_node_si IS BOUND.
APPEND INITIAL LINE TO me-&gt;shared_strings ASSIGNING &lt;lv_shared_string&gt;. &quot; Each &lt;si&gt;-entry in the xml-file must lead to an entry in our stringtable
lo_node_si_child ?= lo_node_si-&gt;get_first_child( ).
IF lo_node_si_child IS BOUND.
lv_tag_name = lo_node_si_child-&gt;get_name( ).
IF lv_tag_name = &apos;t&apos;.
*--------------------------------------------------------------------*
* §1.1 - &quot;simple&quot; strings
* Example: see above
*--------------------------------------------------------------------*
&lt;lv_shared_string&gt; = lo_node_si_child-&gt;get_value( ).
ELSE.
*--------------------------------------------------------------------*
* §1.2 - rich text formatted strings
* it is sufficient to strip the &lt;t&gt;...&lt;/t&gt; tag from each &lt;r&gt;-tag and concatenate these
* as long as rich text formatting is not supported (2do§1) ignore all info about formatting
* Example: see above
*--------------------------------------------------------------------*
WHILE lo_node_si_child IS BOUND. &quot; actually these children of &lt;si&gt; are &lt;r&gt;-tags
lo_node_r_child_t ?= lo_node_si_child-&gt;find_from_name( &apos;t&apos; ). &quot; extract the &lt;t&gt;...&lt;/t&gt; part of each &lt;r&gt;-tag
IF lo_node_r_child_t IS BOUND.
lv_node_value = lo_node_r_child_t-&gt;get_value( ).
CONCATENATE &lt;lv_shared_string&gt; lv_node_value INTO &lt;lv_shared_string&gt; RESPECTING BLANKS.
ENDIF.
lo_node_si_child ?= lo_node_si_child-&gt;get_next( ).
ENDWHILE.
ENDIF.
ENDIF.
lo_node_si ?= lo_node_si-&gt;get_next( ).
ENDWHILE.
endmethod.</source>
</method>
<method CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_STYLES" VERSION="1" LANGU="E" DESCRIPT="Loads styles" EXPOSURE="1" STATE="1" EDITORDER="9 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="0" MTDNEWEXC="X" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_STYLES" SCONAME="IP_PATH" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="STRING"/>
<parameter CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_STYLES" SCONAME="IP_EXCEL" VERSION="1" LANGU="E" DESCRIPT="Excel creator" CMPTYPE="1" MTDTYPE="0" EDITORDER="2 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="3" TYPE="ZCL_EXCEL"/>
<exception CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_STYLES" SCONAME="ZCX_EXCEL" VERSION="1" LANGU="E" DESCRIPT="Exceptions for ABAP2XLSX" MTDTYPE="0" EDITORDER="1 "/>
<source>method LOAD_STYLES.
*--------------------------------------------------------------------*
* issue #230 - Pimp my Code
* - Stefan Schmöcker, (wip ) 2012-11-25
* - ...
* changes: renaming variables and types to naming conventions
* aligning code
* adding comments to explain what we are trying to achieve
*--------------------------------------------------------------------*
TYPES: BEGIN OF lty_xf,
applyalignment TYPE string,
applyborder TYPE string,
applyfill TYPE string,
applyfont TYPE string,
applynumberformat TYPE string,
applyprotection TYPE string,
borderid TYPE string,
fillid TYPE string,
fontid TYPE string,
numfmtid TYPE string,
pivotbutton TYPE string,
quoteprefix TYPE string,
xfid TYPE string,
END OF lty_xf.
TYPES: BEGIN OF lty_alignment,
horizontal TYPE string,
indent TYPE string,
justifylastline TYPE string,
readingorder TYPE string,
relativeindent TYPE string,
shrinktofit TYPE string,
textrotation TYPE string,
vertical TYPE string,
wraptext TYPE string,
END OF lty_alignment.
TYPES: BEGIN OF lty_protection,
hidden TYPE string,
locked TYPE string,
END OF lty_protection.
DATA: lo_styles_xml TYPE REF TO if_ixml_document,
lo_style TYPE REF TO zcl_excel_style,
lt_num_formats TYPE t_num_formats,
lt_fills TYPE t_fills,
lt_borders TYPE t_borders,
lt_fonts TYPE t_fonts,
ls_num_format TYPE t_num_format,
ls_fill TYPE REF TO zcl_excel_style_fill,
ls_cell_border TYPE REF TO zcl_excel_style_borders,
ls_font TYPE REF TO zcl_excel_style_font,
lo_node_cellxfs TYPE REF TO if_ixml_element,
lo_node_cellxfs_xf TYPE REF TO if_ixml_element,
lo_node_cellxfs_xf_alignment TYPE REF TO if_ixml_element,
lo_node_cellxfs_xf_protection TYPE REF TO if_ixml_element,
lo_nodes_xf TYPE REF TO if_ixml_node_collection,
lo_iterator_cellxfs TYPE REF TO if_ixml_node_iterator,
ls_xf TYPE lty_xf,
ls_alignment TYPE lty_alignment,
ls_protection TYPE lty_protection,
lv_index TYPE i.
*--------------------------------------------------------------------*
* To build a complete style that fully describes how a cell looks like
* we need the various parts
* §1 - Numberformat
* §2 - Fillstyle
* §3 - Borders
* §4 - Font
* §5 - Alignment
* §6 - Protection
* Following is an example how this part of a file could be set up
* ...
* parts with various formatinformation - see §1,§2,§3,§4
* ...
* &lt;cellXfs count=&quot;26&quot;&gt;
* &lt;xf numFmtId=&quot;0&quot; borderId=&quot;0&quot; fillId=&quot;0&quot; fontId=&quot;0&quot; xfId=&quot;0&quot;/&gt;
* &lt;xf numFmtId=&quot;0&quot; borderId=&quot;0&quot; fillId=&quot;2&quot; fontId=&quot;0&quot; xfId=&quot;0&quot; applyFill=&quot;1&quot;/&gt;
* &lt;xf numFmtId=&quot;0&quot; borderId=&quot;1&quot; fillId=&quot;3&quot; fontId=&quot;0&quot; xfId=&quot;0&quot; applyFill=&quot;1&quot; applyBorder=&quot;1&quot;/&gt;
* &lt;xf numFmtId=&quot;0&quot; borderId=&quot;2&quot; fillId=&quot;3&quot; fontId=&quot;0&quot; xfId=&quot;0&quot; applyFill=&quot;1&quot; applyBorder=&quot;1&quot;/&gt;
* &lt;xf numFmtId=&quot;0&quot; borderId=&quot;3&quot; fillId=&quot;3&quot; fontId=&quot;0&quot; xfId=&quot;0&quot; applyFill=&quot;1&quot; applyBorder=&quot;1&quot;/&gt;
* &lt;xf numFmtId=&quot;0&quot; borderId=&quot;4&quot; fillId=&quot;3&quot; fontId=&quot;0&quot; xfId=&quot;0&quot; applyFill=&quot;1&quot; applyBorder=&quot;1&quot;/&gt;
* &lt;xf numFmtId=&quot;0&quot; borderId=&quot;0&quot; fillId=&quot;3&quot; fontId=&quot;0&quot; xfId=&quot;0&quot; applyFill=&quot;1&quot; applyBorder=&quot;1&quot;/&gt;
* ...
* &lt;/cellXfs&gt;
*--------------------------------------------------------------------*
lo_styles_xml = me-&gt;get_ixml_from_zip_archive( ip_path ).
*--------------------------------------------------------------------*
* The styles are build up from
* §1 number formats
* §2 fill styles
* §3 border styles
* §4 fonts
* These need to be read before we can try to build up a complete
* style that describes the look of a cell
*--------------------------------------------------------------------*
lt_num_formats = load_style_num_formats( lo_styles_xml ). &quot; §1
lt_fills = load_style_fills( lo_styles_xml ). &quot; §2
lt_borders = load_style_borders( lo_styles_xml ). &quot; §3
lt_fonts = load_style_fonts( lo_styles_xml ). &quot; §4
*--------------------------------------------------------------------*
* Now everything is prepared to build a &quot;full&quot; style
*--------------------------------------------------------------------*
lo_node_cellxfs = lo_styles_xml-&gt;find_from_name( name = &apos;cellXfs&apos; ).
IF lo_node_cellxfs IS BOUND.
lo_nodes_xf = lo_node_cellxfs-&gt;get_elements_by_tag_name( name = &apos;xf&apos; ).
lo_iterator_cellxfs = lo_nodes_xf-&gt;create_iterator( ).
lo_node_cellxfs_xf ?= lo_iterator_cellxfs-&gt;get_next( ).
WHILE lo_node_cellxfs_xf IS BOUND.
lo_style = ip_excel-&gt;add_new_style( ).
fill_struct_from_attributes( EXPORTING
ip_element = lo_node_cellxfs_xf
CHANGING
cp_structure = ls_xf ).
*--------------------------------------------------------------------*
* §2 fill style
*--------------------------------------------------------------------*
IF ls_xf-applyfill = &apos;1&apos; AND ls_xf-fillid IS NOT INITIAL.
lv_index = ls_xf-fillid + 1.
READ TABLE lt_fills INTO ls_fill INDEX lv_index.
IF sy-subrc = 0.
lo_style-&gt;fill = ls_fill.
ENDIF.
ENDIF.
*--------------------------------------------------------------------*
* §1 number format
*--------------------------------------------------------------------*
IF ls_xf-numfmtid IS NOT INITIAL.
READ TABLE lt_num_formats INTO ls_num_format WITH TABLE KEY id = ls_xf-numfmtid.
IF sy-subrc = 0.
lo_style-&gt;number_format = ls_num_format-format.
ENDIF.
ENDIF.
*--------------------------------------------------------------------*
* §3 border style
*--------------------------------------------------------------------*
IF ls_xf-applyborder = &apos;1&apos; AND ls_xf-borderid IS NOT INITIAL.
lv_index = ls_xf-borderid + 1.
READ TABLE lt_borders INTO ls_cell_border INDEX lv_index.
IF sy-subrc = 0.
lo_style-&gt;borders = ls_cell_border.
ENDIF.
ENDIF.
*--------------------------------------------------------------------*
* §4 font
*--------------------------------------------------------------------*
IF ls_xf-applyfont = &apos;1&apos; AND ls_xf-fontid IS NOT INITIAL.
lv_index = ls_xf-fontid + 1.
READ TABLE lt_fonts INTO ls_font INDEX lv_index.
IF sy-subrc = 0.
lo_style-&gt;font = ls_font.
ENDIF.
ENDIF.
*--------------------------------------------------------------------*
* §5 - Alignment
*--------------------------------------------------------------------*
lo_node_cellxfs_xf_alignment ?= lo_node_cellxfs_xf-&gt;find_from_name( &apos;alignment&apos; ).
IF lo_node_cellxfs_xf_alignment IS BOUND.
fill_struct_from_attributes( EXPORTING
ip_element = lo_node_cellxfs_xf_alignment
CHANGING
cp_structure = ls_alignment ).
IF ls_alignment-horizontal IS NOT INITIAL.
lo_style-&gt;alignment-&gt;horizontal = ls_alignment-horizontal.
ENDIF.
IF ls_alignment-vertical IS NOT INITIAL.
lo_style-&gt;alignment-&gt;vertical = ls_alignment-vertical.
ENDIF.
IF ls_alignment-textrotation IS NOT INITIAL.
lo_style-&gt;alignment-&gt;textrotation = ls_alignment-textrotation.
ENDIF.
IF ls_alignment-wraptext = &apos;1&apos; OR ls_alignment-wraptext = &apos;true&apos;.
lo_style-&gt;alignment-&gt;wraptext = abap_true.
ENDIF.
IF ls_alignment-shrinktofit = &apos;1&apos; OR ls_alignment-shrinktofit = &apos;true&apos;.
lo_style-&gt;alignment-&gt;shrinktofit = abap_true.
ENDIF.
IF ls_alignment-indent IS NOT INITIAL.
lo_style-&gt;alignment-&gt;indent = ls_alignment-indent.
ENDIF.
ENDIF.
*--------------------------------------------------------------------*
* §6 - Protection
*--------------------------------------------------------------------*
lo_node_cellxfs_xf_protection ?= lo_node_cellxfs_xf-&gt;find_from_name( &apos;protection&apos; ).
IF lo_node_cellxfs_xf_protection IS BOUND.
fill_struct_from_attributes( EXPORTING
ip_element = lo_node_cellxfs_xf_protection
CHANGING
cp_structure = ls_protection ).
IF ls_protection-locked = &apos;1&apos; OR ls_protection-locked = &apos;true&apos;.
lo_style-&gt;protection-&gt;locked = zcl_excel_style_protection=&gt;c_protection_locked.
ELSE.
lo_style-&gt;protection-&gt;locked = zcl_excel_style_protection=&gt;c_protection_unlocked.
ENDIF.
IF ls_protection-hidden = &apos;1&apos; OR ls_protection-hidden = &apos;true&apos;.
lo_style-&gt;protection-&gt;hidden = zcl_excel_style_protection=&gt;c_protection_hidden.
ELSE.
lo_style-&gt;protection-&gt;hidden = zcl_excel_style_protection=&gt;c_protection_unhidden.
ENDIF.
ENDIF.
INSERT lo_style INTO TABLE me-&gt;styles.
lo_node_cellxfs_xf ?= lo_iterator_cellxfs-&gt;get_next( ).
ENDWHILE.
ENDIF.
endmethod.</source>
</method>
<method CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_STYLE_BORDERS" VERSION="1" LANGU="E" DESCRIPT="Loads &apos;borders&apos; part of styles" EXPOSURE="1" STATE="1" EDITORDER="10 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="0" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_STYLE_BORDERS" SCONAME="IP_XML" VERSION="1" LANGU="E" DESCRIPT="IF_IXML_DOCUMENT" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="3" TYPE="IF_IXML_DOCUMENT"/>
<parameter CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_STYLE_BORDERS" SCONAME="EP_BORDERS" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="2 " DISPID="0 " PARDECLTYP="3" PARPASSTYP="0" TYPTYPE="1" TYPE="T_BORDERS"/>
<source>method LOAD_STYLE_BORDERS.
*--------------------------------------------------------------------*
* issue #230 - Pimp my Code
* - Stefan Schmöcker, (done) 2012-11-25
* - ...
* changes: renaming variables and types to naming conventions
* aligning code
* renaming variables to indicate what they are used for
* adding comments to explain what we are trying to achieve
*--------------------------------------------------------------------*
DATA: lo_node_border TYPE REF TO if_ixml_element,
lo_node_bordertype TYPE REF TO if_ixml_element,
lo_node_bordercolor TYPE REF TO if_ixml_element,
lo_cell_border TYPE REF TO zcl_excel_style_borders,
lo_border TYPE REF TO zcl_excel_style_border,
ls_color TYPE t_color.
*--------------------------------------------------------------------*
* We need a table of used borderformats to build up our styles
* §1 A cell has 4 outer borders and 2 diagonal &quot;borders&quot;
* These borders can be formatted separately but the diagonal borders
* are always being formatted the same
* We&apos;ll parse through the &lt;border&gt;-tag for each of the bordertypes
* §2 and read the corresponding formatting information
* Following is an example how this part of a file could be set up
* &lt;border diagonalDown=&quot;1&quot;&gt;
* &lt;left style=&quot;mediumDashDotDot&quot;&gt;
* &lt;color rgb=&quot;FFFF0000&quot;/&gt;
* &lt;/left&gt;
* &lt;right/&gt;
* &lt;top style=&quot;thick&quot;&gt;
* &lt;color rgb=&quot;FFFF0000&quot;/&gt;
* &lt;/top&gt;
* &lt;bottom style=&quot;thick&quot;&gt;
* &lt;color rgb=&quot;FFFF0000&quot;/&gt;
* &lt;/bottom&gt;
* &lt;diagonal style=&quot;thick&quot;&gt;
* &lt;color rgb=&quot;FFFF0000&quot;/&gt;
* &lt;/diagonal&gt;
* &lt;/border&gt;
*--------------------------------------------------------------------*
lo_node_border ?= ip_xml-&gt;find_from_name( &apos;border&apos; ).
WHILE lo_node_border IS BOUND.
CREATE OBJECT lo_cell_border.
*--------------------------------------------------------------------*
* Diagonal borderlines are formatted the equally. Determine what kind of diagonal borders are present if any
*--------------------------------------------------------------------*
* DiagonalNone = 0
* DiagonalUp = 1
* DiagonalDown = 2
* DiagonalBoth = 3
*--------------------------------------------------------------------*
IF lo_node_border-&gt;get_attribute( &apos;diagonalDown&apos; ) IS NOT INITIAL.
add zcl_excel_style_borders=&gt;c_diagonal_down to lo_cell_border-&gt;diagonal_mode.
ENDIF.
IF lo_node_border-&gt;get_attribute( &apos;diagonalUp&apos; ) IS NOT INITIAL.
add zcl_excel_style_borders=&gt;c_diagonal_up to lo_cell_border-&gt;diagonal_mode.
ENDIF.
lo_node_bordertype ?= lo_node_border-&gt;get_first_child( ).
WHILE lo_node_bordertype IS BOUND.
*--------------------------------------------------------------------*
* §1 Determine what kind of border we are talking about
*--------------------------------------------------------------------*
* Up, down, left, right, diagonal
*--------------------------------------------------------------------*
CREATE OBJECT lo_border.
CASE lo_node_bordertype-&gt;get_name( ).
WHEN &apos;left&apos;.
lo_cell_border-&gt;left = lo_border.
WHEN &apos;right&apos;.
lo_cell_border-&gt;right = lo_border.
WHEN &apos;top&apos;.
lo_cell_border-&gt;top = lo_border.
WHEN &apos;bottom&apos;.
lo_cell_border-&gt;down = lo_border.
WHEN &apos;diagonal&apos;.
lo_cell_border-&gt;diagonal = lo_border.
ENDCASE.
*--------------------------------------------------------------------*
* §2 Read the border-formatting
*--------------------------------------------------------------------*
lo_border-&gt;border_style = lo_node_bordertype-&gt;get_attribute( &apos;style&apos; ).
lo_node_bordercolor ?= lo_node_bordertype-&gt;find_from_name( &apos;color&apos; ).
IF lo_node_bordercolor IS BOUND.
fill_struct_from_attributes( EXPORTING
ip_element = lo_node_bordercolor
CHANGING
cp_structure = ls_color ).
lo_border-&gt;border_color-rgb = ls_color-rgb.
IF ls_color-indexed IS NOT INITIAL.
lo_border-&gt;border_color-indexed = ls_color-indexed.
ENDIF.
IF ls_color-theme IS NOT INITIAL.
lo_border-&gt;border_color-theme = ls_color-theme.
ENDIF.
lo_border-&gt;border_color-tint = ls_color-tint.
ENDIF.
lo_node_bordertype ?= lo_node_bordertype-&gt;get_next( ).
ENDWHILE.
INSERT lo_cell_border INTO TABLE ep_borders.
lo_node_border ?= lo_node_border-&gt;get_next( ).
ENDWHILE.
endmethod.</source>
</method>
<method CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_STYLE_FILLS" VERSION="1" LANGU="E" DESCRIPT="Loads &apos;fills&apos; part of styles" EXPOSURE="1" STATE="1" EDITORDER="11 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="0" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_STYLE_FILLS" SCONAME="IP_XML" VERSION="1" LANGU="E" DESCRIPT="IF_IXML_DOCUMENT" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="3" TYPE="IF_IXML_DOCUMENT"/>
<parameter CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_STYLE_FILLS" SCONAME="EP_FILLS" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="2 " DISPID="0 " PARDECLTYP="3" PARPASSTYP="0" TYPTYPE="1" TYPE="T_FILLS"/>
<source>method LOAD_STYLE_FILLS.
*--------------------------------------------------------------------*
* ToDos:
* 2do§1 Support gradientFill
*--------------------------------------------------------------------*
*--------------------------------------------------------------------*
* issue #230 - Pimp my Code
* - Stefan Schmöcker, (done) 2012-11-25
* - ...
* changes: renaming variables and types to naming conventions
* aligning code
* commenting on problems/future enhancements/todos we already know of or should decide upon
* adding comments to explain what we are trying to achieve
* renaming variables to indicate what they are used for
*--------------------------------------------------------------------*
DATA: lv_value TYPE string,
lo_node_fill TYPE REF TO if_ixml_element,
lo_node_fill_child TYPE REF TO if_ixml_element,
lo_node_bgcolor TYPE REF TO if_ixml_element,
lo_node_fgcolor TYPE REF TO if_ixml_element,
lo_fill TYPE REF TO zcl_excel_style_fill,
ls_color TYPE t_color.
*--------------------------------------------------------------------*
* We need a table of used fillformats to build up our styles
* Following is an example how this part of a file could be set up
* &lt;fill&gt;
* &lt;patternFill patternType=&quot;gray125&quot;/&gt;
* &lt;/fill&gt;
* &lt;fill&gt;
* &lt;patternFill patternType=&quot;solid&quot;&gt;
* &lt;fgColor rgb=&quot;FFFFFF00&quot;/&gt;
* &lt;bgColor indexed=&quot;64&quot;/&gt;
* &lt;/patternFill&gt;
* &lt;/fill&gt;
*--------------------------------------------------------------------*
lo_node_fill ?= ip_xml-&gt;find_from_name( &apos;fill&apos; ).
WHILE lo_node_fill IS BOUND.
CREATE OBJECT lo_fill.
lo_node_fill_child ?= lo_node_fill-&gt;get_first_child( ).
lv_value = lo_node_fill_child-&gt;get_name( ).
CASE lv_value.
*--------------------------------------------------------------------*
* Patternfill
*--------------------------------------------------------------------*
WHEN &apos;patternFill&apos;.
lo_fill-&gt;filltype = lo_node_fill_child-&gt;get_attribute( &apos;patternType&apos; ).
*--------------------------------------------------------------------*
* Patternfill - background color
*--------------------------------------------------------------------*
lo_node_bgcolor = lo_node_fill_child-&gt;find_from_name( &apos;bgColor&apos; ).
IF lo_node_bgcolor IS BOUND.
fill_struct_from_attributes( EXPORTING
ip_element = lo_node_bgcolor
CHANGING
cp_structure = ls_color ).
lo_fill-&gt;bgcolor-rgb = ls_color-rgb.
IF ls_color-indexed IS NOT INITIAL.
lo_fill-&gt;bgcolor-indexed = ls_color-indexed.
ENDIF.
IF ls_color-theme IS NOT INITIAL.
lo_fill-&gt;bgcolor-theme = ls_color-theme.
ENDIF.
lo_fill-&gt;bgcolor-tint = ls_color-tint.
ENDIF.
*--------------------------------------------------------------------*
* Patternfill - foreground color
*--------------------------------------------------------------------*
lo_node_fgcolor = lo_node_fill-&gt;find_from_name( &apos;fgColor&apos; ).
IF lo_node_fgcolor IS BOUND.
fill_struct_from_attributes( EXPORTING
ip_element = lo_node_fgcolor
CHANGING
cp_structure = ls_color ).
lo_fill-&gt;fgcolor-rgb = ls_color-rgb.
IF ls_color-indexed IS NOT INITIAL.
lo_fill-&gt;fgcolor-indexed = ls_color-indexed.
ENDIF.
IF ls_color-theme IS NOT INITIAL.
lo_fill-&gt;fgcolor-theme = ls_color-theme.
ENDIF.
lo_fill-&gt;fgcolor-tint = ls_color-tint.
ENDIF.
*--------------------------------------------------------------------*
* gradientFill
*--------------------------------------------------------------------*
WHEN &apos;gradientFill&apos;.
&quot; 2do§1 Support gradientFill
WHEN OTHERS.
ENDCASE.
INSERT lo_fill INTO TABLE ep_fills.
lo_node_fill ?= lo_node_fill-&gt;get_next( ).
ENDWHILE.
endmethod.</source>
</method>
<method CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_STYLE_FONTS" VERSION="1" LANGU="E" DESCRIPT="Loads &apos;fonts&apos; part of styles" EXPOSURE="1" STATE="1" EDITORDER="12 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="0" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_STYLE_FONTS" SCONAME="IP_XML" VERSION="1" LANGU="E" DESCRIPT="IF_IXML_DOCUMENT" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="3" TYPE="IF_IXML_DOCUMENT"/>
<parameter CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_STYLE_FONTS" SCONAME="EP_FONTS" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="2 " DISPID="0 " PARDECLTYP="3" PARPASSTYP="0" TYPTYPE="1" TYPE="T_FONTS"/>
<source>method LOAD_STYLE_FONTS.
*--------------------------------------------------------------------*
* issue #230 - Pimp my Code
* - Stefan Schmöcker, (done) 2012-11-25
* - ...
* changes: renaming variables and types to naming conventions
* aligning code
* removing unused variables
* adding comments to explain what we are trying to achieve
*--------------------------------------------------------------------*
DATA: lo_node_font TYPE REF TO if_ixml_element,
lo_node2 TYPE REF TO if_ixml_element,
lo_font TYPE REF TO zcl_excel_style_font,
ls_color TYPE t_color.
*--------------------------------------------------------------------*
* We need a table of used fonts to build up our styles
* Following is an example how this part of a file could be set up
* &lt;font&gt;
* &lt;sz val=&quot;11&quot;/&gt;
* &lt;color theme=&quot;1&quot;/&gt;
* &lt;name val=&quot;Calibri&quot;/&gt;
* &lt;family val=&quot;2&quot;/&gt;
* &lt;scheme val=&quot;minor&quot;/&gt;
* &lt;/font&gt;
*--------------------------------------------------------------------*
lo_node_font ?= ip_xml-&gt;find_from_name( &apos;font&apos; ).
WHILE lo_node_font IS BOUND.
CREATE OBJECT lo_font.
*--------------------------------------------------------------------*
* Bold
*--------------------------------------------------------------------*
IF lo_node_font-&gt;find_from_name( &apos;b&apos; ) IS BOUND.
lo_font-&gt;bold = abap_true.
ENDIF.
*--------------------------------------------------------------------*
* Italic
*--------------------------------------------------------------------*
IF lo_node_font-&gt;find_from_name( &apos;i&apos; ) IS BOUND.
lo_font-&gt;italic = abap_true.
ENDIF.
*--------------------------------------------------------------------*
* Underline
*--------------------------------------------------------------------*
lo_node2 = lo_node_font-&gt;find_from_name( &apos;u&apos; ).
IF lo_node2 IS BOUND.
lo_font-&gt;underline = abap_true.
lo_font-&gt;underline_mode = lo_node2-&gt;get_attribute( &apos;val&apos; ).
ENDIF.
*--------------------------------------------------------------------*
* StrikeThrough
*--------------------------------------------------------------------*
IF lo_node_font-&gt;find_from_name( &apos;strike&apos; ) IS BOUND.
lo_font-&gt;strikethrough = abap_true.
ENDIF.
*--------------------------------------------------------------------*
* Fontsize
*--------------------------------------------------------------------*
lo_node2 = lo_node_font-&gt;find_from_name( &apos;sz&apos; ).
IF lo_node2 IS BOUND.
lo_font-&gt;size = lo_node2-&gt;get_attribute( &apos;val&apos; ).
ENDIF.
*--------------------------------------------------------------------*
* Fontname
*--------------------------------------------------------------------*
lo_node2 = lo_node_font-&gt;find_from_name( &apos;name&apos; ).
IF lo_node2 IS BOUND.
lo_font-&gt;name = lo_node2-&gt;get_attribute( &apos;val&apos; ).
ENDIF.
*--------------------------------------------------------------------*
* Fontfamily
*--------------------------------------------------------------------*
lo_node2 = lo_node_font-&gt;find_from_name( &apos;family&apos; ).
IF lo_node2 IS BOUND.
lo_font-&gt;family = lo_node2-&gt;get_attribute( &apos;val&apos; ).
ENDIF.
*--------------------------------------------------------------------*
* Fontscheme
*--------------------------------------------------------------------*
lo_node2 = lo_node_font-&gt;find_from_name( &apos;scheme&apos; ).
IF lo_node2 IS BOUND.
lo_font-&gt;scheme = lo_node2-&gt;get_attribute( &apos;val&apos; ).
ENDIF.
*--------------------------------------------------------------------*
* Fontcolor
*--------------------------------------------------------------------*
lo_node2 = lo_node_font-&gt;find_from_name( &apos;color&apos; ).
IF lo_node2 IS BOUND.
fill_struct_from_attributes( EXPORTING
ip_element = lo_node2
CHANGING
cp_structure = ls_color ).
lo_font-&gt;color-rgb = ls_color-rgb.
IF ls_color-indexed IS NOT INITIAL.
lo_font-&gt;color-indexed = ls_color-indexed.
ENDIF.
IF ls_color-theme IS NOT INITIAL.
lo_font-&gt;color-theme = ls_color-theme.
ENDIF.
lo_font-&gt;color-tint = ls_color-tint.
ENDIF.
INSERT lo_font INTO TABLE ep_fonts.
lo_node_font ?= lo_node_font-&gt;get_next( ).
ENDWHILE.
endmethod.</source>
</method>
<method CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_STYLE_NUM_FORMATS" VERSION="1" LANGU="E" DESCRIPT="Loads &apos;number format&apos; part of styles" EXPOSURE="1" STATE="1" EDITORDER="13 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="0" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_STYLE_NUM_FORMATS" SCONAME="IP_XML" VERSION="1" LANGU="E" DESCRIPT="IF_IXML_DOCUMENT" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="3" TYPE="IF_IXML_DOCUMENT"/>
<parameter CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_STYLE_NUM_FORMATS" SCONAME="EP_NUM_FORMATS" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="2 " DISPID="0 " PARDECLTYP="3" PARPASSTYP="0" TYPTYPE="1" TYPE="T_NUM_FORMATS"/>
<source>method LOAD_STYLE_NUM_FORMATS.
*--------------------------------------------------------------------*
* ToDos:
* 2do§1 Explain gaps in predefined formats
*--------------------------------------------------------------------*
*--------------------------------------------------------------------*
* issue #230 - Pimp my Code
* - Stefan Schmöcker, (done) 2012-11-25
* - ...
* changes: renaming variables and types to naming conventions
* adding comments to explain what we are trying to achieve
* aligning code
*--------------------------------------------------------------------*
DATA: lo_node_numfmt TYPE REF TO if_ixml_element,
ls_num_format TYPE t_num_format.
*--------------------------------------------------------------------*
* We need a table of used numberformats to build up our styles
* there are two kinds of numberformats
* §1 those that have been explicitly added by the createor of the excel-file
* §2 and built-in numberformats
*--------------------------------------------------------------------*
*--------------------------------------------------------------------*
* §1 Get non-internal numberformats that are found in the file explicitly
* Following is an example how this part of a file could be set up
* &lt;numFmts count=&quot;1&quot;&gt;
* &lt;numFmt formatCode=&quot;#,###,###,###,##0.00&quot; numFmtId=&quot;164&quot;/&gt;
* &lt;/numFmts&gt;
*--------------------------------------------------------------------*
lo_node_numfmt ?= ip_xml-&gt;find_from_name( &apos;numFmt&apos; ).
WHILE lo_node_numfmt IS BOUND.
CLEAR ls_num_format.
CREATE OBJECT ls_num_format-format.
ls_num_format-format-&gt;format_code = lo_node_numfmt-&gt;get_attribute( &apos;formatCode&apos; ).
ls_num_format-id = lo_node_numfmt-&gt;get_attribute( &apos;numFmtId&apos; ).
INSERT ls_num_format INTO TABLE ep_num_formats.
lo_node_numfmt ?= lo_node_numfmt-&gt;get_next( ).
ENDWHILE.
DEFINE predefined_format.
ls_num_format-id = &amp;1.
create object ls_num_format-format.
ls_num_format-format-&gt;format_code = &amp;2.
insert ls_num_format into table ep_num_formats.
END-OF-DEFINITION.
*--------------------------------------------------------------------*
* §1 Get internal predefined numberformats
*--------------------------------------------------------------------*
predefined_format &apos;1&apos; &apos;0&apos;.
predefined_format &apos;2&apos; &apos;0.00&apos;.
predefined_format &apos;3&apos; &apos;#,##0&apos;.
predefined_format &apos;4&apos; &apos;#,##0.00&apos;.
predefined_format &apos;5&apos; &apos;$#,##0_);($#,##0)&apos;.
predefined_format &apos;6&apos; &apos;$#,##0_);[Red]($#,##0)&apos;.
predefined_format &apos;7&apos; &apos;$#,##0.00_);($#,##0.00)&apos;.
predefined_format &apos;8&apos; &apos;$#,##0.00_);[Red]($#,##0.00)&apos;.
predefined_format &apos;9&apos; &apos;0%&apos;.
predefined_format &apos;10&apos; &apos;0.00%&apos;.
predefined_format &apos;11&apos; &apos;0.00E+00&apos;.
predefined_format &apos;12&apos; &apos;# ?/?&apos;.
predefined_format &apos;13&apos; &apos;# ??/??&apos;.
predefined_format &apos;14&apos; &apos;m/d/yyyy&apos;.
predefined_format &apos;15&apos; &apos;d-mmm-yy&apos;.
predefined_format &apos;16&apos; &apos;d-mmm&apos;.
predefined_format &apos;17&apos; &apos;mmm-yy&apos;.
predefined_format &apos;18&apos; &apos;h:mm AM/PM&apos;.
predefined_format &apos;19&apos; &apos;h:mm:ss AM/PM&apos;.
predefined_format &apos;20&apos; &apos;h:mm&apos;.
predefined_format &apos;21&apos; &apos;h:mm:ss&apos;.
predefined_format &apos;22&apos; &apos;m/d/yyyy h:mm&apos;.
* 2do§1 Why is there a gap in here?
predefined_format &apos;37&apos; &apos;#,##0_);(#,##0)&apos;.
predefined_format &apos;38&apos; &apos;#,##0_);[Red](#,##0)&apos;.
predefined_format &apos;39&apos; &apos;#,##0.00_);(#,##0.00)&apos;.
predefined_format &apos;40&apos; &apos;#,##0.00_);[Red](#,##0.00)&apos;.
* 2do§1 Why is there a gap in here?
predefined_format &apos;45&apos; &apos;mm:ss&apos;.
predefined_format &apos;46&apos; &apos;[h]:mm:ss&apos;.
predefined_format &apos;47&apos; &apos;mm:ss.0&apos;.
predefined_format &apos;48&apos; &apos;##0.0E+0&apos;.
predefined_format &apos;49&apos; &apos;@&apos;.
* 2do§1 Is 49 really the last predefined format?
endmethod.</source>
</method>
<method CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_WORKBOOK" VERSION="1" LANGU="E" DESCRIPT="Loads workbook" EXPOSURE="1" STATE="1" EDITORDER="4 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="0" MTDNEWEXC="X" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_WORKBOOK" SCONAME="IV_WORKBOOK_FULL_FILENAME" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="STRING"/>
<parameter CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_WORKBOOK" SCONAME="IO_EXCEL" VERSION="1" LANGU="E" DESCRIPT="Excel creator" CMPTYPE="1" MTDTYPE="0" EDITORDER="2 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="3" TYPE="ZCL_EXCEL"/>
<exception CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_WORKBOOK" SCONAME="ZCX_EXCEL" VERSION="1" LANGU="E" DESCRIPT="Exceptions for ABAP2XLSX" MTDTYPE="0" EDITORDER="1 "/>
<source>METHOD load_workbook.
*--------------------------------------------------------------------*
* ToDos:
* 2do§1 Move macro-reading from zcl_excel_reader_xlsm to this class
* autodetect existance of macro/vba content
* Allow inputparameter to explicitly tell reader to ignore vba-content
*--------------------------------------------------------------------*
*--------------------------------------------------------------------*
* issue #230 - Pimp my Code
* - Stefan Schmöcker, (done) 2012-11-10
* - ...
* changes: renaming variables to naming conventions
* aligning code
* removing unused variables
* adding me-&gt; where possible
* renaming variables to indicate what they are used for
* adding comments to explain what we are trying to achieve
* renaming i/o parameters: previous input-parameter ip_path holds a (full) filename and not a path --&gt; rename to iv_workbook_full_filename
* ip_excel renamed while being at it --&gt; rename to io_excel
*--------------------------------------------------------------------*
* issue #232 - Read worksheetstate hidden/veryHidden
* - Stefan Schmöcker, 2012-11-11
*--------------------------------------------------------------------*
* issue#235 - repeat rows/columns
* - Stefan Schmöcker, 2012-12-02
* changes: correction in named ranges to correctly attach
* sheetlocal names/ranges to the correct sheet
*--------------------------------------------------------------------*
CONSTANTS: lcv_shared_strings TYPE string VALUE &apos;http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings&apos;,
lcv_worksheet TYPE string VALUE &apos;http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet&apos;,
lcv_styles TYPE string VALUE &apos;http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles&apos;,
lcv_vba_project TYPE string VALUE &apos;http://schemas.microsoft.com/office/2006/relationships/vbaProject&apos;, &quot;#EC NEEDED for future incorporation of XLSM-reader
*--------------------------------------------------------------------*
* #232: Read worksheetstate hidden/veryHidden - begin data declarations
*--------------------------------------------------------------------*
lcv_worksheet_state_hidden TYPE string VALUE &apos;hidden&apos;,
lcv_worksheet_state_veryhidden TYPE string VALUE &apos;veryHidden&apos;.
*--------------------------------------------------------------------*
* #232: Read worksheetstate hidden/veryHidden - end data declarations
*--------------------------------------------------------------------*
DATA:
lv_path TYPE string,
lv_filename TYPE chkfile,
lv_full_filename TYPE string,
lo_rels_workbook TYPE REF TO if_ixml_document,
lt_worksheets TYPE STANDARD TABLE OF t_relationship WITH NON-UNIQUE DEFAULT KEY,
lo_workbook TYPE REF TO if_ixml_document,
lv_workbook_index TYPE i,
lv_worksheet_path TYPE string,
ls_sheet TYPE t_sheet,
lo_node TYPE REF TO if_ixml_element,
ls_relationship TYPE t_relationship,
lo_worksheet TYPE REF TO zcl_excel_worksheet,
lo_range TYPE REF TO zcl_excel_range,
lv_worksheet_title TYPE zexcel_sheet_title,
lv_tabix TYPE sytabix, &quot; #235 - repeat rows/cols. Needed to link defined name to correct worksheet
ls_range TYPE t_range,
lv_range_value TYPE zexcel_range_value,
*--------------------------------------------------------------------*
* #229: Set active worksheet - begin data declarations
*--------------------------------------------------------------------*
lv_active_sheet_string TYPE string,
lv_zexcel_active_worksheet TYPE zexcel_active_worksheet,
*--------------------------------------------------------------------*
* issue#235 - repeat rows/columns - added autofilter support while changing this section
lo_autofilter TYPE REF TO zcl_excel_autofilter,
ls_area TYPE zexcel_s_autofilter_area,
lv_col_start_alpha TYPE zexcel_cell_column_alpha,
lv_col_end_alpha TYPE zexcel_cell_column_alpha.
*--------------------------------------------------------------------*
* #229: Set active worksheet - end data declarations
*--------------------------------------------------------------------*
FIELD-SYMBOLS: &lt;worksheet&gt; TYPE t_relationship.
*--------------------------------------------------------------------*
* §1 Get the position of files related to this workbook
* Usually this will be &lt;root&gt;/xl/workbook.xml
* Thus the workbookroot will be &lt;root&gt;/xl/
* The position of all related files will be given in file
* &lt;workbookroot&gt;/_rels/&lt;workbookfilename&gt;.rels and their positions
* be be given relative to the workbookroot
* Following is an example how this file could be set up
* &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;true&quot;?&gt;
* &lt;Relationships xmlns=&quot;http://schemas.openxmlformats.org/package/2006/relationships&quot;&gt;
* &lt;Relationship Target=&quot;styles.xml&quot; Type=&quot;http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles&quot; Id=&quot;rId6&quot;/&gt;
* &lt;Relationship Target=&quot;theme/theme1.xml&quot; Type=&quot;http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme&quot; Id=&quot;rId5&quot;/&gt;
* &lt;Relationship Target=&quot;worksheets/sheet1.xml&quot; Type=&quot;http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet&quot; Id=&quot;rId1&quot;/&gt;
* &lt;Relationship Target=&quot;worksheets/sheet2.xml&quot; Type=&quot;http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet&quot; Id=&quot;rId2&quot;/&gt;
* &lt;Relationship Target=&quot;worksheets/sheet3.xml&quot; Type=&quot;http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet&quot; Id=&quot;rId3&quot;/&gt;
* &lt;Relationship Target=&quot;worksheets/sheet4.xml&quot; Type=&quot;http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet&quot; Id=&quot;rId4&quot;/&gt;
* &lt;Relationship Target=&quot;sharedStrings.xml&quot; Type=&quot;http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings&quot; Id=&quot;rId7&quot;/&gt;
* &lt;/Relationships&gt;
*
* §2 Load data that is relevant to the complete workbook
* Currently supported is:
* §2.1 Shared strings - This holds all strings that are used in all worksheets
* §2.2 Styles - This holds all styles that are used in all worksheets
* §2.3 Worksheets - For each worksheet in the workbook one entry appears here to point to the file that holds the content of this worksheet
* §2.4 [Themes] - not supported
* §2.5 [VBA (Macro)] - supported in class zcl_excel_reader_xlsm but should be moved here and autodetect
* ...
*
* §3 Some information is held in the workbookfile as well
* §3.1 Names and order of of worksheets
* §3.2 Active worksheet
* §3.3 Defined names
* ...
* Following is an example how this file could be set up
* &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;true&quot;?&gt;
* &lt;workbook xmlns:r=&quot;http://schemas.openxmlformats.org/officeDocument/2006/relationships&quot; xmlns=&quot;http://schemas.openxmlformats.org/spreadsheetml/2006/main&quot;&gt;
* &lt;fileVersion rupBuild=&quot;4506&quot; lowestEdited=&quot;4&quot; lastEdited=&quot;4&quot; appName=&quot;xl&quot;/&gt;
* &lt;workbookPr defaultThemeVersion=&quot;124226&quot;/&gt;
* &lt;bookViews&gt;
* &lt;workbookView activeTab=&quot;1&quot; windowHeight=&quot;8445&quot; windowWidth=&quot;19035&quot; yWindow=&quot;120&quot; xWindow=&quot;120&quot;/&gt;
* &lt;/bookViews&gt;
* &lt;sheets&gt;
* &lt;sheet r:id=&quot;rId1&quot; sheetId=&quot;1&quot; name=&quot;Sheet1&quot;/&gt;
* &lt;sheet r:id=&quot;rId2&quot; sheetId=&quot;2&quot; name=&quot;Sheet2&quot;/&gt;
* &lt;sheet r:id=&quot;rId3&quot; sheetId=&quot;3&quot; name=&quot;Sheet3&quot; state=&quot;hidden&quot;/&gt;
* &lt;sheet r:id=&quot;rId4&quot; sheetId=&quot;4&quot; name=&quot;Sheet4&quot;/&gt;
* &lt;/sheets&gt;
* &lt;definedNames/&gt;
* &lt;calcPr calcId=&quot;125725&quot;/&gt;
* &lt;/workbook&gt;
*--------------------------------------------------------------------*
*--------------------------------------------------------------------*
* §1 Get the position of files related to this workbook
* Entry into this method is with the filename of the workbook
*--------------------------------------------------------------------*
CALL FUNCTION &apos;TRINT_SPLIT_FILE_AND_PATH&apos;
EXPORTING
full_name = iv_workbook_full_filename
IMPORTING
stripped_name = lv_filename
file_path = lv_path.
CONCATENATE lv_path &apos;_rels/&apos; lv_filename &apos;.rels&apos;
INTO lv_full_filename.
lo_rels_workbook = me-&gt;get_ixml_from_zip_archive( lv_full_filename ).
lo_node ?= lo_rels_workbook-&gt;find_from_name( &apos;Relationship&apos; ). &quot;#EC NOTEXT
WHILE lo_node IS BOUND.
me-&gt;fill_struct_from_attributes( EXPORTING ip_element = lo_node CHANGING cp_structure = ls_relationship ).
CASE ls_relationship-type.
*--------------------------------------------------------------------*
* §2.1 Shared strings - This holds all strings that are used in all worksheets
*--------------------------------------------------------------------*
WHEN lcv_shared_strings.
CONCATENATE lv_path ls_relationship-target
INTO lv_full_filename.
me-&gt;load_shared_strings( lv_full_filename ).
*--------------------------------------------------------------------*
* §2.3 Worksheets
* For each worksheet in the workbook one entry appears here to point to the file that holds the content of this worksheet
* Shared strings and styles have to be present before we can start with creating the worksheets
* thus we only store this information for use when parsing the workbookfile for sheetinformations
*--------------------------------------------------------------------*
WHEN lcv_worksheet.
APPEND ls_relationship TO lt_worksheets.
*--------------------------------------------------------------------*
* §2.2 Styles - This holds the styles that are used in all worksheets
*--------------------------------------------------------------------*
WHEN lcv_styles.
CONCATENATE lv_path ls_relationship-target
INTO lv_full_filename.
me-&gt;load_styles( ip_path = lv_full_filename
ip_excel = io_excel ).
WHEN OTHERS.
ENDCASE.
lo_node ?= lo_node-&gt;get_next( ).
ENDWHILE.
*--------------------------------------------------------------------*
* §3 Some information held in the workbookfile
*--------------------------------------------------------------------*
lo_workbook = me-&gt;get_ixml_from_zip_archive( iv_workbook_full_filename ).
*--------------------------------------------------------------------*
* §3.1 Names and order of of worksheets
*--------------------------------------------------------------------*
lo_node ?= lo_workbook-&gt;find_from_name( &apos;sheet&apos; ).
lv_workbook_index = 1.
WHILE lo_node IS BOUND.
me-&gt;fill_struct_from_attributes( EXPORTING
ip_element = lo_node
CHANGING
cp_structure = ls_sheet ).
*--------------------------------------------------------------------*
* Create new worksheet in workbook with correct name
*--------------------------------------------------------------------*
lv_worksheet_title = ls_sheet-name.
IF lv_workbook_index = 1. &quot; First sheet has been added automatically by creating io_excel
lo_worksheet = io_excel-&gt;get_active_worksheet( ).
lo_worksheet-&gt;set_title( lv_worksheet_title ).
ELSE.
lo_worksheet = io_excel-&gt;add_new_worksheet( lv_worksheet_title ).
ENDIF.
*--------------------------------------------------------------------*
* #232 - Read worksheetstate hidden/veryHidden - begin of coding
* Set status hidden if necessary
*--------------------------------------------------------------------*
CASE ls_sheet-state.
WHEN lcv_worksheet_state_hidden.
lo_worksheet-&gt;zif_excel_sheet_properties~hidden = zif_excel_sheet_properties=&gt;c_hidden.
WHEN lcv_worksheet_state_veryhidden.
lo_worksheet-&gt;zif_excel_sheet_properties~hidden = zif_excel_sheet_properties=&gt;c_veryhidden.
ENDCASE.
*--------------------------------------------------------------------*
* #232 - Read worksheetstate hidden/veryHidden - end of coding
*--------------------------------------------------------------------*
*--------------------------------------------------------------------*
* Load worksheetdata
*--------------------------------------------------------------------*
READ TABLE lt_worksheets ASSIGNING &lt;worksheet&gt; WITH KEY id = ls_sheet-id.
IF sy-subrc = 0.
&lt;worksheet&gt;-sheetid = ls_sheet-sheetid. &quot;ins #235 - repeat rows/cols - needed to identify correct sheet
CONCATENATE lv_path &lt;worksheet&gt;-target
INTO lv_worksheet_path.
me-&gt;load_worksheet( ip_path = lv_worksheet_path
io_worksheet = lo_worksheet ).
&lt;worksheet&gt;-worksheet = lo_worksheet.
ENDIF.
lo_node ?= lo_node-&gt;get_next( ).
ADD 1 TO lv_workbook_index.
ENDWHILE.
*--------------------------------------------------------------------*
* #229: Set active worksheet - begin coding
* §3.2 Active worksheet
*--------------------------------------------------------------------*
lv_zexcel_active_worksheet = 1. &quot; First sheet = active sheet if nothing else specified.
lo_node ?= lo_workbook-&gt;find_from_name( &apos;workbookView&apos; ).
IF lo_node IS BOUND.
lv_active_sheet_string = lo_node-&gt;get_attribute( &apos;activeTab&apos; ).
TRY.
lv_zexcel_active_worksheet = lv_active_sheet_string + 1. &quot; EXCEL numbers the sheets from 0 onwards --&gt; index into worksheettable is increased by one
CATCH cx_sy_conversion_error. &quot;#EC NO_HANDLER - error here --&gt; just use the default 1st sheet
ENDTRY.
ENDIF.
io_excel-&gt;set_active_sheet_index( lv_zexcel_active_worksheet ).
*--------------------------------------------------------------------*
* #229: Set active worksheet - end coding
*--------------------------------------------------------------------*
*--------------------------------------------------------------------*
* §3.3 Defined names
* So far I have encountered these
* - named ranges - sheetlocal
* - named ranges - workbookglobal
* - autofilters - sheetlocal ( special range )
* - repeat rows/cols - sheetlocal ( special range )
*
*--------------------------------------------------------------------*
lo_node ?= lo_workbook-&gt;find_from_name( &apos;definedName&apos; ).
WHILE lo_node IS BOUND.
CLEAR lo_range. &quot;ins issue #235 - repeat rows/cols
me-&gt;fill_struct_from_attributes( EXPORTING
ip_element = lo_node
CHANGING
cp_structure = ls_range ).
lv_range_value = lo_node-&gt;get_value( ).
IF ls_range-localsheetid IS NOT INITIAL. &quot; issue #163+
* READ TABLE lt_worksheets ASSIGNING &lt;worksheet&gt; WITH KEY id = ls_range-localsheetid. &quot;del issue #235 - repeat rows/cols &quot; issue #163+
* lo_range = &lt;worksheet&gt;-worksheet-&gt;add_new_range( ). &quot;del issue #235 - repeat rows/cols &quot; issue #163+
*--------------------------------------------------------------------*
* issue#235 - repeat rows/columns - begin
*--------------------------------------------------------------------*
lv_tabix = ls_range-localsheetid + 1.
READ TABLE lt_worksheets ASSIGNING &lt;worksheet&gt; INDEX lv_tabix.
IF sy-subrc = 0.
CASE ls_range-name.
WHEN zcl_excel_autofilters=&gt;c_autofilter.
lo_autofilter = io_excel-&gt;add_new_autofilter( io_sheet = &lt;worksheet&gt;-worksheet ) .
zcl_excel_common=&gt;convert_range2column_a_row( EXPORTING i_range = lv_range_value
IMPORTING e_column_start = lv_col_start_alpha
e_column_end = lv_col_end_alpha
e_row_start = ls_area-row_start ).
ls_area-col_start = zcl_excel_common=&gt;convert_column2int( lv_col_start_alpha ).
ls_area-col_end = zcl_excel_common=&gt;convert_column2int( lv_col_end_alpha ).
lo_autofilter-&gt;set_filter_area( is_area = ls_area ).
WHEN OTHERS.
lo_range = &lt;worksheet&gt;-worksheet-&gt;add_new_range( ).
ENDCASE.
ENDIF.
*--------------------------------------------------------------------*
* issue#235 - repeat rows/columns - end
*--------------------------------------------------------------------*
ELSE. &quot; issue #163+
lo_range = io_excel-&gt;add_new_range( ). &quot; issue #163+
ENDIF. &quot; issue #163+
* lo_range = ip_excel-&gt;add_new_range( ). &quot; issue #163-
IF lo_range IS BOUND. &quot;ins issue #235 - repeat rows/cols
lo_range-&gt;name = ls_range-name.
lo_range-&gt;set_range_value( lv_range_value ).
ENDIF. &quot;ins issue #235 - repeat rows/cols
lo_node ?= lo_node-&gt;get_next( ).
ENDWHILE.
ENDMETHOD.</source>
</method>
<method CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_WORKSHEET" VERSION="1" LANGU="E" DESCRIPT="Loads worksheet" EXPOSURE="1" STATE="1" EDITORDER="6 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="0" MTDNEWEXC="X" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_WORKSHEET" SCONAME="IP_PATH" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="STRING"/>
<parameter CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_WORKSHEET" SCONAME="IO_WORKSHEET" VERSION="1" LANGU="E" DESCRIPT="Excel creator" CMPTYPE="1" MTDTYPE="0" EDITORDER="2 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="3" TYPE="ZCL_EXCEL_WORKSHEET"/>
<exception CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_WORKSHEET" SCONAME="ZCX_EXCEL" VERSION="1" LANGU="E" DESCRIPT="Exceptions for ABAP2XLSX" MTDTYPE="0" EDITORDER="1 "/>
<source>method LOAD_WORKSHEET.
TYPES: BEGIN OF t_cell,
r TYPE string,
t TYPE string,
s TYPE string,
END OF t_cell.
TYPES: BEGIN OF t_column,
min TYPE string,
max TYPE string,
width TYPE float,
customwidth TYPE string,
style TYPE string,
bestfit TYPE string,
collapsed TYPE string,
hidden TYPE string,
outlinelevel TYPE string,
END OF t_column.
TYPES: BEGIN OF t_sheetview,
showgridlines TYPE zexcel_show_gridlines,
tabselected TYPE string,
zoomscalenormal TYPE string,
workbookviewid TYPE string,
showrowcolheaders TYPE string,
END OF t_sheetview.
TYPES: BEGIN OF t_mergecell,
ref TYPE string,
END OF t_mergecell.
TYPES: BEGIN OF t_row,
r TYPE string,
customheight TYPE string,
ht TYPE float,
spans TYPE string,
thickbot TYPE string,
customformat TYPE string,
thicktop TYPE string,
collapsed TYPE string,
hidden TYPE string,
outlinelevel TYPE string,
END OF t_row.
TYPES: BEGIN OF t_page_setup,
id TYPE string,
orientation TYPE string,
scale TYPE string,
END OF t_page_setup.
TYPES: BEGIN OF t_page_margins,
footer TYPE string,
header TYPE string,
bottom TYPE string,
top TYPE string,
right TYPE string,
left TYPE string,
END OF t_page_margins.
TYPES: BEGIN OF t_sheetformatpr,
customheight TYPE string,
defaultrowheight TYPE string,
customwidth TYPE string,
defaultcolwidth TYPE string,
END OF t_sheetformatpr.
TYPES: BEGIN OF t_headerfooter,
alignwithmargins TYPE string,
differentoddeven TYPE string,
END OF t_headerfooter.
TYPES: BEGIN OF lty_tabcolor,
rgb TYPE string,
theme TYPE string,
END OF lty_tabcolor.
CONSTANTS: lc_xml_attr_true TYPE string VALUE &apos;true&apos;,
lc_xml_attr_true_int TYPE string VALUE &apos;1&apos;.
CONSTANTS: lc_rel_drawing TYPE string VALUE &apos;http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing&apos;,
lc_rel_printer TYPE string VALUE &apos;http://schemas.openxmlformats.org/officeDocument/2006/relationships/printerSettings&apos;.
DATA: worksheet TYPE REF TO if_ixml_document,
cells TYPE REF TO if_ixml_node_collection,
iterator TYPE REF TO if_ixml_node_iterator,
iterator2 TYPE REF TO if_ixml_node_iterator,
row_elem TYPE REF TO if_ixml_element,
cell_elem TYPE REF TO if_ixml_element,
cell TYPE t_cell,
index TYPE i,
value_elem TYPE REF TO if_ixml_element,
formula_elem TYPE REF TO if_ixml_element,
cell_value TYPE zexcel_cell_value,
cell_formula TYPE zexcel_cell_formula,
cell_column TYPE zexcel_cell_column_alpha,
cell_row TYPE zexcel_cell_row,
style TYPE REF TO zcl_excel_style,
style_guid TYPE zexcel_cell_style,
lo_dimension_elem TYPE REF TO if_ixml_element, &quot;#+234
lv_dimension_range TYPE string, &quot;#+234
sheetview_elem TYPE REF TO if_ixml_element,
sheetview TYPE t_sheetview,
pane_elem TYPE REF TO if_ixml_element,
pane TYPE zexcel_pane,
pane_cell_row_a TYPE string,
pane_cell_row TYPE zexcel_cell_row,
pane_cell_col_a TYPE zexcel_cell_column_alpha,
pane_cell_col TYPE zexcel_cell_column,
mergecells TYPE REF TO if_ixml_node_collection,
mergecell_elem TYPE REF TO if_ixml_element,
mergecell TYPE t_mergecell,
merge_column_start TYPE zexcel_cell_column_alpha,
merge_column_end TYPE zexcel_cell_column_alpha,
merge_row_start TYPE zexcel_cell_row,
merge_row_end TYPE zexcel_cell_row,
sheetformatpr_elem TYPE REF TO if_ixml_element,
sheetformatpr TYPE t_sheetformatpr,
height TYPE float,
width TYPE float,
headerfooter_elem TYPE REF TO if_ixml_element,
headerfooter TYPE t_headerfooter,
odd_header TYPE zexcel_s_worksheet_head_foot,
odd_footer TYPE zexcel_s_worksheet_head_foot,
even_header TYPE zexcel_s_worksheet_head_foot,
even_footer TYPE zexcel_s_worksheet_head_foot,
hf_value_elem TYPE REF TO if_ixml_element,
pagemargins_elem TYPE REF TO if_ixml_element,
pagemargins TYPE t_page_margins,
pagesetup_elem TYPE REF TO if_ixml_element,
pagesetup TYPE t_page_setup,
columns TYPE REF TO if_ixml_node_collection,
column_elem TYPE REF TO if_ixml_element,
column TYPE t_column,
column_alpha TYPE zexcel_cell_column_alpha,
column_dimension TYPE REF TO zcl_excel_worksheet_columndime,
outline_level TYPE int4,
lr_tabcolor TYPE REF TO if_ixml_element,
ls_tabcolor TYPE lty_tabcolor,
ls_excel_s_tabcolor TYPE zexcel_s_tabcolor,
rows TYPE REF TO if_ixml_node_collection,
row TYPE t_row,
max_col TYPE i, &quot;for use with SPANS element
min_col TYPE i, &quot;for use with SPANS element
max_col_s TYPE char10, &quot;for use with SPANS element
min_col_s TYPE char10, &quot;for use with SPANS element
row_dimension TYPE REF TO zcl_excel_worksheet_rowdimensi,
path TYPE string,
node TYPE REF TO if_ixml_element,
relationship TYPE t_relationship,
rels_worksheet TYPE REF TO if_ixml_document,
rels_worksheet_path TYPE string,
stripped_name TYPE chkfile,
dirname TYPE string.
&quot; Read Workbook Relationships
CALL FUNCTION &apos;TRINT_SPLIT_FILE_AND_PATH&apos;
EXPORTING
full_name = ip_path
IMPORTING
stripped_name = stripped_name
file_path = dirname.
CONCATENATE dirname &apos;_rels/&apos; stripped_name &apos;.rels&apos;
INTO rels_worksheet_path.
TRY. &quot; +#222 _rels/xxx.rels might not be present. If not found there can be no drawings --&gt; just ignore this section
rels_worksheet = me-&gt;get_ixml_from_zip_archive( rels_worksheet_path ).
node ?= rels_worksheet-&gt;find_from_name( &apos;Relationship&apos; ).
CATCH zcx_excel. &quot;#EC NO_HANDLER +#222
&quot; +#222 No errorhandling necessary - node will be unbound if error occurs
ENDTRY. &quot; +#222
WHILE node IS BOUND.
fill_struct_from_attributes( EXPORTING ip_element = node CHANGING cp_structure = relationship ).
CONCATENATE dirname relationship-target INTO path.
path = resolve_path( path ).
CASE relationship-type.
WHEN lc_rel_drawing.
&quot; Read Drawings
CALL METHOD me-&gt;load_worksheet_drawing
EXPORTING
ip_path = path
io_worksheet = io_worksheet.
WHEN lc_rel_printer.
&quot; Read Printer settings
WHEN OTHERS.
ENDCASE.
node ?= node-&gt;get_next( ).
ENDWHILE.
worksheet = me-&gt;get_ixml_from_zip_archive( ip_path ).
lr_tabcolor ?= worksheet-&gt;find_from_name( &apos;tabColor&apos; ).
IF lr_tabcolor IS BOUND.
fill_struct_from_attributes( EXPORTING ip_element = lr_tabcolor CHANGING cp_structure = ls_tabcolor ).
* Theme not supported yet
IF ls_tabcolor-rgb IS NOT INITIAL.
ls_excel_s_tabcolor-rgb = ls_tabcolor-rgb.
io_worksheet-&gt;set_tabcolor( ls_excel_s_tabcolor ).
ENDIF.
ENDIF.
rows = worksheet-&gt;get_elements_by_tag_name( name = &apos;row&apos; ).
iterator = rows-&gt;create_iterator( ).
row_elem ?= iterator-&gt;get_next( ).
WHILE row_elem IS BOUND.
fill_struct_from_attributes( EXPORTING ip_element = row_elem CHANGING cp_structure = row ).
SPLIT row-spans AT &apos;:&apos; INTO min_col_s max_col_s.
index = max_col_s.
IF index &gt; max_col.
max_col = index.
ENDIF.
cell_row = row-r.
IF row-customheight = &apos;1&apos; OR row-collapsed = lc_xml_attr_true OR row-collapsed = lc_xml_attr_true_int OR
row-hidden = lc_xml_attr_true OR row-hidden = lc_xml_attr_true_int OR row-outlinelevel &gt; &apos;0&apos;.
row_dimension = io_worksheet-&gt;get_row_dimension( cell_row ).
IF row-customheight = &apos;1&apos;.
row_dimension-&gt;set_row_height( row-ht ).
ENDIF.
IF row-collapsed = lc_xml_attr_true OR row-collapsed = lc_xml_attr_true_int.
row_dimension-&gt;set_collapsed( abap_true ).
ENDIF.
IF row-hidden = lc_xml_attr_true OR row-hidden = lc_xml_attr_true_int.
row_dimension-&gt;set_visible( abap_false ).
ENDIF.
IF row-outlinelevel &gt; &apos;&apos;.
* outline_level = condense( row-outlineLevel ). &quot;For basis 7.02 and higher
CONDENSE row-outlinelevel.
outline_level = row-outlinelevel.
IF outline_level &gt; 0.
row_dimension-&gt;set_outline_level( outline_level ).
ENDIF.
ENDIF.
ENDIF.
cells = row_elem-&gt;get_elements_by_tag_name( name = &apos;c&apos; ).
iterator2 = cells-&gt;create_iterator( ).
cell_elem ?= iterator2-&gt;get_next( ).
WHILE cell_elem IS BOUND.
CLEAR: cell_value, cell_formula, style_guid.
fill_struct_from_attributes( EXPORTING ip_element = cell_elem CHANGING cp_structure = cell ).
value_elem = cell_elem-&gt;find_from_name( name = &apos;v&apos; ).
CASE cell-t.
WHEN &apos;s&apos;. &quot; String values are stored as index in shared string table
index = value_elem-&gt;get_value( ) + 1.
READ TABLE shared_strings INTO cell_value INDEX index.
WHEN &apos;inlineStr&apos;. &quot; inlineStr values are kept in special node
value_elem = cell_elem-&gt;find_from_name( name = &apos;is&apos; ).
IF value_elem IS BOUND.
cell_value = value_elem-&gt;get_value( ).
ENDIF.
WHEN OTHERS. &quot;other types are stored directly
IF value_elem IS BOUND.
cell_value = value_elem-&gt;get_value( ).
ENDIF.
ENDCASE.
CLEAR style_guid.
&quot;read style based on index
IF cell-s IS NOT INITIAL.
index = cell-s + 1.
READ TABLE styles INTO style INDEX index.
IF sy-subrc = 0.
style_guid = style-&gt;get_guid( ).
ENDIF.
ENDIF.
formula_elem = cell_elem-&gt;find_from_name( name = &apos;f&apos; ).
IF formula_elem IS BOUND.
cell_formula = formula_elem-&gt;get_value( ).
ENDIF.
IF NOT cell_value IS INITIAL OR NOT cell_formula IS INITIAL OR style_guid IS NOT INITIAL.
zcl_excel_common=&gt;convert_columnrow2column_a_row(
EXPORTING
i_columnrow = cell-r
IMPORTING
e_column = cell_column
e_row = cell_row
).
io_worksheet-&gt;set_cell(
ip_column = cell_column &quot; cell_elem Column
ip_row = cell_row &quot; cell_elem row_elem
ip_value = cell_value &quot; cell_elem Value
ip_formula = cell_formula
ip_data_type = cell-t
ip_style = style_guid ).
ENDIF.
cell_elem ?= iterator2-&gt;get_next( ).
ENDWHILE.
row_elem ?= iterator-&gt;get_next( ).
ENDWHILE.
*--------------------------------------------------------------------*
*#234 - column width not read correctly - begin of coding
* reason - libre office doesn&apos;t use SPAN in row - definitions
*--------------------------------------------------------------------*
IF max_col = 0.
lo_dimension_elem = worksheet-&gt;find_from_name( name = &apos;dimension&apos; ).
IF lo_dimension_elem IS BOUND.
lv_dimension_range = lo_dimension_elem-&gt;get_attribute( &apos;ref&apos; ).
IF lv_dimension_range CS &apos;:&apos;.
REPLACE REGEX &apos;\D+\d+:(\D+)\d+&apos; IN lv_dimension_range WITH &apos;$1&apos;. &quot; Get max column
ELSE.
REPLACE REGEX &apos;(\D+)\d+&apos; IN lv_dimension_range WITH &apos;$1&apos;. &quot; Get max column
ENDIF.
max_col = zcl_excel_common=&gt;convert_column2int( lv_dimension_range ).
ENDIF.
ENDIF.
*--------------------------------------------------------------------*
*#234 - column width not read correctly - end of coding
*--------------------------------------------------------------------*
&quot;Get the customized column width
columns = worksheet-&gt;get_elements_by_tag_name( name = &apos;col&apos; ).
iterator = columns-&gt;create_iterator( ).
column_elem ?= iterator-&gt;get_next( ).
WHILE column_elem IS BOUND.
fill_struct_from_attributes( EXPORTING ip_element = column_elem CHANGING cp_structure = column ).
column_elem ?= iterator-&gt;get_next( ).
IF column-customwidth = lc_xml_attr_true OR
column-customwidth = lc_xml_attr_true_int OR
column-bestfit = lc_xml_attr_true OR
column-bestfit = lc_xml_attr_true_int OR
column-collapsed = lc_xml_attr_true OR
column-collapsed = lc_xml_attr_true_int OR
column-hidden = lc_xml_attr_true OR
column-hidden = lc_xml_attr_true_int OR
column-outlinelevel &gt; &apos;&apos; OR
column-style &gt; &apos;&apos;.
index = column-min.
WHILE index &lt;= column-max AND index &lt;= max_col.
column_alpha = zcl_excel_common=&gt;convert_column2alpha( index ).
column_dimension = io_worksheet-&gt;get_column_dimension( column_alpha ).
IF column-customwidth = lc_xml_attr_true OR column-customwidth = lc_xml_attr_true_int
OR column-width IS NOT INITIAL. &quot;+#234
column_dimension-&gt;set_width( column-width ).
ENDIF.
IF column-bestfit = lc_xml_attr_true OR column-bestfit = lc_xml_attr_true_int.
column_dimension-&gt;set_auto_size( abap_true ).
ENDIF.
IF column-collapsed = lc_xml_attr_true OR column-collapsed = lc_xml_attr_true_int.
column_dimension-&gt;set_collapsed( abap_true ).
ENDIF.
IF column-hidden = lc_xml_attr_true OR column-hidden = lc_xml_attr_true_int.
column_dimension-&gt;set_visible( abap_false ).
ENDIF.
IF column-outlinelevel &gt; &apos;&apos;.
* outline_level = condense( column-outlineLevel ).
CONDENSE column-outlinelevel.
outline_level = column-outlinelevel.
IF outline_level &gt; 0.
column_dimension-&gt;set_outline_level( outline_level ).
ENDIF.
ENDIF.
IF column-style &gt; &apos;&apos;.
sy-index = column-style + 1.
READ TABLE styles INTO style INDEX sy-index.
DATA: dummy_zexcel_cell_style TYPE zexcel_cell_style.
dummy_zexcel_cell_style = style-&gt;get_guid( ).
column_dimension-&gt;set_column_style_by_guid( dummy_zexcel_cell_style ).
ENDIF.
ADD 1 TO index.
ENDWHILE.
ENDIF.
* Fix 207 Read attributes HIDDEN, OUTLINELEVEL, COLLAPSED in ZCL_EXCEL_READER_2007
* IF column-hidden = lc_xml_attr_true OR
* column-hidden = lc_xml_attr_true_int.
* index = column-min.
* WHILE index &lt;= column-max.
* column_alpha = zcl_excel_common=&gt;convert_column2alpha( index ).
* column_dimension = io_worksheet-&gt;get_column_dimension( column_alpha ).
* column_dimension-&gt;set_visible( abap_false ).
* ADD 1 TO index.
* ENDWHILE.
* ENDIF.
ENDWHILE.
&quot;Now we need to get information from the sheetView node
sheetview_elem = worksheet-&gt;find_from_name( name = &apos;sheetView&apos; ).
fill_struct_from_attributes( EXPORTING ip_element = sheetview_elem CHANGING cp_structure = sheetview ).
IF sheetview-showgridlines IS INITIAL OR
sheetview-showgridlines = lc_xml_attr_true OR
sheetview-showgridlines = lc_xml_attr_true_int.
&quot;If the attribute is not specified or set to true, we will show grid lines
sheetview-showgridlines = abap_true.
ELSE.
sheetview-showgridlines = abap_false.
ENDIF.
io_worksheet-&gt;set_show_gridlines( sheetview-showgridlines ).
&quot;Add merge cell information
mergecells = worksheet-&gt;get_elements_by_tag_name( name = &apos;mergeCell&apos; ).
iterator = mergecells-&gt;create_iterator( ).
mergecell_elem ?= iterator-&gt;get_next( ).
WHILE mergecell_elem IS BOUND.
fill_struct_from_attributes( EXPORTING ip_element = mergecell_elem CHANGING cp_structure = mergecell ).
zcl_excel_common=&gt;convert_range2column_a_row(
EXPORTING
i_range = mergecell-ref
IMPORTING
e_column_start = merge_column_start
e_column_end = merge_column_end
e_row_start = merge_row_start
e_row_end = merge_row_end
).
mergecell_elem ?= iterator-&gt;get_next( ).
io_worksheet-&gt;set_merge(
EXPORTING
ip_column_start = merge_column_start
ip_column_end = merge_column_end
ip_row = merge_row_start
ip_row_to = merge_row_end
).
ENDWHILE.
&quot; read sheet format properties
sheetformatpr_elem = worksheet-&gt;find_from_name( &apos;sheetFormatPr&apos; ).
IF sheetformatpr_elem IS NOT INITIAL.
fill_struct_from_attributes( EXPORTING ip_element = sheetformatpr_elem CHANGING cp_structure = sheetformatpr ).
IF sheetformatpr-customheight = &apos;1&apos;.
height = sheetformatpr-defaultrowheight.
row_dimension = io_worksheet-&gt;get_default_row_dimension( ).
row_dimension-&gt;set_row_height( height ).
ENDIF.
&quot; TODO... column
ENDIF.
&quot; Read in page margins
pagemargins_elem = worksheet-&gt;find_from_name( &apos;pageMargins&apos; ).
IF pagemargins_elem IS NOT INITIAL.
fill_struct_from_attributes( EXPORTING ip_element = pagemargins_elem CHANGING cp_structure = pagemargins ).
io_worksheet-&gt;sheet_setup-&gt;margin_bottom = pagemargins-bottom.
io_worksheet-&gt;sheet_setup-&gt;margin_footer = pagemargins-footer.
io_worksheet-&gt;sheet_setup-&gt;margin_header = pagemargins-header.
io_worksheet-&gt;sheet_setup-&gt;margin_left = pagemargins-left.
io_worksheet-&gt;sheet_setup-&gt;margin_right = pagemargins-right.
io_worksheet-&gt;sheet_setup-&gt;margin_top = pagemargins-top.
ENDIF.
&quot; Read in page setup
pagesetup_elem = worksheet-&gt;find_from_name( &apos;pageSetup&apos; ).
IF pagesetup_elem IS NOT INITIAL.
fill_struct_from_attributes( EXPORTING ip_element = pagesetup_elem CHANGING cp_structure = pagesetup ).
io_worksheet-&gt;sheet_setup-&gt;orientation = pagesetup-orientation.
io_worksheet-&gt;sheet_setup-&gt;scale = pagesetup-scale.
ENDIF.
&quot; Read header footer
headerfooter_elem = worksheet-&gt;find_from_name( &apos;headerFooter&apos; ).
IF headerfooter_elem IS NOT INITIAL.
fill_struct_from_attributes( EXPORTING ip_element = headerfooter_elem CHANGING cp_structure = headerfooter ).
io_worksheet-&gt;sheet_setup-&gt;diff_oddeven_headerfooter = headerfooter-differentoddeven.
hf_value_elem = headerfooter_elem-&gt;find_from_name( &apos;oddFooter&apos; ).
IF hf_value_elem IS NOT INITIAL.
odd_footer-left_value = hf_value_elem-&gt;get_value( ).
ENDIF.
&quot; TODO.. get the rest.
io_worksheet-&gt;sheet_setup-&gt;set_header_footer(
ip_odd_header = odd_header
ip_odd_footer = odd_footer
ip_even_header = even_header
ip_even_footer = even_footer ).
ENDIF.
&quot; Start fix 194 Read attributes HIDDEN, OUTLINELEVEL, COLLAPSED in ZCL_EXCEL_READER_2007
&quot; Read pane
pane_elem = sheetview_elem-&gt;find_from_name( name = &apos;pane&apos; ).
IF pane_elem IS BOUND.
fill_struct_from_attributes( EXPORTING ip_element = pane_elem CHANGING cp_structure = pane ).
FIND REGEX &apos;^(\w+)(\d+)$&apos; IN pane-topleftcell SUBMATCHES pane_cell_col_a
pane_cell_row_a.
pane_cell_row = pane_cell_row_a.
pane_cell_col = zcl_excel_common=&gt;convert_column2int( pane_cell_col_a ).
SUBTRACT 1 FROM: pane_cell_col, pane_cell_row.
IF pane_cell_col &gt; 0 AND pane_cell_row &gt; 0.
io_worksheet-&gt;freeze_panes( ip_num_rows = pane_cell_row
ip_num_columns = pane_cell_col ).
ELSEIF pane_cell_row &gt; 0.
io_worksheet-&gt;freeze_panes( ip_num_rows = pane_cell_row ).
ELSE.
io_worksheet-&gt;freeze_panes( ip_num_columns = pane_cell_col ).
ENDIF.
ENDIF.
&quot; End fix 194 Read attributes HIDDEN, OUTLINELEVEL, COLLAPSED in ZCL_EXCEL_READER_2007
endmethod.</source>
</method>
<method CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_WORKSHEET_DRAWING" VERSION="1" LANGU="E" DESCRIPT="Loads worksheet drawings" EXPOSURE="1" STATE="1" EDITORDER="7 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="0" MTDNEWEXC="X" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_WORKSHEET_DRAWING" SCONAME="IP_PATH" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="STRING"/>
<parameter CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_WORKSHEET_DRAWING" SCONAME="IO_WORKSHEET" VERSION="1" LANGU="E" DESCRIPT="Excel creator" CMPTYPE="1" MTDTYPE="0" EDITORDER="2 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="3" TYPE="ZCL_EXCEL_WORKSHEET"/>
<exception CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_WORKSHEET_DRAWING" SCONAME="ZCX_EXCEL" VERSION="1" LANGU="E" DESCRIPT="Exceptions for ABAP2XLSX" MTDTYPE="0" EDITORDER="1 "/>
<source>method LOAD_WORKSHEET_DRAWING.
TYPES: BEGIN OF t_c_nv_pr,
name TYPE string,
id TYPE string,
END OF t_c_nv_pr.
TYPES: BEGIN OF t_blip,
cstate TYPE string,
embed TYPE string,
END OF t_blip.
TYPES: BEGIN OF t_chart,
id TYPE string,
END OF t_chart.
CONSTANTS: lc_xml_attr_true TYPE string VALUE &apos;true&apos;,
lc_xml_attr_true_int TYPE string VALUE &apos;1&apos;.
CONSTANTS: lc_rel_chart TYPE string VALUE &apos;http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart&apos;,
lc_rel_image TYPE string VALUE &apos;http://schemas.openxmlformats.org/officeDocument/2006/relationships/image&apos;.
DATA: drawing TYPE REF TO if_ixml_document,
anchors TYPE REF TO if_ixml_node_collection,
node TYPE REF TO if_ixml_element,
coll_length TYPE i,
iterator TYPE REF TO if_ixml_node_iterator,
anchor_elem TYPE REF TO if_ixml_element,
relationship TYPE t_relationship,
rel_drawings TYPE t_rel_drawings,
rel_drawing TYPE t_rel_drawing,
rels_drawing TYPE REF TO if_ixml_document,
rels_drawing_path TYPE string,
stripped_name TYPE chkfile,
dirname TYPE string,
path TYPE string,
path2 TYPE text255,
file_ext2 TYPE char10.
&quot; Read Workbook Relationships
CALL FUNCTION &apos;TRINT_SPLIT_FILE_AND_PATH&apos;
EXPORTING
full_name = ip_path
IMPORTING
stripped_name = stripped_name
file_path = dirname.
CONCATENATE dirname &apos;_rels/&apos; stripped_name &apos;.rels&apos;
INTO rels_drawing_path.
rels_drawing_path = resolve_path( rels_drawing_path ).
rels_drawing = me-&gt;get_ixml_from_zip_archive( rels_drawing_path ).
node ?= rels_drawing-&gt;find_from_name( &apos;Relationship&apos; ).
WHILE node IS BOUND.
fill_struct_from_attributes( EXPORTING ip_element = node CHANGING cp_structure = relationship ).
rel_drawing-id = relationship-id.
CONCATENATE dirname relationship-target INTO path.
path = resolve_path( path ).
rel_drawing-content = me-&gt;get_from_zip_archive( path ). &quot;------------&gt; This is for template usage
path2 = path.
zcl_excel_common=&gt;split_file( EXPORTING ip_file = path2
IMPORTING ep_extension = file_ext2 ).
* CALL FUNCTION &apos;CV120_SPLIT_FILE&apos;
* EXPORTING
* pf_file = path2
* IMPORTING
* pfx_extension = file_ext2.
rel_drawing-file_ext = file_ext2.
&quot;-------------Added by Alessandro Iannacci - Should load graph xml
CASE relationship-type.
WHEN lc_rel_chart.
&quot;Read chart xml
rel_drawing-content_xml = me-&gt;get_ixml_from_zip_archive( path ).
WHEN OTHERS.
ENDCASE.
&quot;----------------------------
APPEND rel_drawing TO rel_drawings.
node ?= node-&gt;get_next( ).
ENDWHILE.
drawing = me-&gt;get_ixml_from_zip_archive( ip_path ).
* one-cell anchor **************
anchors = drawing-&gt;get_elements_by_tag_name( name = &apos;oneCellAnchor&apos; namespace = &apos;xdr&apos; ).
coll_length = anchors-&gt;get_length( ).
iterator = anchors-&gt;create_iterator( ).
DO coll_length TIMES.
anchor_elem ?= iterator-&gt;get_next( ).
CALL METHOD me-&gt;load_drawing_anchor
EXPORTING
io_anchor_element = anchor_elem
io_worksheet = io_worksheet
it_related_drawings = rel_drawings.
ENDDO.
* two-cell anchor ******************
anchors = drawing-&gt;get_elements_by_tag_name( name = &apos;twoCellAnchor&apos; namespace = &apos;xdr&apos; ).
coll_length = anchors-&gt;get_length( ).
iterator = anchors-&gt;create_iterator( ).
DO coll_length TIMES.
anchor_elem ?= iterator-&gt;get_next( ).
CALL METHOD me-&gt;load_drawing_anchor
EXPORTING
io_anchor_element = anchor_elem
io_worksheet = io_worksheet
it_related_drawings = rel_drawings.
ENDDO.
endmethod.</source>
</method>
<method CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="RESOLVE_PATH" VERSION="1" LANGU="E" DESCRIPT="Return path after ../ values are removed" EXPOSURE="1" STATE="1" EDITORDER="1 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="1" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="RESOLVE_PATH" SCONAME="IP_PATH" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="STRING"/>
<parameter CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="RESOLVE_PATH" SCONAME="RP_RESULT" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="2 " DISPID="0 " PARDECLTYP="3" PARPASSTYP="0" TYPTYPE="1" TYPE="STRING"/>
<source>method RESOLVE_PATH.
*--------------------------------------------------------------------*
* ToDos:
* 2do§1 Determine whether the replacement should be done
* iterative to allow /../../.. or something alike
* 2do§2 Determine whether /./ has to be supported as well
* 2do§3 Create unit-test for this method
*
* Please don&apos;t just delete these ToDos if they are not
* needed but leave a comment that states this
*--------------------------------------------------------------------*
*--------------------------------------------------------------------*
* issue #230 - Pimp my Code
* - Stefan Schmöcker, (done) 2012-11-11
* - ...
* changes: replaced previous coding by regular expression
* adding comments to explain what we are trying to achieve
*--------------------------------------------------------------------*
*--------------------------------------------------------------------*
* §1 This routine will receive a path, that may have a relative pathname (/../) included somewhere
* The output should be a resolved path without relative references
* Example: Input xl/worksheets/../drawings/drawing1.xml
* Output xl/drawings/drawing1.xml
*--------------------------------------------------------------------*
rp_result = ip_path.
*--------------------------------------------------------------------*
* §1 Remove relative pathnames
*--------------------------------------------------------------------*
* Regular expression [^/]*/\.\./
* [^/]* --&gt; any number of characters other than /
* followed by /\.\./ --&gt; the sequence /../
* ==&gt; worksheets/../ will be found in the example
*--------------------------------------------------------------------*
REPLACE REGEX &apos;[^/]*/\.\./&apos; IN rp_result WITH ``.
endmethod.</source>
</method>
</CLAS>