mirror of
https://github.com/abap2xlsx/abap2xlsx.git
synced 2025-05-05 03:02:04 +08:00
309 lines
16 KiB
XML
309 lines
16 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<CLAS CLSNAME="ZCL_EXCEL_WRITER_XLSM" VERSION="1" LANGU="E" DESCRIPT="Excel with macro writer" CATEGORY="00" EXPOSURE="2" STATE="1" RELEASE="0" CLSCCINCL="X" FIXPT="X" UNICODE="X" CLSBCCAT="00" DURATION_TYPE="0 " RISK_LEVEL="0 " ZSAPLINK_PLUGIN_MAJOR_VERSION="0 " ZSAPLINK_PLUGIN_MINOR_VERSION="1 " ZSAPLINK_PLUGIN_BUILD_VERSION="0 " ZSAPLINK_PLUGIN_INFO1="ZSAPLINK_CLASS is part of the main ZSAPLINK project --> This plugin found there instead of ZSAPLINK_PLUGINS projects" ZSAPLINK_PLUGIN_INFO2="SAPLINK homepage: https://www.assembla.com/spaces/saplink/wiki" ZSAPLINK_PLUGIN_INFO3="Download from https://www.assembla.com/code/saplink/subversion/nodes" ZSAPLINK_PLUGIN_INFO4="and navigate to: trunk -> core -> ZSAPLINK -> CLAS -> ZSAPLINK_CLASS.slnk" REFCLSNAME="ZCL_EXCEL_WRITER_2007">
|
|
<localImplementation>*"* use this source file for the definition and implementation of
|
|
*"* local helper classes, interface definitions and type
|
|
*"* declarations</localImplementation>
|
|
<localTypes>*"* use this source file for any type of declarations (class
|
|
*"* definitions, interfaces or type declarations) you need for
|
|
*"* components in the private section</localTypes>
|
|
<localMacros>*"* use this source file for any macro definitions you need
|
|
*"* in the implementation part of the class</localMacros>
|
|
<attribute CLSNAME="ZCL_EXCEL_WRITER_XLSM" CMPNAME="C_XL_VBAPROJECT" VERSION="1" LANGU="E" EXPOSURE="1" STATE="1" EDITORDER="1 " ATTDECLTYP="2" ATTVALUE="'xl/vbaProject.bin'" ATTEXPVIRT="0" TYPTYPE="1" TYPE="STRING" SRCROW1="0 " SRCCOLUMN1="0 " SRCROW2="0 " SRCCOLUMN2="0 " TYPESRC_LENG="0 "/>
|
|
<inheritance CLSNAME="ZCL_EXCEL_WRITER_XLSM" REFCLSNAME="ZCL_EXCEL_WRITER_2007" VERSION="1" STATE="1">
|
|
<redefinition CLSNAME="ZCL_EXCEL_WRITER_XLSM" REFCLSNAME="ZCL_EXCEL_WRITER_2007" VERSION="1" MTDNAME="ADD_FURTHER_DATA_TO_ZIP" EXPOSURE="1"/>
|
|
<redefinition CLSNAME="ZCL_EXCEL_WRITER_XLSM" REFCLSNAME="ZCL_EXCEL_WRITER_2007" VERSION="1" MTDNAME="CREATE_CONTENT_TYPES" EXPOSURE="1"/>
|
|
<redefinition CLSNAME="ZCL_EXCEL_WRITER_XLSM" REFCLSNAME="ZCL_EXCEL_WRITER_2007" VERSION="1" MTDNAME="CREATE_XL_RELATIONSHIPS" EXPOSURE="1"/>
|
|
<redefinition CLSNAME="ZCL_EXCEL_WRITER_XLSM" REFCLSNAME="ZCL_EXCEL_WRITER_2007" VERSION="1" MTDNAME="CREATE_XL_SHEET" EXPOSURE="1"/>
|
|
<redefinition CLSNAME="ZCL_EXCEL_WRITER_XLSM" REFCLSNAME="ZCL_EXCEL_WRITER_2007" VERSION="1" MTDNAME="CREATE_XL_WORKBOOK" EXPOSURE="1"/>
|
|
</inheritance>
|
|
<method CLSNAME="ZCL_EXCEL_WRITER_2007" CMPNAME="ADD_FURTHER_DATA_TO_ZIP" VERSION="0" EXPOSURE="0" STATE="0" EDITORDER="0 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="0" BCMTDCAT="00" BCMTDSYN="0">
|
|
<source>METHOD add_further_data_to_zip.
|
|
|
|
super->add_further_data_to_zip( io_zip = io_zip ).
|
|
|
|
* Add vbaProject.bin to zip
|
|
io_zip->add( name = me->c_xl_vbaproject
|
|
content = me->excel->zif_excel_book_vba_project~vbaproject ).
|
|
|
|
ENDMETHOD.</source>
|
|
</method>
|
|
<method CLSNAME="ZCL_EXCEL_WRITER_2007" CMPNAME="CREATE_CONTENT_TYPES" VERSION="0" EXPOSURE="0" STATE="0" EDITORDER="0 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="0" BCMTDCAT="00" BCMTDSYN="0">
|
|
<source>METHOD create_content_types.
|
|
** Constant node name
|
|
DATA: lc_xml_node_workb_ct TYPE string VALUE 'application/vnd.ms-excel.sheet.macroEnabled.main+xml',
|
|
lc_xml_node_default TYPE string VALUE 'Default',
|
|
" Node attributes
|
|
lc_xml_attr_partname TYPE string VALUE 'PartName',
|
|
lc_xml_attr_extension TYPE string VALUE 'Extension',
|
|
lc_xml_attr_contenttype TYPE string VALUE 'ContentType',
|
|
lc_xml_attr_codename TYPE string VALUE 'codeName',
|
|
lc_xml_node_workb_pn TYPE string VALUE '/xl/workbook.xml',
|
|
lc_xml_node_bin_ext TYPE string VALUE 'bin',
|
|
lc_xml_node_bin_ct TYPE string VALUE 'application/vnd.ms-office.vbaProject'.
|
|
|
|
|
|
DATA: lo_ixml TYPE REF TO if_ixml,
|
|
lo_document TYPE REF TO if_ixml_document,
|
|
lo_document_xml TYPE REF TO cl_xml_document,
|
|
lo_element_root TYPE REF TO if_ixml_node,
|
|
lo_element TYPE REF TO if_ixml_element,
|
|
lo_collection TYPE REF TO if_ixml_node_collection,
|
|
lo_iterator TYPE REF TO if_ixml_node_iterator,
|
|
lo_node TYPE REF TO if_ixml_node,
|
|
lo_encoding TYPE REF TO if_ixml_encoding,
|
|
lo_streamfactory TYPE REF TO if_ixml_stream_factory,
|
|
lo_ostream TYPE REF TO if_ixml_ostream,
|
|
lo_renderer TYPE REF TO if_ixml_renderer.
|
|
|
|
DATA: lv_subrc TYPE sysubrc,
|
|
lv_contenttype TYPE string,
|
|
lv_syindex(2) TYPE c.
|
|
|
|
**********************************************************************
|
|
* STEP 3: Create standard contentType
|
|
ep_content = super->create_content_types( ).
|
|
|
|
**********************************************************************
|
|
* STEP 2: modify XML adding the extension bin definition
|
|
|
|
CREATE OBJECT lo_document_xml.
|
|
lv_subrc = lo_document_xml->parse_xstring( ep_content ).
|
|
|
|
lo_document ?= lo_document_xml->m_document.
|
|
lo_element_root = lo_document->if_ixml_node~get_first_child( ).
|
|
|
|
" extension node
|
|
lo_element = lo_document->create_simple_element( name = lc_xml_node_default
|
|
parent = lo_document ).
|
|
lo_element->set_attribute_ns( name = lc_xml_attr_extension
|
|
value = lc_xml_node_bin_ext ).
|
|
lo_element->set_attribute_ns( name = lc_xml_attr_contenttype
|
|
value = lc_xml_node_bin_ct ).
|
|
lo_element_root->append_child( new_child = lo_element ).
|
|
|
|
**********************************************************************
|
|
* STEP 3: modify XML changing the contentType of node Override /xl/workbook.xml
|
|
|
|
lo_collection = lo_document->get_elements_by_tag_name( 'Override' ).
|
|
lo_iterator = lo_collection->create_iterator( ).
|
|
lo_element ?= lo_iterator->get_next( ).
|
|
WHILE lo_element IS BOUND.
|
|
lv_contenttype = lo_element->get_attribute_ns( lc_xml_attr_partname ).
|
|
IF lv_contenttype EQ lc_xml_node_workb_pn.
|
|
lo_element->remove_attribute_ns( lc_xml_attr_contenttype ).
|
|
lo_element->set_attribute_ns( name = lc_xml_attr_contenttype
|
|
value = lc_xml_node_workb_ct ).
|
|
EXIT.
|
|
ENDIF.
|
|
lo_element ?= lo_iterator->get_next( ).
|
|
ENDWHILE.
|
|
|
|
**********************************************************************
|
|
* STEP 3: Create xstring stream
|
|
CLEAR ep_content.
|
|
lo_ixml = cl_ixml=>create( ).
|
|
lo_streamfactory = lo_ixml->create_stream_factory( ).
|
|
lo_ostream = lo_streamfactory->create_ostream_xstring( string = ep_content ).
|
|
lo_renderer = lo_ixml->create_renderer( ostream = lo_ostream document = lo_document ).
|
|
lo_renderer->render( ).
|
|
|
|
ENDMETHOD.</source>
|
|
</method>
|
|
<method CLSNAME="ZCL_EXCEL_WRITER_2007" CMPNAME="CREATE_XL_RELATIONSHIPS" VERSION="0" EXPOSURE="0" STATE="0" EDITORDER="0 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="0" BCMTDCAT="00" BCMTDSYN="0">
|
|
<source>METHOD create_xl_relationships.
|
|
|
|
** Constant node name
|
|
DATA: lc_xml_node_relationships TYPE string VALUE 'Relationships',
|
|
lc_xml_node_relationship TYPE string VALUE 'Relationship',
|
|
" Node attributes
|
|
lc_xml_attr_id TYPE string VALUE 'Id',
|
|
lc_xml_attr_type TYPE string VALUE 'Type',
|
|
lc_xml_attr_target TYPE string VALUE 'Target',
|
|
" Node id
|
|
lc_xml_node_ridx_id TYPE string VALUE 'rId#',
|
|
" Node type
|
|
lc_xml_node_rid_vba_tp TYPE string VALUE 'http://schemas.microsoft.com/office/2006/relationships/vbaProject',
|
|
" Node target
|
|
lc_xml_node_rid_vba_tg TYPE string VALUE 'vbaProject.bin'.
|
|
|
|
DATA: lo_ixml TYPE REF TO if_ixml,
|
|
lo_document TYPE REF TO if_ixml_document,
|
|
lo_document_xml TYPE REF TO cl_xml_document,
|
|
lo_element_root TYPE REF TO if_ixml_node,
|
|
lo_element TYPE REF TO if_ixml_element,
|
|
lo_node TYPE REF TO if_ixml_node,
|
|
lo_encoding TYPE REF TO if_ixml_encoding,
|
|
lo_streamfactory TYPE REF TO if_ixml_stream_factory,
|
|
lo_ostream TYPE REF TO if_ixml_ostream,
|
|
lo_renderer TYPE REF TO if_ixml_renderer.
|
|
|
|
DATA: lv_xml_node_ridx_tg TYPE string,
|
|
lv_xml_node_ridx_id TYPE string,
|
|
lv_size TYPE i,
|
|
lv_subrc TYPE sysubrc,
|
|
lv_syindex(2) TYPE c.
|
|
|
|
**********************************************************************
|
|
* STEP 3: Create standard relationship
|
|
ep_content = super->create_xl_relationships( ).
|
|
|
|
**********************************************************************
|
|
* STEP 2: modify XML adding the vbaProject relation
|
|
|
|
CREATE OBJECT lo_document_xml.
|
|
lv_subrc = lo_document_xml->parse_xstring( ep_content ).
|
|
|
|
lo_document ?= lo_document_xml->m_document.
|
|
lo_element_root = lo_document->if_ixml_node~get_first_child( ).
|
|
|
|
|
|
lv_size = excel->get_worksheets_size( ).
|
|
|
|
" Relationship node
|
|
lo_element = lo_document->create_simple_element( name = lc_xml_node_relationship
|
|
parent = lo_document ).
|
|
ADD 4 TO lv_size.
|
|
lv_syindex = lv_size.
|
|
SHIFT lv_syindex RIGHT DELETING TRAILING space.
|
|
SHIFT lv_syindex LEFT DELETING LEADING space.
|
|
lv_xml_node_ridx_id = lc_xml_node_ridx_id.
|
|
REPLACE ALL OCCURRENCES OF '#' IN lv_xml_node_ridx_id WITH lv_syindex.
|
|
lo_element->set_attribute_ns( name = lc_xml_attr_id
|
|
value = lv_xml_node_ridx_id ).
|
|
lo_element->set_attribute_ns( name = lc_xml_attr_type
|
|
value = lc_xml_node_rid_vba_tp ).
|
|
lo_element->set_attribute_ns( name = lc_xml_attr_target
|
|
value = lc_xml_node_rid_vba_tg ).
|
|
lo_element_root->append_child( new_child = lo_element ).
|
|
|
|
**********************************************************************
|
|
* STEP 3: Create xstring stream
|
|
CLEAR ep_content.
|
|
lo_ixml = cl_ixml=>create( ).
|
|
lo_streamfactory = lo_ixml->create_stream_factory( ).
|
|
lo_ostream = lo_streamfactory->create_ostream_xstring( string = ep_content ).
|
|
lo_renderer = lo_ixml->create_renderer( ostream = lo_ostream document = lo_document ).
|
|
lo_renderer->render( ).
|
|
|
|
ENDMETHOD.</source>
|
|
</method>
|
|
<method CLSNAME="ZCL_EXCEL_WRITER_2007" CMPNAME="CREATE_XL_SHEET" VERSION="0" EXPOSURE="0" STATE="0" EDITORDER="0 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="0" BCMTDCAT="00" BCMTDSYN="0">
|
|
<source>METHOD create_xl_sheet.
|
|
|
|
** Constant node name
|
|
DATA: lc_xml_attr_codename TYPE string VALUE 'codeName'.
|
|
|
|
DATA: lo_ixml TYPE REF TO if_ixml,
|
|
lo_document TYPE REF TO if_ixml_document,
|
|
lo_document_xml TYPE REF TO cl_xml_document,
|
|
lo_element_root TYPE REF TO if_ixml_node,
|
|
lo_element TYPE REF TO if_ixml_element,
|
|
lo_collection TYPE REF TO if_ixml_node_collection,
|
|
lo_iterator TYPE REF TO if_ixml_node_iterator,
|
|
lo_node TYPE REF TO if_ixml_node,
|
|
lo_encoding TYPE REF TO if_ixml_encoding,
|
|
lo_streamfactory TYPE REF TO if_ixml_stream_factory,
|
|
lo_ostream TYPE REF TO if_ixml_ostream,
|
|
lo_renderer TYPE REF TO if_ixml_renderer.
|
|
|
|
DATA: lv_subrc TYPE sysubrc,
|
|
lv_syindex(2) TYPE c.
|
|
|
|
**********************************************************************
|
|
* STEP 3: Create standard relationship
|
|
ep_content = super->create_xl_sheet( io_worksheet = io_worksheet
|
|
iv_active = iv_active ).
|
|
|
|
**********************************************************************
|
|
* STEP 2: modify XML adding the vbaProject relation
|
|
|
|
CREATE OBJECT lo_document_xml.
|
|
lv_subrc = lo_document_xml->parse_xstring( ep_content ).
|
|
|
|
lo_document ?= lo_document_xml->m_document.
|
|
lo_element_root = lo_document->if_ixml_node~get_first_child( ).
|
|
|
|
lo_collection = lo_document->get_elements_by_tag_name( 'sheetPr' ).
|
|
lo_iterator = lo_collection->create_iterator( ).
|
|
lo_element ?= lo_iterator->get_next( ).
|
|
WHILE lo_element IS BOUND.
|
|
lo_element->set_attribute_ns( name = lc_xml_attr_codename
|
|
value = io_worksheet->zif_excel_sheet_vba_project~codename_pr ).
|
|
lo_element ?= lo_iterator->get_next( ).
|
|
ENDWHILE.
|
|
|
|
**********************************************************************
|
|
* STEP 3: Create xstring stream
|
|
CLEAR ep_content.
|
|
lo_ixml = cl_ixml=>create( ).
|
|
lo_streamfactory = lo_ixml->create_stream_factory( ).
|
|
lo_ostream = lo_streamfactory->create_ostream_xstring( string = ep_content ).
|
|
lo_renderer = lo_ixml->create_renderer( ostream = lo_ostream document = lo_document ).
|
|
lo_renderer->render( ).
|
|
ENDMETHOD.</source>
|
|
</method>
|
|
<method CLSNAME="ZCL_EXCEL_WRITER_2007" CMPNAME="CREATE_XL_WORKBOOK" VERSION="0" EXPOSURE="0" STATE="0" EDITORDER="0 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="0" BCMTDCAT="00" BCMTDSYN="0">
|
|
<source>METHOD create_xl_workbook.
|
|
|
|
** Constant node name
|
|
DATA: lc_xml_attr_codename TYPE string VALUE 'codeName'.
|
|
|
|
DATA: lo_ixml TYPE REF TO if_ixml,
|
|
lo_document TYPE REF TO if_ixml_document,
|
|
lo_document_xml TYPE REF TO cl_xml_document,
|
|
lo_element_root TYPE REF TO if_ixml_node,
|
|
lo_element TYPE REF TO if_ixml_element,
|
|
lo_collection TYPE REF TO if_ixml_node_collection,
|
|
lo_iterator TYPE REF TO if_ixml_node_iterator,
|
|
lo_node TYPE REF TO if_ixml_node,
|
|
lo_encoding TYPE REF TO if_ixml_encoding,
|
|
lo_streamfactory TYPE REF TO if_ixml_stream_factory,
|
|
lo_ostream TYPE REF TO if_ixml_ostream,
|
|
lo_renderer TYPE REF TO if_ixml_renderer.
|
|
|
|
DATA: lv_subrc TYPE sysubrc,
|
|
lv_syindex(2) TYPE c.
|
|
|
|
**********************************************************************
|
|
* STEP 3: Create standard relationship
|
|
ep_content = super->create_xl_workbook( ).
|
|
|
|
**********************************************************************
|
|
* STEP 2: modify XML adding the vbaProject relation
|
|
|
|
CREATE OBJECT lo_document_xml.
|
|
lv_subrc = lo_document_xml->parse_xstring( ep_content ).
|
|
|
|
lo_document ?= lo_document_xml->m_document.
|
|
lo_element_root = lo_document->if_ixml_node~get_first_child( ).
|
|
|
|
lo_collection = lo_document->get_elements_by_tag_name( 'fileVersion' ).
|
|
lo_iterator = lo_collection->create_iterator( ).
|
|
lo_element ?= lo_iterator->get_next( ).
|
|
WHILE lo_element IS BOUND.
|
|
lo_element->set_attribute_ns( name = lc_xml_attr_codename
|
|
value = me->excel->zif_excel_book_vba_project~codename ).
|
|
lo_element ?= lo_iterator->get_next( ).
|
|
ENDWHILE.
|
|
|
|
lo_collection = lo_document->get_elements_by_tag_name( 'workbookPr' ).
|
|
lo_iterator = lo_collection->create_iterator( ).
|
|
lo_element ?= lo_iterator->get_next( ).
|
|
WHILE lo_element IS BOUND.
|
|
lo_element->set_attribute_ns( name = lc_xml_attr_codename
|
|
value = me->excel->zif_excel_book_vba_project~codename_pr ).
|
|
lo_element ?= lo_iterator->get_next( ).
|
|
ENDWHILE.
|
|
|
|
**********************************************************************
|
|
* STEP 3: Create xstring stream
|
|
CLEAR ep_content.
|
|
lo_ixml = cl_ixml=>create( ).
|
|
lo_streamfactory = lo_ixml->create_stream_factory( ).
|
|
lo_ostream = lo_streamfactory->create_ostream_xstring( string = ep_content ).
|
|
lo_renderer = lo_ixml->create_renderer( ostream = lo_ostream document = lo_document ).
|
|
lo_renderer->render( ).
|
|
ENDMETHOD.</source>
|
|
</method>
|
|
</CLAS>
|