I am using PHPWord in a project.
I am trying to find out some information about the attributes that go with the $objWriter
:
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
Specifically, what is the 'Word2007' used for at the end? I have tried searching $objWriter
but can't locate any info. I have tried replacing it with 'Word2013' or 'Word2016' but I get:
"Word2016" is not a valid writer. in wamp...\vendor\phpoffice\phpword\src\PhpWord\IOFactory.php on line 29
The 2nd parameter is for the type of document you're creating a writer for. There are 5 allowed types:
You can see this in the code for the IOFactory class:
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
If you want to support a later MS Word document format, you will need to implement your own writer that extends AbstractWriter implements WriterInterface
. However, at this time, there are no later formats yet created. (Note that Word 2007 the format is different from the application version.)