diff --git a/ZA2X/CLAS/ZCL_EXCEL_HYPERLINK.slnk b/ZA2X/CLAS/ZCL_EXCEL_HYPERLINK.slnk
new file mode 100644
index 0000000..e9a632f
--- /dev/null
+++ b/ZA2X/CLAS/ZCL_EXCEL_HYPERLINK.slnk
@@ -0,0 +1,139 @@
+
+
+ class ZCL_EXCEL_HYPERLINK definition
+ public
+ final
+ create private .
+
+*"* public components of class ZCL_EXCEL_HYPERLINK
+*"* do not include other source files here!!!
+public section.
+ type-pools ABAP .
+
+ class-methods CREATE_EXTERNAL_LINK
+ importing
+ !IV_URL type STRING
+ returning
+ value(OV_LINK) type ref to ZCL_EXCEL_HYPERLINK .
+ class-methods CREATE_INTERNAL_LINK
+ importing
+ !IV_LOCATION type STRING
+ returning
+ value(OV_LINK) type ref to ZCL_EXCEL_HYPERLINK .
+ methods IS_INTERNAL
+ returning
+ value(EV_RET) type ABAP_BOOL .
+ methods SET_CELL_REFERENCE
+ importing
+ !IP_COLUMN type ZEXCEL_CELL_COLUMN_ALPHA
+ !IP_ROW type ZEXCEL_CELL_ROW .
+ methods GET_REF
+ returning
+ value(EV_REF) type STRING .
+ methods GET_URL
+ returning
+ value(EV_URL) type STRING .
+ *"* protected components of class ZCL_EXCEL_HYPERLINK
+*"* do not include other source files here!!!
+protected section.
+ *"* private components of class ZCL_EXCEL_HYPERLINK
+*"* do not include other source files here!!!
+private section.
+
+ data LOCATION type STRING .
+ data CELL_REFERENCE type STRING .
+ data INTERNAL type ABAP_BOOL .
+ data COLUMN type ZEXCEL_CELL_COLUMN_ALPHA .
+ data ROW type ZEXCEL_CELL_ROW .
+
+ class-methods CREATE
+ importing
+ !IV_URL type STRING
+ !IV_INTERNAL type ABAP_BOOL
+ returning
+ value(OV_LINK) type ref to ZCL_EXCEL_HYPERLINK .
+ *"* local class implementation for public class
+*"* use this source file for the implementation part of
+*"* local helper classes
+ *"* use this source file for any type declarations (class
+*"* definitions, interfaces or data types) you need for method
+*"* implementation or private method's signature
+ *"* use this source file for any macro definitions you need
+*"* in the implementation part of the class
+
+
+
+ ABAP
+
+
+
+
+
+
+
+
+
+ method CREATE.
+ data: lo_hyperlink type REF TO zcl_excel_hyperlink.
+
+ create OBJECT lo_hyperlink.
+
+ lo_hyperlink->location = iv_url.
+ lo_hyperlink->internal = iv_internal.
+
+ ov_link = lo_hyperlink.
+endmethod.
+
+
+
+
+
+ METHOD create_external_link.
+
+ ov_link = zcl_excel_hyperlink=>create( iv_url = iv_url
+ iv_internal = abap_false ).
+ENDMETHOD.
+
+
+
+
+
+ METHOD create_internal_link.
+ ov_link = zcl_excel_hyperlink=>create( iv_url = iv_location
+ iv_internal = abap_true ).
+ENDMETHOD.
+
+
+
+
+ METHOD get_ref.
+ ev_ref = row.
+ CONDENSE ev_ref.
+ CONCATENATE column ev_ref INTO ev_ref.
+ENDMETHOD.
+
+
+
+
+ method GET_URL.
+ ev_url = me->location.
+endmethod.
+
+
+
+
+ method IS_INTERNAL.
+ ev_ret = me->internal.
+endmethod.
+
+
+
+
+
+ METHOD set_cell_reference.
+ me->column = ip_column.
+ me->row = ip_row.
+ENDMETHOD.
+
+
+
diff --git a/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk b/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk
index 2a13192..91a816e 100644
--- a/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk
+++ b/ZA2X/CLAS/ZCL_EXCEL_WORKSHEET.slnk
@@ -128,7 +128,8 @@ public section.
!IP_ROW type ZEXCEL_CELL_ROW
!IP_VALUE type SIMPLE optional
!IP_FORMULA type ZEXCEL_CELL_FORMULA optional
- !IP_STYLE type ZEXCEL_CELL_STYLE optional .
+ !IP_STYLE type ZEXCEL_CELL_STYLE optional
+ !IP_HYPERLINK type ref to ZCL_EXCEL_HYPERLINK optional .
methods SET_CELL_STYLE
importing
!IP_COLUMN type ZEXCEL_CELL_COLUMN_ALPHA
@@ -148,7 +149,13 @@ public section.
!IP_BODY_STYLE type ZEXCEL_CELL_STYLE optional
!IP_TABLE_TITLE type STRING
!IP_TOP_LEFT_COLUMN type ZEXCEL_CELL_COLUMN_ALPHA default 'B'
- !IP_TOP_LEFT_ROW type ZEXCEL_CELL_ROW default 3 .
+ !IP_TOP_LEFT_ROW type ZEXCEL_CELL_ROW default 3 .
+ methods GET_HYPERLINKS_SIZE
+ returning
+ value(EP_SIZE) type I .
+ methods GET_HYPERLINKS_ITERATOR
+ returning
+ value(EO_ITERATOR) type ref to CL_OBJECT_COLLECTION_ITERATOR .
*"* protected components of class ZCL_EXCEL_WORKSHEET
*"* do not include other source files here!!!
protected section.
@@ -171,6 +178,7 @@ private section.
data ROW_DIMENSIONS type ZEXCEL_T_WORKSHEET_ROWDIMENSIO .
data TABLES type ref to CL_OBJECT_COLLECTION .
data UPPER_CELL type ZEXCEL_S_CELL_DATA .
+ data HYPERLINKS type ref to CL_OBJECT_COLLECTION .
methods UPDATE_DIMENSION_RANGE .
*"* local class implementation for public class
@@ -209,6 +217,7 @@ private section.
+
METHOD zif_excel_sheet_protection~initialize.
@@ -390,6 +399,7 @@ endmethod.
CREATE OBJECT tables.
CREATE OBJECT drawings.
me->zif_excel_sheet_protection~initialize( ).
+ CREATE OBJECT hyperlinks.
* initialize active cell coordinates
active_cell-cell_row = 1.
@@ -709,7 +719,8 @@ endmethod.
- method SET_CELL.
+
+ METHOD set_cell.
DATA: lv_column TYPE zexcel_cell_column,
ls_sheet_content TYPE zexcel_s_cell_data,
@@ -766,6 +777,12 @@ endmethod.
ENDCASE.
ENDIF.
+ IF ip_hyperlink IS BOUND.
+ ip_hyperlink->set_cell_reference( ip_column = ip_column
+ ip_row = ip_row ).
+ me->hyperlinks->add( ip_hyperlink ).
+ ENDIF.
+
lv_column = zcl_excel_common=>convert_column2int( ip_column ).
READ TABLE sheet_content ASSIGNING <fs_sheet_content> WITH KEY cell_row = ip_row
@@ -964,4 +981,18 @@ endmethod.
endmethod.
+
+
+ METHOD get_hyperlinks_iterator.
+ eo_iterator = hyperlinks->get_iterator( ).
+ENDMETHOD.
+
+
+
+
+ METHOD get_hyperlinks_size.
+ ep_size = hyperlinks->size( ).
+ENDMETHOD.
+
+
diff --git a/ZA2X/CLAS/ZCL_EXCEL_WRITER_2007.slnk b/ZA2X/CLAS/ZCL_EXCEL_WRITER_2007.slnk
index e320ca2..ca279ec 100644
--- a/ZA2X/CLAS/ZCL_EXCEL_WRITER_2007.slnk
+++ b/ZA2X/CLAS/ZCL_EXCEL_WRITER_2007.slnk
@@ -1722,7 +1722,8 @@ endmethod.
ls_style_mapping TYPE zexcel_s_styles_mapping,
lv_freeze_cell_row TYPE zexcel_cell_row,
lv_freeze_cell_column TYPE zexcel_cell_column,
- lv_freeze_cell_column_alpha TYPE zexcel_cell_column_alpha.
+ lv_freeze_cell_column_alpha TYPE zexcel_cell_column_alpha,
+ lv_relation_id TYPE i.
DATA: default_col_dimension TYPE REF TO zcl_excel_worksheet_columndime,
default_row_dimension TYPE REF TO zcl_excel_worksheet_rowdimensi.
@@ -2307,6 +2308,49 @@ endmethod.
lo_element_root->append_child( new_child = lo_element ).
ENDIF.
+* links
+ DATA: lv_hyperlinks_count TYPE i,
+ lo_link TYPE REF TO zcl_excel_hyperlink.
+
+ lv_hyperlinks_count = io_worksheet->get_hyperlinks_size( ).
+ IF lv_hyperlinks_count > 0.
+ lo_element = lo_document->create_simple_element( name = 'hyperlinks'
+ parent = lo_document ).
+
+ lv_relation_id = io_worksheet->get_tables_size( ). "need to count tables
+ lo_iterator = io_worksheet->get_hyperlinks_iterator( ).
+ WHILE lo_iterator->if_object_collection_iterator~has_next( ) EQ abap_true.
+ lo_link ?= lo_iterator->if_object_collection_iterator~get_next( ).
+
+ lo_element_2 = lo_document->create_simple_element( name = 'hyperlink'
+ parent = lo_element ).
+
+ lv_value = lo_link->get_ref( ).
+ lo_element_2->set_attribute_ns( name = 'ref'
+ value = lv_value ).
+
+ IF lo_link->is_internal( ) = abap_true.
+ lv_value = lo_link->get_url( ).
+ lo_element_2->set_attribute_ns( name = 'location'
+ value = lv_value ).
+ ELSE.
+ ADD 1 TO lv_relation_id.
+
+ lv_value = lv_relation_id.
+ CONDENSE lv_value.
+ CONCATENATE 'rId' lv_value INTO lv_value.
+
+ lo_element_2->set_attribute_ns( name = 'r:id'
+ value = lv_value ).
+
+ ENDIF.
+
+ lo_element->append_child( new_child = lo_element_2 ).
+ ENDWHILE.
+
+ lo_element_root->append_child( new_child = lo_element ).
+ ENDIF.
+
" pageMargins node
lo_element = lo_document->create_simple_element( name = lc_xml_node_pagemargins
parent = lo_document ).
@@ -2467,13 +2511,13 @@ endmethod.
lo_element->set_attribute_ns( name = 'count'
value = lv_value ).
- lv_table_count = 0.
+ lv_relation_id = 0.
lo_iterator = io_worksheet->get_tables_iterator( ).
WHILE lo_iterator->if_object_collection_iterator~has_next( ) EQ abap_true.
lo_table ?= lo_iterator->if_object_collection_iterator~get_next( ).
- ADD 1 TO lv_table_count.
+ ADD 1 TO lv_relation_id.
- lv_value = lv_table_count.
+ lv_value = lv_relation_id.
CONDENSE lv_value.
CONCATENATE 'rId' lv_value INTO lv_value.
lo_element_2 = lo_document->create_simple_element( name = 'tablePart'
@@ -2523,10 +2567,13 @@ ENDMETHOD.
lc_xml_attr_id TYPE string VALUE 'Id',
lc_xml_attr_type TYPE string VALUE 'Type',
lc_xml_attr_target TYPE string VALUE 'Target',
+ lc_xml_attr_target_mode TYPE string VALUE 'TargetMode',
+ lc_xml_val_external TYPE string VALUE 'External',
" Node namespace
lc_xml_node_rels_ns TYPE string VALUE 'http://schemas.openxmlformats.org/package/2006/relationships',
lc_xml_node_rid_table_tp TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/table',
lc_xml_node_rid_drawing_tp TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing'.
+ lc_xml_node_rid_link_tp TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink'.
DATA: lo_ixml TYPE REF TO if_ixml,
lo_document TYPE REF TO if_ixml_document,
@@ -2537,7 +2584,8 @@ ENDMETHOD.
lo_ostream TYPE REF TO if_ixml_ostream,
lo_renderer TYPE REF TO if_ixml_renderer,
lo_iterator TYPE REF TO cl_object_collection_iterator,
- lo_table TYPE REF TO zcl_excel_table.
+ lo_table TYPE REF TO zcl_excel_table,
+ lo_link TYPE REF TO zcl_excel_hyperlink.
DATA: lv_value TYPE string,
lv_counter TYPE i,
@@ -2590,6 +2638,30 @@ ENDMETHOD.
lo_element_root->append_child( new_child = lo_element ).
ENDWHILE.
+ lo_iterator = io_worksheet->get_hyperlinks_iterator( ).
+ WHILE lo_iterator->if_object_collection_iterator~has_next( ) EQ abap_true.
+ lo_link ?= lo_iterator->if_object_collection_iterator~get_next( ).
+ ADD 1 TO lv_counter.
+
+ lv_value = lv_counter.
+ CONDENSE lv_value.
+ CONCATENATE 'rId' lv_value INTO lv_value.
+
+ lo_element = lo_document->create_simple_element( name = lc_xml_node_relationship
+ parent = lo_document ).
+ lo_element->set_attribute_ns( name = lc_xml_attr_id
+ value = lv_value ).
+ lo_element->set_attribute_ns( name = lc_xml_attr_type
+ value = lc_xml_node_rid_link_tp ).
+
+ lv_value = lo_link->get_url( ).
+ lo_element->set_attribute_ns( name = lc_xml_attr_target
+ value = lv_value ).
+ lo_element->set_attribute_ns( name = lc_xml_attr_target_mode
+ value = lc_xml_val_external ).
+ lo_element_root->append_child( new_child = lo_element ).
+ ENDWHILE.
+
* drawing
DATA: lo_drawings TYPE REF TO zcl_excel_drawings.
diff --git a/ZA2X/PROG/ZDEMO_EXCEL1.slnk b/ZA2X/PROG/ZDEMO_EXCEL1.slnk
index d6310e6..4537926 100644
--- a/ZA2X/PROG/ZDEMO_EXCEL1.slnk
+++ b/ZA2X/PROG/ZDEMO_EXCEL1.slnk
@@ -1,5 +1,5 @@
-
+
@@ -17,7 +17,9 @@ REPORT zdemo_excel1.
DATA: lo_excel TYPE REF TO zcl_excel,
lo_excel_writer TYPE REF TO zif_excel_writer,
- lo_worksheet TYPE REF TO zcl_excel_worksheet.
+ lo_worksheet TYPE REF TO zcl_excel_worksheet,
+ lo_hyperlink TYPE REF TO zcl_excel_hyperlink,
+ column_dimension TYPE REF TO zcl_excel_worksheet_columndime.
DATA: lv_file TYPE xstring,
lv_bytecount TYPE i,
@@ -59,6 +61,11 @@ START-OF-SELECTION.
lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = 'Hello world' ).
lo_worksheet->set_cell( ip_column = 'B' ip_row = 3 ip_value = sy-datum ).
lo_worksheet->set_cell( ip_column = 'C' ip_row = 3 ip_value = sy-uzeit ).
+ lo_hyperlink = zcl_excel_hyperlink=>create_external_link( iv_url = 'https://cw.sdn.sap.com/cw/groups/abap2xlsx' ).
+ lo_worksheet->set_cell( ip_column = 'B' ip_row = 4 ip_value = 'Click here to visit abap2xlsx homepage' ip_hyperlink = lo_hyperlink ).
+
+ column_dimension = lo_worksheet->get_column_dimension( 'B' ).
+ column_dimension->set_width( 11 ).
CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007.
lv_file = lo_excel_writer->write_file( lo_excel ).
diff --git a/ZA2X/PROG/ZDEMO_EXCEL4.slnk b/ZA2X/PROG/ZDEMO_EXCEL4.slnk
index b9ecd09..c3610b1 100644
--- a/ZA2X/PROG/ZDEMO_EXCEL4.slnk
+++ b/ZA2X/PROG/ZDEMO_EXCEL4.slnk
@@ -1,5 +1,5 @@
-
+
@@ -17,7 +17,8 @@ REPORT zdemo_excel4.
DATA: lo_excel TYPE REF TO zcl_excel,
lo_excel_writer TYPE REF TO zif_excel_writer,
- lo_worksheet TYPE REF TO zcl_excel_worksheet.
+ lo_worksheet TYPE REF TO zcl_excel_worksheet,
+ lo_hyperlink TYPE REF TO zcl_excel_hyperlink.
DATA: lv_file TYPE xstring,
lv_bytecount TYPE i,
@@ -57,6 +58,8 @@ START-OF-SELECTION.
lo_worksheet = lo_excel->get_active_worksheet( ).
lo_worksheet->title = 'Sheet1'.
lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = 'This is the first sheet' ).
+ lo_hyperlink = zcl_excel_hyperlink=>create_internal_link( iv_location = 'Sheet2!B2' ).
+ lo_worksheet->set_cell( ip_column = 'B' ip_row = 3 ip_value = 'This is link to second sheet' ip_hyperlink = lo_hyperlink ).
lo_worksheet->sheet_setup->set_page_margins( ip_header = '1' ip_footer = '1' ip_unit = 'cm' ).
lo_worksheet->sheet_setup->black_and_white = 'X'.
@@ -73,6 +76,8 @@ START-OF-SELECTION.
lo_worksheet = lo_excel->add_new_worksheet( ).
lo_worksheet->title = 'Sheet2'.
lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = 'This is the second sheet' ).
+ lo_hyperlink = zcl_excel_hyperlink=>create_internal_link( iv_location = 'Sheet1!B2' ).
+ lo_worksheet->set_cell( ip_column = 'B' ip_row = 3 ip_value = 'This is link to first sheet' ip_hyperlink = lo_hyperlink ).
CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007.
lv_file = lo_excel_writer->write_file( lo_excel ).