PhpPowerpoint class XMLwriter not found

2.4k Views Asked by At

I'm trying to use PHPPowerpoint and his examples

But I get the following error :

*Sample 01 Complex
14:56:03 Create new PHPPresentation object
14:56:03 Set properties
14:56:03 Remove first slide
14:56:03 Create templated slide
14:56:03 Create a shape (rich text)
14:56:03 Create templated slide
14:56:03 Create a shape (rich text)
14:56:03 Create a shape (rich text)
14:56:03 Create templated slide
14:56:03 Create a shape (rich text)
14:56:03 Create a shape (rich text)
14:56:03 Create templated slide
14:56:03 Create a shape (rich text)
14:56:03 Create a shape (rich text)

**Fatal error: Class 'Common\XMLWriter' not found in .....\test phppowerpoint\PHPPowerPoint-develop\src\PhpPresentation\Writer\PowerPoint2007\AbstractPart.php on line 76***

Can anyone help me to fix this error ? Thank you

2

There are 2 best solutions below

0
On

As Raj said, you need to download the common PHPOffice classes from the link he specified. You can place them where is more convenient to you. In my case, I placed the Common folder inside the src folder (so in src you'd have PHPPresentation and Common). Afterwards, you need to include them in the source code, as Raj said

require_once 'PHPPresentation/src/Common/Autoloader.php;
\PhpOffice\Common\Autoloader::register();

You'll have to update the path in require_once to your actual path.

P.S.: Don't forget about writing permissions on the destination folder, otherwise the library won't be able to write out the presentation file!

2
On

You are facing this problem because common office php files are missing. Download:

https://github.com/PHPOffice/Common

and include it in your source code (after updating the path):

require_once 'Common-develop/src/Common/Autoloader.php';
\PhpOffice\Common\Autoloader::register();