2016-11-27 15:11:16 +00:00
|
|
|
# Migration from PHPExcel
|
|
|
|
|
2016-12-03 15:00:54 +00:00
|
|
|
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
|
2017-10-17 07:16:54 +00:00
|
|
|
classes to their new names. But they are also manual changes that
|
|
|
|
need to be done.
|
|
|
|
|
|
|
|
## Automated tool
|
2016-11-27 15:11:16 +00:00
|
|
|
|
2016-12-03 15:00:54 +00:00
|
|
|
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:
|
2016-11-27 15:11:16 +00:00
|
|
|
|
2016-12-03 15:00:54 +00:00
|
|
|
``` sh
|
2016-11-27 15:11:16 +00:00
|
|
|
cd /project/to/migrate/src
|
|
|
|
/project/to/migrate/vendor/phpoffice/phpspreadsheet/bin/migrate-from-phpexcel
|
|
|
|
```
|
|
|
|
|
2016-12-03 15:00:54 +00:00
|
|
|
**Important** The tool will irreversibly modify your sources, be sure to
|
|
|
|
backup everything, and double check the result before committing.
|
2016-12-04 06:02:30 +00:00
|
|
|
|
2017-10-17 07:16:54 +00:00
|
|
|
## Manual changes
|
|
|
|
|
|
|
|
In addition to automated changes, a few things need to be migrated manually.
|
|
|
|
|
|
|
|
### Renamed readers and writers
|
|
|
|
|
|
|
|
When using with `IOFactory::createReader()`, `IOFactory::createWriter()`
|
|
|
|
and `IOFactory::identify()`, the reader/writer short names are used.
|
|
|
|
Those were changed, along as their corresponding class, to remove ambiguity:
|
|
|
|
|
|
|
|
Before | After
|
|
|
|
-----------------|---------
|
|
|
|
`'CSV'` | `'Csv'`
|
|
|
|
`'Excel2003XML'` | `'Xml'`
|
|
|
|
`'Excel2007'` | `'Xlsx'`
|
|
|
|
`'Excel5'` | `'Xls'`
|
|
|
|
`'Gnumeric'` | `'Gnumeric'`
|
|
|
|
`'HTML'` | `'Html'`
|
|
|
|
`'OOCalc'` | `'Ods'`
|
|
|
|
`'OpenDocument'` | `'Ods'`
|
|
|
|
`'PDF'` | `'Pdf'`
|
|
|
|
`'SYLK'` | `'Slk'`
|
|
|
|
|
2016-12-04 06:02:30 +00:00
|
|
|
|
2017-10-17 07:16:54 +00:00
|
|
|
### Removed deprecated things
|
2016-12-04 06:02:30 +00:00
|
|
|
|
2017-10-17 07:16:54 +00:00
|
|
|
#### Worksheet::duplicateStyleArray()
|
2016-12-04 06:02:30 +00:00
|
|
|
|
|
|
|
``` php
|
|
|
|
// Before
|
|
|
|
$worksheet->duplicateStyleArray($styles, $range, $advanced);
|
|
|
|
|
|
|
|
// After
|
|
|
|
$worksheet->getStyle($range)->applyFromArray($styles, $advanced);
|
|
|
|
```
|
|
|
|
|
2017-10-17 07:16:54 +00:00
|
|
|
#### DataType::dataTypeForValue()
|
2016-12-04 06:02:30 +00:00
|
|
|
|
|
|
|
``` php
|
|
|
|
// Before
|
|
|
|
DataType::dataTypeForValue($value);
|
|
|
|
|
|
|
|
// After
|
|
|
|
DefaultValueBinder::dataTypeForValue($value);
|
|
|
|
```
|
|
|
|
|
2017-10-17 07:16:54 +00:00
|
|
|
#### Conditional::getCondition()
|
2016-12-04 06:02:30 +00:00
|
|
|
|
|
|
|
``` php
|
|
|
|
// Before
|
|
|
|
$conditional->getCondition();
|
|
|
|
|
|
|
|
// After
|
|
|
|
$conditional->getConditions()[0];
|
|
|
|
```
|
|
|
|
|
2017-10-17 07:16:54 +00:00
|
|
|
#### Conditional::setCondition()
|
2016-12-04 06:02:30 +00:00
|
|
|
|
|
|
|
``` php
|
|
|
|
// Before
|
|
|
|
$conditional->setCondition($value);
|
|
|
|
|
|
|
|
// After
|
|
|
|
$conditional->setConditions($value);
|
|
|
|
```
|
|
|
|
|
2017-10-17 07:16:54 +00:00
|
|
|
#### Worksheet::getDefaultStyle()
|
2016-12-04 06:02:30 +00:00
|
|
|
|
|
|
|
``` php
|
|
|
|
// Before
|
|
|
|
$worksheet->getDefaultStyle();
|
|
|
|
|
|
|
|
// After
|
|
|
|
$worksheet->getParent()->getDefaultStyle();
|
|
|
|
```
|
|
|
|
|
2017-10-17 07:16:54 +00:00
|
|
|
#### Worksheet::setDefaultStyle()
|
2016-12-04 06:02:30 +00:00
|
|
|
|
|
|
|
``` php
|
|
|
|
// Before
|
|
|
|
$worksheet->setDefaultStyle($value);
|
|
|
|
|
|
|
|
// After
|
|
|
|
$worksheet->getParent()->getDefaultStyle()->applyFromArray([
|
|
|
|
'font' => [
|
|
|
|
'name' => $pValue->getFont()->getName(),
|
|
|
|
'size' => $pValue->getFont()->getSize(),
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
```
|
|
|
|
|
2017-10-17 07:16:54 +00:00
|
|
|
#### Worksheet::setSharedStyle()
|
2016-12-04 06:02:30 +00:00
|
|
|
|
|
|
|
``` php
|
|
|
|
// Before
|
|
|
|
$worksheet->setSharedStyle($sharedStyle, $range);
|
|
|
|
|
|
|
|
// After
|
|
|
|
$worksheet->duplicateStyle($sharedStyle, $range);
|
|
|
|
```
|
|
|
|
|
2017-10-17 07:16:54 +00:00
|
|
|
#### Worksheet::getSelectedCell()
|
2016-12-04 06:02:30 +00:00
|
|
|
|
|
|
|
``` php
|
|
|
|
// Before
|
|
|
|
$worksheet->getSelectedCell();
|
|
|
|
|
|
|
|
// After
|
|
|
|
$worksheet->getSelectedCells();
|
|
|
|
```
|
|
|
|
|
2017-10-17 07:16:54 +00:00
|
|
|
#### Writer\Xls::setTempDir()
|
2016-12-04 06:02:30 +00:00
|
|
|
|
|
|
|
``` php
|
|
|
|
// Before
|
|
|
|
$writer->setTempDir();
|
|
|
|
|
|
|
|
// After, there is no way to set temporary storage directory anymore
|
|
|
|
```
|
2017-01-21 15:44:33 +00:00
|
|
|
|
2017-10-17 07:16:54 +00:00
|
|
|
### Autoloader
|
2017-01-21 15:44:33 +00:00
|
|
|
|
|
|
|
The class `PHPExcel_Autoloader` was removed entirely and is replaced by composer
|
|
|
|
autoloading mechanism.
|
|
|
|
|
2017-10-17 07:16:54 +00:00
|
|
|
### Writing PDF
|
2017-01-21 15:44:33 +00:00
|
|
|
|
2017-10-14 05:57:44 +00:00
|
|
|
`PHPExcel_Settings::getPdfRenderer()` and `PHPExcel_Settings::setPdfRenderer()`
|
|
|
|
were removed. `PHPExcel_Settings::getPdfRendererName()` and
|
|
|
|
`PHPExcel_Settings::setPdfRendererName()` were renamed as `setDefaultPdfWriter()`
|
|
|
|
and `setDefaultPdfWriter()` respectively. And PDF libraries must be installed via
|
|
|
|
composer. So the only thing to do is to specify a default writer class like so:
|
2017-01-21 15:44:33 +00:00
|
|
|
|
|
|
|
```php
|
2017-10-14 05:57:44 +00:00
|
|
|
$rendererName = \PhpOffice\PhpSpreadsheet\Writer\Pdf\MPDF::class;
|
|
|
|
\PhpOffice\PhpSpreadsheet\Settings::setDefaultPdfWriter($rendererName);
|
2017-01-21 15:44:33 +00:00
|
|
|
```
|
2017-03-11 02:48:46 +00:00
|
|
|
|
2017-10-17 07:16:54 +00:00
|
|
|
### PclZip and ZipArchive
|
2017-03-11 02:48:46 +00:00
|
|
|
|
|
|
|
Support for PclZip were dropped in favor of the more complete and modern
|
2017-04-14 05:22:33 +00:00
|
|
|
[PHP extension ZipArchive](http://php.net/manual/en/book.zip.php).
|
|
|
|
So the following were removed:
|
2017-03-11 02:48:46 +00:00
|
|
|
|
|
|
|
- `PclZip`
|
|
|
|
- `PHPExcel_Settings::setZipClass()`
|
|
|
|
- `PHPExcel_Settings::getZipClass()`
|
|
|
|
- `PHPExcel_Shared_ZipArchive`
|
|
|
|
- `PHPExcel_Shared_ZipStreamWrapper`
|
|
|
|
|
2017-04-14 05:22:33 +00:00
|
|
|
|
2017-10-17 07:16:54 +00:00
|
|
|
### Cell caching
|
2017-04-14 05:22:33 +00:00
|
|
|
|
|
|
|
Cell caching was heavily refactored to leverage
|
|
|
|
[PSR-16](http://www.php-fig.org/psr/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](./memory_saving.md) to see how to migrate.
|
2017-04-16 03:46:18 +00:00
|
|
|
|
2017-10-17 07:16:54 +00:00
|
|
|
### Dropped conditionally returned cell
|
2017-04-16 03:46:18 +00:00
|
|
|
|
|
|
|
For all the following methods, it is no more possible to change the type of
|
|
|
|
returned value. It always return the Worksheet and never the Cell or Rule:
|
|
|
|
|
|
|
|
- Worksheet::setCellValue()
|
|
|
|
- Worksheet::setCellValueByColumnAndRow()
|
|
|
|
- Worksheet::setCellValueExplicit()
|
|
|
|
- Worksheet::setCellValueExplicitByColumnAndRow()
|
|
|
|
- Worksheet::addRule()
|
|
|
|
|
|
|
|
Migration would be similar to:
|
|
|
|
|
|
|
|
``` php
|
|
|
|
// Before
|
|
|
|
$cell = $worksheet->setCellValue('A1', 'value', true);
|
|
|
|
|
|
|
|
// After
|
|
|
|
$cell = $worksheet->getCell('A1')->setValue('value');
|
|
|
|
```
|
2017-09-08 17:56:23 +00:00
|
|
|
|
2017-10-17 07:16:54 +00:00
|
|
|
### Standardized keys for styling
|
2017-09-08 17:56:23 +00:00
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
```php
|
|
|
|
// Before
|
|
|
|
$style = [
|
|
|
|
'numberformat' => [
|
|
|
|
'code' => NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE,
|
|
|
|
],
|
|
|
|
'font' => [
|
|
|
|
'strike' => true,
|
|
|
|
'superScript' => true,
|
|
|
|
'subScript' => true,
|
|
|
|
],
|
|
|
|
'alignment' => [
|
|
|
|
'rotation' => 90,
|
|
|
|
'readorder' => Alignment::READORDER_RTL,
|
|
|
|
'wrap' => true,
|
|
|
|
],
|
|
|
|
'borders' => [
|
|
|
|
'diagonaldirection' => Borders::DIAGONAL_BOTH,
|
|
|
|
'allborders' => [
|
|
|
|
'style' => Border::BORDER_THIN,
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'fill' => [
|
|
|
|
'type' => Fill::FILL_GRADIENT_LINEAR,
|
|
|
|
'startcolor' => [
|
|
|
|
'argb' => 'FFA0A0A0',
|
|
|
|
],
|
|
|
|
'endcolor' => [
|
|
|
|
'argb' => 'FFFFFFFF',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
// After
|
|
|
|
$style = [
|
|
|
|
'numberFormat' => [
|
|
|
|
'formatCode' => NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE,
|
|
|
|
],
|
|
|
|
'font' => [
|
|
|
|
'strikethrough' => true,
|
|
|
|
'superscript' => true,
|
|
|
|
'subscript' => true,
|
|
|
|
],
|
|
|
|
'alignment' => [
|
|
|
|
'textRotation' => 90,
|
|
|
|
'readOrder' => Alignment::READORDER_RTL,
|
|
|
|
'wrapText' => true,
|
|
|
|
],
|
|
|
|
'borders' => [
|
|
|
|
'diagonalDirection' => Borders::DIAGONAL_BOTH,
|
|
|
|
'allBorders' => [
|
|
|
|
'borderStyle' => Border::BORDER_THIN,
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'fill' => [
|
|
|
|
'fillType' => Fill::FILL_GRADIENT_LINEAR,
|
|
|
|
'startColor' => [
|
|
|
|
'argb' => 'FFA0A0A0',
|
|
|
|
],
|
|
|
|
'endColor' => [
|
|
|
|
'argb' => 'FFFFFFFF',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
```
|