How to use PhpSpreadsheet without installation (like PHPExcel)
If you are transitioning from PHPExcel to PhpSpreadsheet, the immediate friction point is often the dependency management model. The official documentation explicitly requires Composer for installation, which presents a blocker for environments lacking terminal access, such as shared web hosting with only Plesk or FTP capabilities. This environment was standard for PHPExcel, where you simply dropped the Classes folder into your project root and included files manually. Replicating this behavior with PhpSpreadsheet is possible, but it requires navigating the library's strict autoloading requirements without relying on the Composer binary.
The fundamental difference lies in how the codebase is organized. PHPExcel was a monolithic class structure where you could grab specific classes or include the entire Classes/PHPExcel.php file. PhpSpreadsheet, conversely, relies heavily on namespaces and PSR-4 autoloading standards introduced to maintain compatibility with modern PHP frameworks. You cannot simply drop the root folder of a Composer-based package into your project and expect it to work without configuring the namespace mapping.
To achieve a "drop-in" experience similar to PHPExcel using only FTP, you must manually configure the autoloader. This involves locating the vendor/autoload.php file within the extracted PhpSpreadsheet archive. If you extract the package directly from GitHub or a zip file intended for Composer, that file might not exist in the expected location relative to your project root. The most reliable method without terminal access is to download the specific version of PhpSpreadsheet as a ZIP file from the official source, extract it into a folder named PhpSpreadsheet, and then manually include the necessary files in your script.
You cannot use the standard require 'vendor/autoload.php' line unless you have run Composer to install dependencies or created a custom vendor directory. Instead, you must identify the specific entry point for the library. In PhpSpreadsheet, this is typically the PhpSpreadsheet/PhpSpreadsheet.php file or the main Bootstrap.php if you are using the newer versioning schemes that bundle the engine.
Here is the practical implementation strategy:
- Download the latest stable release of PhpSpreadsheet as a ZIP file from the official repository.
- Extract the contents directly into your project directory, preserving the folder structure.
- Create a single include statement at the top of your script that maps the library's root namespace to a known path.
<?php
// Define the path relative to where you extracted the files
require_once 'vendor/PhpSpreadsheet/PhpSpreadsheet.php';
// Or if using the bootstrap approach common in recent versions
// require_once 'vendor/autoload.php';
?>
However, there is a critical pitfall here. PhpSpreadsheet expects certain dependencies to be available via Composer, specifically psr/simple-cache and potentially others depending on the version. If you simply drop the files without resolving these sub-dependencies, your script will fail at runtime with "Class not found" errors regarding internal classes like \PhpOffice\PhpSpreadsheet\Calculation\Calculation.
To bypass this entirely without Composer, you must manually download every dependency listed in composer.json and their respective composer.lock files. This is a tedious process involving multiple FTP sessions to fetch JSON data and resolve transitive dependencies. Alternatively, you can look for pre-built "standalone" distributions or use the legacy approach of copying specific classes you need if the library allows it (which it generally does not anymore due to strict PSR-4 enforcement).
The most pragmatic solution for a Plesk-only environment is to utilize a local Composer installation. While you lack access to the server's terminal, you can download your composer.json file via FTP, run the install command locally on your machine or a shared Linux instance with SSH access, and then upload the resulting vendor directory along with the PhpSpreadsheet source code. This hybrid approach respects the library's architecture while adhering to your hosting limitations.
If you strictly require no terminal access and refuse to download dependencies, you are limited to reading-only documentation or attempting to find a legacy fork that mimics PHPExcel's structure, though these often lack security updates and support. The official stance remains that Composer is the supported method; deviating from it introduces significant maintenance overhead regarding class loading and dependency resolution.
