打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Generating Microsoft Word Doc with dynamic data | SAP Blogs

https://blogs.sap.com/2016/02/17/generating-microsoft-word-doc-with-dynamic-data/

In many cases there is a requirement to generate Microsoft word doc , which contains standard template data as well as dynamic variable data for creating an attachment.

Though there is standard functionality to create attachment in CRM with templates , but many times it may not suffice our requirement .

In this blog , I will provide steps which can be used to generate Microsoft word documents as attachment with dynamic data.

Software Required : Microsoft Word Content Control Tool Kit

Step 1 :  Create a Microsoft word template using the Content controls.

You can create the Microsoft word template , which contains the fixed text as well as dynamic data that you want to populate. The dynamic data will be handled by content controls at run time .

Content controls are predefined pieces of contents that include text blocks, drop-down menus, check boxes, and pictures, etc. You can map content controls with elements in an custom XML file so that the data can be automatically populated in the document.

Step 2:  Binding content controls to the custom XML part

Open the Word template you have just created in step 1 in word content control toolkit . Bind  the content controls to Custom XML parts.

Step 3 : Uploading the template to the MIME folder

Now upload the word template with content controls into the Mime repository in the SAP system  .

Go to SE80 and select MIME Repository, and expand to folder  . You can select the folder in which you want to upload the template.

Right-click your folder and choose Import MIME Objects. Select and upload the template.

On the Create New Document screen, select Application-Specific MIME Object as the document class, enter a document name, and choose Save.

Step 4 : Generate the XML data

Go to transaction XSLT_TOOLS and create a simple transformation Z_XML_GEN.

This transformation will  contain the dynamic data that you want to fill into the template . In our case we want to fill the Sold to name and sold to number from the SAP system .

Hence we write this transformation.This will generate custom XML with the data for sold to name and  sold to id.

Step 5: Fetch the Word Document template

Now in your program (where you actually want to generate the word template ), first we need to fetch the word template which we uploaded in Mime repository (step 3). It will be loaded in variable docx.

Step 6: Fetch Data and Call the transformation to generate custom XML

Now fill the data Sold to name and sold to id into structure ls_data (this structure can contain 2 fields sold_to_name and sold_to_id).  And call the transformation Z_GEN_XML with this data . The transformation will generate the custom XML  with the data for sold to name and sold to id. This will be stored in variable ‘texts’

Step 7: Create the style sheets for the word template .

In step 5 we had fetched the word template from the mime repository into variable docx. Now we generate style sheet for this docx. Data stored in variable lt_xslttab.

Step 8 : Merge data

Merge the word template style sheet created in step 7 with the XML data generated from transformation in step 6.

Step 9 : Generate the attachment object with the merged data

lv_doc now contains the template data along with the merged data . Make sure everything is in  XSTRING format. With this you can now create a attachment object(the programming for this is easy , you can simply refer the standard coding for that ) and display it in the web UI.

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
word模板和XML数据源是如何合并生成最后的word文档的详细过程
java生成复杂word文档的完美解决方案
Grouping and Summing the Values in XML Using XSLT
Word Template | Axure RP
java如何生成word文档_使用Java生成word文档(附源码)
如何能让Java生成复杂Word文档(1)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服