Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the main differences between PHPExcel and PhpSpreadsheet?

In project of PHPOffice there are two projects associated with spreadsheet file formats:

PHPExcel

PHPExcel is a library written in pure PHP and providing a set of classes that allow you to write to and read from different spreadsheet file formats, like Excel (BIFF) .xls, Excel 2007 (OfficeOpenXML) .xlsx, CSV, Libre/OpenOffice Calc .ods, Gnumeric, PDF, HTML, ... This project is built around Microsoft's OpenXML standard and PHP.

and

PhpSpreadsheets

PhpSpreadsheet is a library written in pure PHP and providing a set of classes that allow you to read from and to write to different spreadsheet file formats, like Excel and LibreOffice Calc.

What are the main differences between them?

like image 202
simhumileco Avatar asked Dec 13 '16 09:12

simhumileco


People also ask

What is PHPExcel?

PHPExcel. PHPExcel is a library written in pure PHP and providing a set of classes that allow you to write to and read from different spreadsheet file formats, like Excel (BIFF) . xls, Excel 2007 (OfficeOpenXML) . xlsx, CSV, Libre/OpenOffice Calc .

What is PhpSpreadsheet?

PhpSpreadsheet is a library written in pure PHP and offers a set of classes that allow you to read and write various spreadsheet file formats such as Excel and LibreOffice Calc.

How can I create multiple sheets in Excel using PHPExcel?

When you first instantiate the $objPHPExcel, it already has a single sheet (sheet 0); you're then adding a new sheet (which will become sheet 1), but setting active sheet to sheet $i (when $i is 0)... so you're renaming and populating the original worksheet created when you instantiated $objPHPExcel rather than the one ...


2 Answers

PHPExcel has been maintained as a library for working with spreadsheet files for many years now, and has been shackled by retaining support for older versions of PHP (>= 5.2) making it very difficult to move forward and improve it. It is a stable library, but will not be developed any further.

PHPSpreadsheet is the newest version of PHPExcel, and large parts of it have been rewritten to take advantage of the newer features of PHP. While retaining all the functionality of PHPExcel, it requires a minimum PHP version of 5.5 (and soon that will be dropped to require a minimum of 5.6).

The change in library name was to reflect the fact that it isn't limited to Excel spreadsheets; but supports a wider range of spreadsheet file formats.

EDIT 2020:

PHP Excel was officially deprecated in 2017 and permanently archived in 2019.

PHP Excel has not be maintained for years and must not be used anymore. All users must migrate to its direct successor PhpSpreadsheet, or another alternative.

like image 180
Mark Baker Avatar answered Oct 13 '22 21:10

Mark Baker


Further to Mark Baker's answer above, there are numerous architectural and syntactical changes to how the new PhpSpreadsheet library is used.

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

 

Non-Exhaustive Summary Of Changes:

(1) Most Important Change: PhpSpreadsheet relies upon Composer being installed.

Strongly inspired by node's npm and ruby's bundler, Composer is not a package manager in the same sense as Yum or Apt. Although it does deal with "packages" and/or libraries, it is a more pure dependency manager, as it manages dependencies on a per-project basis, installing them in a directory (usually named "vendor") inside your project. By default, it does not install anything globally. (It does however support a "global" project for convenience via the global command.)

It is possible to use PhpSpreadsheet without Composer, and here are some thoughts on how to do that. Here are more thoughts direct from the mavens on this same topic.

FWIW, I opened a ticket with my webhost and in 10 minutes received a reply that Composer had been installed on our shared hosting (Green plan, for those wondering). Not saying you will have the same good luck, but perhaps the anecdotal info will be helpful. Worth giving a try with your webhost.

(2) Namespaces were introduced

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

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

(3) Readers and writers were renamed

(4) Reader/Writer short names were changed, significantly. For example:

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

Did you make note that the first letter is capitalized? Required.

(5) IOFactory methods were 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/Deprecations:

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

(7) The class PHPExcel_Autoloader was removed entirely and is replaced by composer autoloading mechanism.

(8) PDF libraries must be installed via composer. The PHPExcel_Settings::get/setPdfRenderer() methods were removed and are replaced by IOFactory::registerWriter() instead.

(9) When rendering charts for HTML or PDF outputs, the process was also simplified. And while JpGraph support is still available, it is unfortunately not up to date for latest PHP versions and it will generate various warnings.

(10) Support for PclZip were dropped in favor of the more complete and modern PHP extension ZipArchive. So many changes to those classes.

(11) Cell caching was heavily refactored to leverage PSR-16. That means most classes related to that feature were removed.

(12) Array keys used for styling have been standardized for a more coherent experience. It now uses the same wording and casing as the getter and setter

(13) Methods to manipulate coordinates in PHPExcel_Cell were extracted to a dedicated new class \PhpOffice\PhpSpreadsheet\Cell\Coordinate. The methods include:

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

(14) Column indexes are now based on 1. So column A is the index 1. This is consistent with rows starting at 1 and Excel function COLUMN() that returns 1 for column A.

(15) Default values for many methods were removed when it did not make sense. Typically, setter methods should not have default values.

(16) Dropped conditionally returned cell... It is no longer possible to change the type of returned value. It always returns the Worksheet and never the Cell or Rule, in methods such as: Worksheet::setCellValue(), Worksheet::setCellValueExplicit(), etc. For e.g.:

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

For additional details on these changes, refer to the source document, below.

References:

PhpSpreadsheet Docs - Migration From PhpExcel - readthedocs.io

Making the switch from PhpExcel to PhpSpreadsheet by Rob Gravelle of Ottawa

like image 26
cssyphus Avatar answered Oct 13 '22 23:10

cssyphus