drxnfdx798517235
drxnfdx798517235
2014-12-08 16:58
浏览 383
已采纳

如何使用phpWord和使用cloneBlock将变量复制到模板中

Using phpWord in my application, I try to clone a block in the template like this :

${CLONEME} <br>
     You may also notice that there’s one text break (empty paragraph) before this one that can be created also by PHPWord ${item}" <br>
${/CLONEME}

Doing this in my php code : $document->cloneBlock('CLONEME', 2}

I obtain :

" You may also notice that there’s one text break (empty paragraph) before this one that can be created also by PHPWord ${item}
You may also notice that there’s one text break (empty paragraph) before this one that can be created also by PHPWord ${item} "

but ${item} don't duplicate.

I want to have :

" You may also notice that there’s one text break (empty paragraph) before this one that can be created also by PHPWord ${item#1} You may also notice that there’s one text break (empty paragraph) before this one that can be created also by PHPWord ${item#2} "

How can I do this ? Thanks

图片转代码服务由CSDN问答提供 功能建议

在我的应用程序中使用phpWord,我尝试在模板中克隆一个块,如下所示:

  $ {CLONEME}&lt; br&gt; 
您可能还注意到,在此之前还有一个文本分隔符(空段落),也可以由PHPWord $ {item}“&lt; br&gt;创建。  
 $ {/ CLONEME} 
   
 
 

在我的php代码中执行此操作: $ document-&gt; cloneBlock('CLONEME ',2}

我获得:

“你 也可能会注意到有一个文本中断(空段) 在此之前也可以由PHPWord创建$ {item}
你还可能会注意到在 之前有一个文本中断(空段) 一个也可以由PHPWord $ {item}“

创建,但 $ {item} 不会重复。

我希望:

“您可能还注意到有一个文本中断(空段落) befor 这个也可以由PHPWord $ {item#1}创建你还可能会注意到在这个之前有一个文本中断(空段落),也可以由PHPWord $ {item#2}创建。

我该怎么做? 谢谢

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douaonong7807
    douaonong7807 2014-12-09 06:58
    已采纳

    I see 2 possibilities:

    1. extend the cloneBlock method to do what you want (or write your own) - and have a look at the cloneRow method to see how they're doing the {item}->{item#1} replacement
    2. just live with multiple {item}-tags after cloneBlock and do several calls to setValue($search, $replace, 1), limiting the replacements to one at a time

    Hope that helps...

    点赞 评论

相关推荐