In this example, it is described how the data in xml stream with table structure is merged into word template:

/wp-content/uploads/2014/08/clipboard1_521261.png

The word looks like below after merge:

/wp-content/uploads/2014/08/clipboard2_521262.png

You should have gone through Understand how the word template is merged with xml data stream – part 1 – Simple structure before you start with table merge.


You could find the template and xml data file used in this example from attachment.


Merge step1 cl_crm_oi_docx_helper=>replace_vars_uuid_with_path

The same as the step in simple structure merge.

Merge step2 add necessary namespace to every node in xml

The same as the step in simple structure merge.

Merge step3 cl_crm_oi_docx_transform_rt=>transform

the formatted template source( uuid replaced with complete path ) and formatted xml data source( n0 namespace added ) are passed into this method.

step3.1 cl_crm_oi_docx_transform_rt=>indicate_tree

The xml node is further enriched with attribute Loopcount and Path, which are especially used for render data with table structure.

See how the xml source looks like after method call:

/wp-content/uploads/2014/08/clipboard3_521263.png

  • New attribute Path is added for each node.
  • Loopcount: total number of nodes which have the same name as current node
  • Loopid: index of current node

step3.2 cl_crm_oi_docx_transform_rt=>update_payload_from_addinsch

This method will create a new attribute sapvartype with value “T” for those node in xml source with table structure:

/wp-content/uploads/2014/08/clipboard4_521264.png

step3.3 recursively call cl_crm_oi_docx_transform_rt=>process_node_cc


/wp-content/uploads/2014/08/clipboard5_521265.png

We identify the current node ( n0:Z_JENS_GET_MORE_COMPLEXResponse/n0:ET_ORDER/ ) is a table node by querying attribute sapvartype with value “T”:

/wp-content/uploads/2014/08/clipboard6_521266.png

And we know from the attribute Loopcount added in step3.1 that currently there are two Item nodes in xml, which means we need to dynamically generate two new rows in the word template to display the table data contained in xml. We can achieve this by cloning the existing row in the word template which contains the mapping information.

/wp-content/uploads/2014/08/clipboard7_521267.png

the cloning is done in this method:

/wp-content/uploads/2014/08/clipboard8_521268.png

/wp-content/uploads/2014/08/clipboard9_521269.png

Have a look at the word template source code after method call:

/wp-content/uploads/2014/08/clipboard10_521270.png

w:sdt node for table header display:

/wp-content/uploads/2014/08/clipboard11_521271.png

w:tr ( the first cloned node ):

/wp-content/uploads/2014/08/clipboard12_521272.png

w:tr ( the second cloned node ):

/wp-content/uploads/2014/08/clipboard13_521276.png

Now the placeholder for table data display is available in word template source. A recursive call is made with iv_node_intable = X to fill cloned table row in word template with table data in xml data file.

/wp-content/uploads/2014/08/clipboard14_521277.png

The left stuff is the same as the step for simple structure:

1. get the dom element node which is to be filled by each table structure field in xml data file:

/wp-content/uploads/2014/08/clipboard15_521278.png

2. call set_content_control_value to set the value 0005012366 of node OBJECT_ID in xml data file to the dom element node from the first cloned table row ( lv_loopid_tr = @1 ).

/wp-content/uploads/2014/08/clipboard16_521279.png

Open the final merged word document:

/wp-content/uploads/2014/08/clipboard17_521280.png

You should find from document source code that all table row fields whose data are filled from xml data file have a new attribute saprtvalue with value X.

/wp-content/uploads/2014/08/clipboard18_521281.png

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply