当前位置:Gxlcms > PHP教程 > phpword生成doc文件特殊符号无法打开

phpword生成doc文件特殊符号无法打开

时间:2021-07-01 10:21:17 帮助过:4人阅读

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');

以上是生成文档的代码,因为是技术的文档所以必须要 “&” 这个符号。不知道什么原因加了这个字符就无法打开文件了。

回复内容:

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');

以上是生成文档的代码,因为是技术的文档所以必须要 “&” 这个符号。不知道什么原因加了这个字符就无法打开文件了。

人气教程排行