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');
以上是生成文档的代码,因为是技术的文档所以必须要 “&” 这个符号。不知道什么原因加了这个字符就无法打开文件了。
ringa_lee2017-04-10 15:40:37
$string = "abc & cde";
if(strpos($string ,"&") !== FALSE ){
$string = str_replace("&", "&", $string);
}
$templateProcessor->setValue($id, $string, ENT_COMPAT, 'UTF-8');
我试了下,这样就ok了