PhpSpreadsheet/docs/topics/migration-from-PHPExcel.md
Adrien Crivelli fd9c925a7b
Refactor CachedObjectStorage to PSR-16
This drop a lot of non-core features code and delegate their maintainance
to third parties. Also it open the door to any missing implementation
out of the box, such as Redis for the moment.

Finally this consistently enforce a constraint where there can be one and
only one active cell at any point in time in code. This used to be true for
non-default implementation of cache, but it was not true for default
implementation where all cells were kept in-memory and thus were never
detached from their worksheet and thus were all kept functionnal at any
point in time.

This inconsistency of behavior between in-memory and off-memory could
lead to bugs when changing cache system if the end-user code was badly
written. Now end-user will never be able to write buggy code in the first
place, avoiding future headache when introducing caching.

Closes #3
2017-04-14 16:56:27 +09:00

4.1 KiB

Migration from PHPExcel

PhpSpreadsheet introduced many breaking changes by introducing namespaces and renaming some classes. To help you migrate existing project, a tool was written to replace all references to PHPExcel classes to their new names.

The tool is included in PhpSpreadsheet. It scans recursively all files and directories, starting from the current directory. Assuming it was installed with composer, it can be run like so:

cd /project/to/migrate/src
/project/to/migrate/vendor/phpoffice/phpspreadsheet/bin/migrate-from-phpexcel

Important The tool will irreversibly modify your sources, be sure to backup everything, and double check the result before committing.

Removed deprecated things

In addition to automated changes, usage of deprecated methods must be migrated manually.

Worksheet::duplicateStyleArray()

// Before
$worksheet->duplicateStyleArray($styles, $range, $advanced);

// After
$worksheet->getStyle($range)->applyFromArray($styles, $advanced);

DataType::dataTypeForValue()

// Before
DataType::dataTypeForValue($value);

// After
DefaultValueBinder::dataTypeForValue($value);

Conditional::getCondition()

// Before
$conditional->getCondition();

// After
$conditional->getConditions()[0];

Conditional::setCondition()

// Before
$conditional->setCondition($value);

// After
$conditional->setConditions($value);

Worksheet::getDefaultStyle()

// Before
$worksheet->getDefaultStyle();

// After
$worksheet->getParent()->getDefaultStyle();

Worksheet::setDefaultStyle()

// Before
$worksheet->setDefaultStyle($value);

// After
$worksheet->getParent()->getDefaultStyle()->applyFromArray([
    'font' => [
        'name' => $pValue->getFont()->getName(),
        'size' => $pValue->getFont()->getSize(),
    ],
]);

Worksheet::setSharedStyle()

// Before
$worksheet->setSharedStyle($sharedStyle, $range);

// After
$worksheet->duplicateStyle($sharedStyle, $range);

Worksheet::getSelectedCell()

// Before
$worksheet->getSelectedCell();

// After
$worksheet->getSelectedCells();

Writer\Xls::setTempDir()

// Before
$writer->setTempDir();

// After, there is no way to set temporary storage directory anymore

Autoloader

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

Writing PDF

PHPExcel_Settings::setPdfRenderer() and PHPExcel_Settings::setPdfRenderer() were removed and PDF libraries must be installed via composer. So the only thing to do is to specify a renderer like so:

$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_MPDF;
\PhpOffice\PhpSpreadsheet\Settings::setPdfRendererName($rendererName);

PclZip and ZipArchive

Support for PclZip were dropped in favor of the more complete and modern PHP extension ZipArchive. So the following were removed:

  • PclZip
  • PHPExcel_Settings::setZipClass()
  • PHPExcel_Settings::getZipClass()
  • PHPExcel_Shared_ZipArchive
  • PHPExcel_Shared_ZipStreamWrapper

Cell caching

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

  • PHPExcel_CachedObjectStorage_APC
  • PHPExcel_CachedObjectStorage_DiscISAM
  • PHPExcel_CachedObjectStorage_ICache
  • PHPExcel_CachedObjectStorage_Igbinary
  • PHPExcel_CachedObjectStorage_Memcache
  • PHPExcel_CachedObjectStorage_Memory
  • PHPExcel_CachedObjectStorage_MemoryGZip
  • PHPExcel_CachedObjectStorage_MemorySerialized
  • PHPExcel_CachedObjectStorage_PHPTemp
  • PHPExcel_CachedObjectStorage_SQLite
  • PHPExcel_CachedObjectStorage_SQLite3
  • PHPExcel_CachedObjectStorage_Wincache

In addition to that, \PhpOffice\PhpSpreadsheet::getCellCollection() was renamed to \PhpOffice\PhpSpreadsheet::getCoordinates() and \PhpOffice\PhpSpreadsheet::getCellCacheController() to \PhpOffice\PhpSpreadsheet::getCellCollection() for clarity.

Refer to the new documentation to see how to migrate.