TinyButStrong OpenTBS include output of one template into other Sub Templating

牧云@^-^@ 提交于 2021-02-18 19:32:13

问题


we are using TinyButStrong and OpenTbs to prepare word (docx) documents from templates. We basically need to process several sub-templates (based on what user selected) and then merge all as table rows into the main template.

So basically we need something like this:

Final Template Table Row 1 - Output from docx1 template Row 2 - Output from docx2 template

The rows can vary, so do the sub template file for each individual row.

TBS seems to have a subtpl markup, however its not clear how it takes up arguments especially when we need to tell it which file to use and the parameters for each template to bind with.


回答1:


It is very difficult to merge two DOCX documents (same for XLSX, PPTX, ...) because of internal elements managed automatically by Ms Office (pictures, charts, styles, numbering, ... ).

Internal elements have internal Ids that are different from a DOCX to another DOCX even if they are visually totally equal.

Thus, when you take a piece of content from a first document, its internal Ids are probably discordant with the other document in which you wish to insert it. When this problem occurs, Ms Office give the message

We're sorry. We can't open xxxxx.docx because we found a problem with its contents.

The only way to insert an external snippet from a DOCX to another DOCX is to be sure that no internal IDS are used in the snippet. Such snippets are hard to build.

But the technical to retrieve the snippet from a document is simple. See GetBlockSource()

And and insert it into another is simple too. See MergeBlock() with source type = 'text'.



来源:https://stackoverflow.com/questions/52397926/tinybutstrong-opentbs-include-output-of-one-template-into-other-sub-templating

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!