I am new to the PHPWord library, and have just now installed it using composer. I want to generate a basic word file. This is my code:
<?php
// (A) LOAD PHPWORD
require "vendor/autoload.php";
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$section->addText(
'"Learn from yesterday, live for today, hope for tomorrow. '
. 'The important thing is not to stop questioning." '
. '(Albert Einstein)'
);
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save('helloWorld.docx');
?>
Whenever I execute the code, I get this error:
Fatal error: Uncaught Error: Class "ZipArchive" not found
I have followed every tutorial and have also searched in youtube, but I haven't got anything related to this issue. After digging a bit more, I found this post related to the issue.
I followed the solution according to that post.
\PhpOffice\PhpWord\Settings::setZipClass(Settings::PCLZIP);
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save('helloWorld.docx');
Fingers crossed, I executed the code, only to be greeted by a new error now:
Fatal error: Uncaught Error: Class "Settings" not found
Can anyone please help me? I am completely new to this library and don't know how to fix this.