https://github.com/PHPOffice/PHPWord
require_once ‘src/PhpWord/Autoloader.php’;
\PhpOffice\PhpWord\Autoloader::register();
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Every element you want to append to the word document is placed in a section.
// To create a basic section:
$section = $phpWord->addSection();
// After creating a section, you can append elements:
$section->addText(“hello&word”);
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, ‘Word2007’);
$objWriter->save(‘helloworld.doc’);
以上是生成文档的代码,因为是技术的文档所以必须要 “&” 这个符号。不知道什么原因加了这个字符就无法打开文件了。