What are the main differences between PHPExcel and PhpSpreadsheet?

There are two projects in the PHPOffice project related to spreadsheet file formats:

PHPExcel

PHPExcel is a library written in pure PHP that provides a set of classes that allow you to write and read from various spreadsheet file formats such as Excel (BIFF) .xls, Excel 2007 (OfficeOpenXML) .xlsx, CSV, Libre / OpenOffice Calc. ods, Gnumeric, PDF, HTML, ... This project is based on the Microsoft OpenXML and PHP standard.

and

PhpSpreadsheets

PhpSpreadsheet is a pure PHP library that provides a set of classes that let you read and write files in various spreadsheet formats such as Excel and LibreOffice Calc.

What are the main differences between the two?

+11
php phpexcel phpoffice phpspreadsheet
source share
2 answers

For many years, PHPExcel was maintained as a library for working with spreadsheet files and was shackled because it supported older versions of PHP (> = 5.2), which made it very difficult to promote and improve. This is a stable library, but will not develop further.

PHPSpreadsheet is the latest version of PHPExcel, most of which has been rewritten to take advantage of new PHP features. Retaining all the functionality of PHPExcel, it requires a minimum version of PHP 5.5 (and will be removed soon to require a minimum of 5.6).

The change in library name should reflect the fact that it is not limited to Excel spreadsheets; but supports a wider range of spreadsheet file formats.

+18
source share

In addition to Mark Baker's answer above, numerous architectural and syntactic changes have been made to the PhpSpreadsheet architecture.

First, note that there is an included migration tool that performs many syntax changes to PhpExcel-to-PhpSpreadsheet for you.

Non-exhaustive summary of changes:

(1) Most important change: PhpSpreadsheet depends on the installed Composer .

Inspired by the npm and ruby ​​bundler nodes, Composer is not a package manager in the same sense as Yum or Apt. Although it works with “packages” and / or libraries, it is a cleaner dependency manager, as it manages the dependencies for each project by installing them in a directory (usually called “vendor”) inside your project. By default, it does not install anything globally. (However, for convenience, it supports a “global” project with a global team.)

You can use PhpSpreadsheet without Composer, and here are a few thoughts on how to do this . Here are some thoughts from the Mavenas on the same topic.

FWIW, I opened a ticket with my web host and after 10 minutes I received a response that Composer was installed on our shared hosting (Green plan, for those who are interested). Not to mention that you will have the same luck, but perhaps the information from the joke will help you. Worth a try with your web hosting.

(2) Namespaces have been introduced

The code side of PhpSpreadsheet has evolved with PhpExcel. Whereas the PhpExcel entry point class - Classes / PHPExcel.php - reflects its namesake, PhpSpreadsheet includes the autoload.php file in the root of the vendor directory. It also uses some namespaces to simplify coding:

<?php use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Spreadsheet; require_once 'vendor/autoload.php'; 

(3) Readers and writers have been renamed

(4) The short names of readers / writers have changed significantly. For example:

 'Excel2003XML' ==> 'Xml' *the leading capital letter is mandatory !* 'Excel2007' ==> 'Xlsx' 'Excel5' ==> 'Xls' 'HTML' ==> 'Html' 'CSV' ==> 'Csv' etc. 

Did you notice that the first letter is uppercase? Necessary.

(5) IOFactory methods have been simplified:

 PHPExcel_IOFactory::getSearchLocations() ==> replaced by ==> IOFactory::registerReader() PHPExcel_IOFactory::setSearchLocations() ==> replaced by ==> IOFactory::registerWriter() PHPExcel_IOFactory::addSearchLocation() 

For example,

 \PHPExcel_IOFactory::addSearchLocation($type, $location, $classname); <=== PhpExcel \PhpOffice\PhpSpreadsheet\IOFactory::registerReader($type, $classname); <=== PhpSpreadsheet 

(6) Other Changes / Deprecated:

 Worksheet::duplicateStyleArray() DataType::dataTypeForValue() Conditional::get/setCondition() Worksheet::get/setDefaultStyle() Worksheet::get/setSelectedCell() Writer\Xls::setTempDir() <==== functionality dropped 

(7) The PHPExcel_Autoloader class has been completely removed and replaced by the composer autoload mechanism.

(8) PDF libraries must be installed through the composer. PHPExcel_Settings::get/setPdfRenderer() been removed and replaced with IOFactory :: registerWriter ().

(9) When rendering diagrams for output in HTML or PDF format, this process was also simplified. Although JpGraph support is still available, unfortunately it has not been updated to the latest versions of PHP and will give various warnings.

(10) PclZip support was discontinued in favor of a more complete and modern extension of PHP ZipArchive. So many changes in these classes.

(11) Cell caching has undergone strong refactoring for the use of PSR-16. This means that most of the classes associated with this function have been removed.

(12) The array keys used for styling have been standardized for a more consistent perception. Now it uses the same wording and case as the getter and setter

(13) Methods for managing coordinates in PHPExcel_Cell were extracted to a new allocated class \PhpOffice\PhpSpreadsheet\Cell\Coordinate . Methods include:

 absoluteCoordinate() absoluteReference() columnIndexFromString() coordinateFromString() buildRange() ... and half-a-dozen more ... 

(14) The column indices are now based on 1. Thus, column A is index 1. This is consistent with rows starting with 1 and Excel COLUMN (), which returns 1 for column A.

(15) The default values ​​for many methods were deleted when this did not make sense. As a rule, installation methods should not have default values.

(16) Discarded conditionally returned cell ... It is no longer possible to change the type of the returned value. It always returns a worksheet, not a cell or rule, in methods such as: Worksheet::setCellValue() , Worksheet::setCellValueExplicit() , etc. For example, for:

 $cell = $worksheet->setCellValue('A1', 'value', true); <==== PhpExcel $cell = $worksheet->getCell('A1')->setValue('value'); <==== PhpSpreadsheet 

See the source document below for more information about these changes.

Recommendations:

PhpSpreadsheet docs - migrating from PhpExcel - readthedocs.io

Migrating from PhpExcel to PhpSpreadsheet by Rob Gravell from Ottawa

+1
source share

All Articles