【发布时间】:2017-05-26 00:23:35
【问题描述】:
我可以从此代码生成 Word 文档
<?php
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment; Filename=SaveAsWordDoc.docx");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\">
<title>Saves as a Word Doc</title>
</head>
<body>
<h1>Header</h1>
This text can be seen in word
<ul>
<li>List 1</li>
<li>List 2</li>
</ul>
</body>
</html>
我想在 word 文档的每一页中添加页眉和页脚。我该怎么做?
【问题讨论】:
-
我们在学校项目中尝试了很长时间没有成功,直到找到github.com/PHPOffice/PHPWord。对我们的项目来说太过分了,但从长远来看,节省了很多时间。另见phpword.readthedocs.io/en/latest
-
附注:您的 HTML 包含虚假的 `\` 字符。