【发布时间】:2012-08-01 12:34:00
【问题描述】:
我有一个 word 文档模板文件和变量来填充它(使用 mysql),但我不知道如何一遍又一遍地重复这个过程,直到 mysql while 进程停止,也就是它保存文件的时候并允许用户下载。
例如:
生成的Word文档:
填充模板
填充模板
填充模板
填充模板
结束文件
允许用户下载文件。
【问题讨论】:
我有一个 word 文档模板文件和变量来填充它(使用 mysql),但我不知道如何一遍又一遍地重复这个过程,直到 mysql while 进程停止,也就是它保存文件的时候并允许用户下载。
例如:
生成的Word文档:
填充模板
填充模板
填充模板
填充模板
结束文件
允许用户下载文件。
【问题讨论】:
它将帮助您http://phpword.codeplex.com/discussions/254789 PHPWord 库中的 template.php 包含一个函数
【讨论】:
您只想用数据库中的内容替换一些变量。你可以这样做:
$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”中。
希望有帮助!
【讨论】: