This is a guide for installing the library PHPWord manually or without having to use Composer on your website.
Requirements:
To manually install PHPWord you will need to download 2 packages of files: the PHPWord package and the Common package, that contains files needed by PHPWord and other PHPOffice projects.
You can download both packages from the links in the library's Github page. Links to both packages are also copied below:
Once you have downloaded the packages, unzip them each to its own separate folder. You should end up with 2 folders called PHPWord and Common.
(Optional) Create a folder "PhpOffice" and put both the "PHPWord" and "Common" folders inside.
The downloaded packages (PHPWord and Common) cannot yet be uploaded to your website and used. They first need to be unpacked by using Composer. And Composer requires PHP to be installed.
To install PHP locally in Windows, follow this excellent guide from geeksforgeeks.
Again, there is an excellent guide from geeksforgeeks for installing Composer locally in Windows.
PHPWord requires two extensions of PHP: Zip and GD. This may only be required for local use and not necessary to enable if only planning on using PHPWord on your website. However, if these extensions are not enabled Composer will give out warning messages when trying to unpack PHPWord.
Enabling these extensions is simple:
Next you will need to separately unpack (or "install", in Composer language) each of the two packages that were downloaded earlier (the PHPWord and Common packages).
Steps:
In your website, create a folder called "PhpOffice" with two folders inside: "PHPWord" and "Common".
You only need to upload the "vendor" and "src" folders of each package in order to be able to use the library.
The structure of the folder PhpOffice in your website should look like this:
๐ PhpOffice
โคท ๐ Common
โคท ๐ src
โคท ๐ vendor
โคท ๐ PHPWord
โคท ๐ src
โคท ๐ vendor
In order to properly call the required files in your PHP script, use the following PHP code:
// Require PHPWord files
require_once '/PhpOffice/PHPWord/vendor/autoload.php'; // make sure this path is correct
// Require Common files
require_once '/PhpOffice/Common/vendor/autoload.php'; // make sure this path is correct
Make sure that the path to the "PhpOffice" folder in your website is correct. The sample code assumes it is in the same folder as the script.
In order to create a PHPWord object, use the following PHP code:
// Create phpWord object
$phpWord = new PhpOffice\PhpWord\PhpWord(); // do not alter this path