Enh: Migrate phpspreadsheet 2.0 (#6976)

* Enh: Migrate phpspreadsheet 2.0

* Enh: migrate 2.0

* Update composer.lock

* Update MIGRATE-DEV.md
This commit is contained in:
ArchBlood 2024-05-02 04:26:26 -04:00 committed by GitHub
parent 735718aded
commit af3971a0c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 638 additions and 298 deletions

View File

@ -17,6 +17,8 @@ At least PHP 8.0 is required with this version.
- Controller route change: `/search/mentioning` -> `/user/mentioning`
- `Yii::$app->search()` component is not longer available.
- Use `(new ContentSearchService($exampleContent->content))->update();` instead of `Yii::$app->search->update($exampleContent);`
- The method `setCellValueByColumnAndRow()` has been replaced with `setCellValue()` and `setValueExplicit()`.
- When rendering xlsx generated data cells, use the `setCellValue()` method with the appropriate coordinate obtained using `getColumnLetter()`.
### Deprecations
- `\humhub\components\Module::getIsActivated()` use `getIsEnabled()` instead
@ -39,6 +41,7 @@ At least PHP 8.0 is required with this version.
- `humhub\modules\stream\actions\GlobalContentStream`
- `humhub\modules\stream\models\GlobalContentStreamQuery`
- `humhub\modules\stream\models\filters\GlobalContentStreamFilter`
- A new protected function `SpreadsheetExport::getColumnLetter()` has been introduced to get the column letter based on the column index.
### Type restrictions
- `\humhub\commands\MigrateController` enforces types on fields, method parameters, & return types

View File

@ -56,7 +56,7 @@
"npm-asset/socket.io-client": "^2.0",
"npm-asset/swiped-events": "^1.0.9",
"npm-asset/timeago": "^1.6.3",
"phpoffice/phpspreadsheet": "^1.0",
"phpoffice/phpspreadsheet": "^2.0",
"raoul2000/yii2-jcrop-widget": "^1.0",
"symfony/amazon-mailer": "^5.4",
"symfony/google-mailer": "^5.4",

890
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -276,24 +276,41 @@ class SpreadsheetExport extends Component
}
/**
* Composes header row contents.
* @param Spreadsheet $spreadsheet
* @throws \PhpOffice\PhpSpreadsheet\Exception
*/
* Composes header row contents.
* @param Spreadsheet $spreadsheet
* @throws \PhpOffice\PhpSpreadsheet\Exception
*/
protected function composeHeaderRow($spreadsheet)
{
$worksheet = $spreadsheet->getActiveSheet();
$row = $this->nextRow();
foreach ($this->columns as $columnIndex => $column) {
$worksheet->setCellValueByColumnAndRow(
$columnIndex + 1,
$row,
$column->renderHeaderCellContent(),
$coordinate = $this->getColumnLetter($columnIndex + 1) . $row;
$worksheet->setCellValue(
$coordinate,
$column->renderHeaderCellContent()
);
}
}
/**
* Get the column letter based on column index.
* @param int $columnIndex
* @return string
*/
protected function getColumnLetter($columnIndex)
{
$letters = range('A', 'Z');
$letter = '';
while ($columnIndex > 0) {
$remainder = ($columnIndex - 1) % 26;
$letter = $letters[$remainder] . $letter;
$columnIndex = floor(($columnIndex - $remainder) / 26);
}
return $letter;
}
/**
* Composes header row contents.
* @param Spreadsheet $spreadsheet
@ -327,17 +344,17 @@ class SpreadsheetExport extends Component
$row = $this->nextRow();
foreach ($this->columns as $columnIndex => $column) {
$cell = $worksheet->getCellByColumnAndRow($columnIndex + 1, $row);
$coordinate = $this->getColumnLetter($columnIndex + 1) . $row;
$value = $column->renderDataCellContent($model, $key, $index);
if ($column->dataType !== null) {
$cell->setValueExplicit($value, $column->dataType);
$worksheet->getCell($coordinate)->setValueExplicit($value, $column->dataType);
} else {
$cell->setValue($value);
$worksheet->setCellValue($coordinate, $value);
}
if ($column->styles !== []) {
$cell->getStyle()->applyFromArray($column->styles);
$worksheet->getStyle($coordinate)->applyFromArray($column->styles);
}
}
}