我在一个项目中使用PHPWord。
我试图找出一些与$objWriter相关的属性的信息。
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');具体来说,“Word2007”在结尾是用来做什么的?我试过搜索$objWriter,但找不到任何信息。我试过用“Word2013”或“Word2016”替换它,但我得到了:
"Word2016“不是一个有效的作者。在第29行的wamp...\vendor\phpoffice\phpword\src\PhpWord\IOFactory.php中
发布于 2016-02-01 17:17:50
第二个参数是您要为之创建作者的文档类型。有5种允许的类型:
您可以在IOFactory类的代码中看到这一点:
public static function createWriter(PhpWord $phpWord, $name = 'Word2007')
{
/**
* Notice the allowed names in the array here.
*/
if ($name !== 'WriterInterface' && !in_array($name, array('ODText', 'RTF', 'Word2007', 'HTML', 'PDF'), true)) {
throw new Exception("\"{$name}\" is not a valid writer.");
}
$fqName = "PhpOffice\\PhpWord\\Writer\\{$name}";
return new $fqName($phpWord);
}https://github.com/PHPOffice/PHPWord/blob/develop/src/PhpWord/IOFactory.php
如果您想支持稍后的MS文档格式,则需要实现您自己的编写器extends AbstractWriter implements WriterInterface。然而,此时,没有以后的格式尚未创建。(请注意,Word 2007的格式与应用程序版本不同。)
https://stackoverflow.com/questions/35136400
复制相似问题