Skip to content

Commit

Permalink
Fix chart data references on sheet title update
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaume-ro-fr committed Feb 22, 2024
1 parent 16b7bff commit 339ddcf
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/PhpSpreadsheet/ReferenceHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use PhpOffice\PhpSpreadsheet\Cell\AddressRange;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\Chart\DataSeries;
use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues;
use PhpOffice\PhpSpreadsheet\Style\Conditional;
use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter;
use PhpOffice\PhpSpreadsheet\Worksheet\Table;
Expand Down Expand Up @@ -891,6 +893,39 @@ public function updateNamedFormulae(Spreadsheet $spreadsheet, string $oldName =
}
}
}

foreach ($sheet->getChartCollection() as $chart) {
/** @var DataSeries $plotGroup */
foreach ($chart->getPlotArea()?->getPlotGroup() as $plotGroup) {

Check failure on line 899 in src/PhpSpreadsheet/ReferenceHelper.php

View workflow job for this annotation

GitHub Actions / phpstan

Argument of an invalid type array<PhpOffice\PhpSpreadsheet\Chart\DataSeries>|null supplied for foreach, only iterables are supported.
/** @var DataSeriesValues $plotCategory */
foreach ($plotGroup->getPlotCategories() as $plotCategory) {
$dataSource = $plotCategory->getDataSource();
if (strpos($dataSource, $oldName) !== false) {

Check failure on line 903 in src/PhpSpreadsheet/ReferenceHelper.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter #1 $haystack of function strpos expects string, string|null given.
$dataSource = str_replace("'" . $oldName . "'!", "'" . $newName . "'!", $dataSource);

Check failure on line 904 in src/PhpSpreadsheet/ReferenceHelper.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter #3 $subject of function str_replace expects array|string, string|null given.
$dataSource = str_replace($oldName . '!', $newName . '!', $dataSource);
$plotCategory->setDataSource($dataSource);
}
}
/** @var DataSeriesValues $plotLabel */
foreach ($plotGroup->getPlotLabels() as $plotLabel) {
$dataSource = $plotLabel->getDataSource();
if (strpos($dataSource, $oldName) !== false) {

Check failure on line 912 in src/PhpSpreadsheet/ReferenceHelper.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter #1 $haystack of function strpos expects string, string|null given.
$dataSource = str_replace("'" . $oldName . "'!", "'" . $newName . "'!", $dataSource);

Check failure on line 913 in src/PhpSpreadsheet/ReferenceHelper.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter #3 $subject of function str_replace expects array|string, string|null given.
$dataSource = str_replace($oldName . '!', $newName . '!', $dataSource);
$plotLabel->setDataSource($dataSource);
}
}
/** @var DataSeriesValues $plotValue */
foreach ($plotGroup->getPlotValues() as $plotValue) {
$dataSource = $plotValue->getDataSource();
if (strpos($dataSource, $oldName) !== false) {

Check failure on line 921 in src/PhpSpreadsheet/ReferenceHelper.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter #1 $haystack of function strpos expects string, string|null given.
$dataSource = str_replace("'" . $oldName . "'!", "'" . $newName . "'!", $dataSource);

Check failure on line 922 in src/PhpSpreadsheet/ReferenceHelper.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter #3 $subject of function str_replace expects array|string, string|null given.
$dataSource = str_replace($oldName . '!', $newName . '!', $dataSource);
$plotValue->setDataSource($dataSource);
}
}
}
}
}
}

Expand Down

0 comments on commit 339ddcf

Please sign in to comment.