【问题标题】:PHPWord Repeat template tag replacement inside one documentPHPWord 在一个文档中重复模板标签替换
【发布时间】:2012-08-01 12:34:00
【问题描述】:

我有一个 word 文档模板文件和变量来填充它(使用 mysql),但我不知道如何一遍又一遍地重复这个过程,直到 mysql while 进程停止,也就是它保存文件的时候并允许用户下载。 例如:
生成的Word文档:
填充模板
填充模板
填充模板
填充模板
结束文件
允许用户下载文件。

【问题讨论】:

    标签: php phpword


    【解决方案1】:

    它将帮助您http://phpword.codeplex.com/discussions/254789 PHPWord 库中的 template.php 包含一个函数

    【讨论】:

      【解决方案2】:

      您只想用数据库中的内容替换一些变量。你可以这样做:

      $results=mysql_query(YOUR QUERY HERE);
      $template='Some contents of the template';
      while ($row= mysql_fetch_array($results)){
         $template=str_replace($row['template_variable'], $row['value_for_this_template'], $template);
      }
      echo $template; //template now has the new values stored in the mysql database
      

      然后您将拥有包含 mysql 值的模板。这假设您有一个 mysql 表列“template_variable”,它与模板文件中最初的内容相对应,并且该模板的特定输出所需的值在“value_for_this_template”中。

      希望有帮助!

      【讨论】:

      • 对不起,我的意思是模板实际上是一个word文档,替换的处理过程是由PHPWord脚本来处理的。
      猜你喜欢
      • 2016-01-19
      • 2015-07-22
      • 2019-06-13
      • 2020-12-24
      • 2018-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-19
      相关资源
      最近更新 更多