0

我有一个word文档模板文件和变量来填充它(使用mysql),但我不知道如何一遍又一遍地重复这个过程,直到mysql同时进程停止,这是它保存文件并允许用户下载它。例如:
WORD DOCUMENT GENERATED:
Filled Template
Filled Template
Filled Template
Filled Template
END DOCUMENT
允许用户下载文件。

4

2 回答 2

0

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

于 2013-03-21T12:53:02.947 回答
0

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

$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”中。

希望有帮助!

于 2012-08-01T12:42:05.830 回答