Skip to content

Conversation

@IonBazan
Copy link

@IonBazan IonBazan commented May 27, 2025

Please take note of our contributing guidelines: https://docs.laravel-excel.com/3.1/getting-started/contributing.html
Filling out the template is required. Any pull request that does not include enough information to be reviewed in a timely manner may be closed at the maintainers' discretion.

1️⃣ Why should it be added? What are the benefits of this change?

Many users raised the need to upgrade to PHPOffice/PHPSpreadsheet v2 or v4 for extended support from upstream library and compatibility with future PHP versions. See #4263

2️⃣ Does it contain multiple, unrelated changes? Please separate the PRs out.

CI changes, adjusted other dependencies and replaced legacy model factories with Laravel 8+ syntax.

3️⃣ Does it include tests, if possible?

Yes

4️⃣ Any drawbacks? Possible breaking changes?

Breaking changes:

  • Drop PHP 7.4, 8.0 support
  • Drop Laravel 5.8, 6 and 7 support
  • Drop support for PHPSpreadsheet v1
  • Add types to classes implementing PHPSpreadsheet interfaces
  • PHPSpreadsheet v2 seem to not support ValueBinder when reading values - only when storing values
  • PHPSpreadsheet v2 changed the logic when reading specific sheets only, breaking WithMultipleSheetsTest error handling. Temporarily removing setLoadSheetsOnly call from the Reader for now. See Option to Create Blank Sheet If LoadSheetsOnly Doesn't Find Any PHPOffice/PhpSpreadsheet#4618

Above broken features' tests were temporarily marked as skipped, hence WIP tag.

5️⃣ Mark the following tasks as done:

  • Checked the codebase to ensure that your feature doesn't already exist.
  • Take note of the contributing guidelines.
  • Checked the pull requests to ensure that another person hasn't already submitted a fix.
  • Added tests to ensure against regression.

6️⃣ Thanks for contributing! 🙌

@IonBazan IonBazan requested a review from stevebauman May 28, 2025 17:57
@patrickbrouwers
Copy link
Member

Thanks for the PR, this seems to be the first actual right attempt of updating phpoffice that actually implemented all the breaking changes.

As this is going to be in the next major release in which I'm planning to drop support for all unsupported PHP and Laravel versions, you can't drop them from the PR as well.

I don't see a need in supporting v2 and v3, we can just bump it straight away to v4

What's the problem with the loadSheetsOnly? Did you find a breaking change note about this?

What things are still WIP?

@IonBazan
Copy link
Author

IonBazan commented Jun 2, 2025

Thanks for the review, @patrickbrouwers. There is nothing else left besides loading the sheet by incorrect name, removing broken test and bumping dependency requirements. I’ll apply your suggestions and target v4 soon.

@IonBazan IonBazan changed the title [WIP] Upgrade PHPOffice to v2/v3/v4 Upgrade PHPOffice to v4 Jun 3, 2025
@IonBazan IonBazan force-pushed the feature/phpoffice-upgrade branch from e153bda to f605839 Compare June 3, 2025 12:01
@IonBazan IonBazan requested a review from patrickbrouwers June 3, 2025 12:02
@IonBazan IonBazan changed the title Upgrade PHPOffice to v4 [4.x] Upgrade PHPOffice to v4 Jun 3, 2025
@IonBazan
Copy link
Author

IonBazan commented Jun 3, 2025

Kindly help to create 4.0 branch and target this PR there 🙏🏻
It's also worth considering to add property types and any missing return types, since we are adding breaking changes and dropping old PHP versions.

@patrickbrouwers
Copy link
Member

I'll look into it after my holiday.
For now let's not add property and return types in this PR. It's okay in a seperate PR so we can see the impact.

@IonBazan
Copy link
Author

IonBazan commented Jul 28, 2025

Hi @patrickbrouwers I hope you had a great holiday and was wondering if you had time to look into this again. Please let me know if you wish to adjust anything with above implementation.

@patrickbrouwers
Copy link
Member

Hey @IonBazan, I currently don't have to time to look into this. As this is a big change that I really want to test carefully before tagging, I need to have the time to spend more on it than the few minutes I have right now :( I can't promise when atm.

@mikebrandl
Copy link

V5 was just released...

@IonBazan IonBazan changed the title [4.x] Upgrade PHPOffice to v4 [4.x] Upgrade PHPOffice to v5 Aug 12, 2025
@oleibman
Copy link

I am a maintainer for PhpSpreadsheet. Please let me know if there is any way I can assist in this effort. In particular, we cannot revert to the old behavior when loadSheetsOnly doesn't match any sheets because that would be a new breaking change, but we can add an option to the reader to create a new sheet if none were read in (this matches the old behavior). Would that be helpful for you?

Mention was made above that valueBinder was not supported for read. Readers and Spreadsheets have supported ValueBinder since PhpSpreadsheet 3.4.

@patrickbrouwers
Copy link
Member

That sounds good, thx!

oleibman added a commit to oleibman/PhpSpreadsheet that referenced this pull request Aug 28, 2025
In PhpSpreadsheet Release 1, if the LoadSheetsOnly option was specified, and no sheets matched, a new blank sheet was created. This behavior changed in PhpSpreadsheet Release 2, so that an exception wound up being thrown instead. Although the Release 2 approach seems more sensible to me, it was actually collateral damage from a different change, and was not an intentional result.

The difference in behavior is causing a problem for Laravel-Excel. In particular, a PR which would move their supported PhpSpreadsheet release from 1 to 5, is delayed because this change in behavior breaks part of their test suite. See SpartnerNL/Laravel-Excel#4302. We would very much like them to get off release 1. I volunteered to add a compatibility option to the Readers which would emulate the release 1 behavior. The result is this PR.

Usage:
```php
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
$reader->setLoadSheetsOnly([list of sheet names]);
if (method_exists($reader, 'setCreateBlankSheetIfNoneRead')) {
    $reader->setCreateBlankSheetIfNoneRead(true);
}
```
In addition to Xlsx Reader, the method is available for Xls, Ods, Xml, and Gnumeric.
@oleibman
Copy link

I have created PR 4618 for PhpSpreadsheet (there is already a link to it above). Typical usage is documented in the commit message. I plan to merge it to master early next week, which will, I hope, give you a chance to see if it meets your needs before I do that. I am not planning a new release for PhpSpreadsheet until just before or just after Php8.5 is released, but, if you need it sooner, let me know. Also, please let me know if there's anything else you'd like to see which would help move this PR forward.

@patrickbrouwers
Copy link
Member

Thanks @oleibman !

@IonBazan
Copy link
Author

Thank you @oleibman - I have tried to use the branch you provided and restored the changes in Reader but tests are still failing at the same location. Providing incorrect sheet name throws an exception.

@oleibman
Copy link

Thank you @oleibman - I have tried to use the branch you provided and restored the changes in Reader but tests are still failing at the same location. Providing incorrect sheet name throws an exception.

I had to add this as a compatibility option in order to avoid introducing a new breaking change in PhpSpreadsheet. You need to add the following to your test:

if (method_exists($reader, 'setCreateBlankSheetIfNoneRead')) {
    $reader->setCreateBlankSheetIfNoneRead(true);
}

Once you do that, your test should succeed for both PhpSpreadsheet 1 and PhpSpreadsheet 5.

@IonBazan IonBazan force-pushed the feature/phpoffice-upgrade branch from 22849df to 512c375 Compare August 31, 2025 18:15
@IonBazan
Copy link
Author

Thanks, I must have missed that! It seems to be working fine now 👍🏻

@oleibman
Copy link

oleibman commented Sep 1, 2025

@IonBazan Thank you for the confirmation. My PR is now moved to dev-master, and will be part of a formal release some time this week.

@oleibman
Copy link

oleibman commented Sep 4, 2025

PhpSpreadsheet 5.1.0, including the compatibility option described above, is now released. (Also 3.10.1 and 2.4.1 just in case.)

@IonBazan IonBazan force-pushed the feature/phpoffice-upgrade branch from 512c375 to 2257b98 Compare September 4, 2025 16:38
@IonBazan IonBazan force-pushed the feature/phpoffice-upgrade branch from 2257b98 to 310b937 Compare September 4, 2025 16:54
@IonBazan
Copy link
Author

IonBazan commented Sep 5, 2025

@patrickbrouwers I've bumped minimal version requirement to v5.1 and added testing under PHP 8.5.
I saw deprecation warnings when running under 8.5 and upon checking it locally, they seem to be caused by:
https://github.com/orchestral/testbench-core/blob/af8d6de7a747fdeaf600863c9df7eef86898d045/laravel/config/database.php#L63

PDO::MYSQL_ATTR_SSL_CA is deprecated since PHP 8.5 and Pdo\Mysql::ATTR_SSL_CA should be used instead but I don't know if we can do anything about this.

@joostdebruijn
Copy link
Contributor

@IonBazan I'm following just following this conversation, expectantly waiting for a merge. Thanks for your work so far!

I was looking into the constant you mentioned, but it's a difficult one to solve because the new constant Pdo\Mysql::ATTR_SSL_CA has been introduced since PHP 8.4 but Laravel (and thus Testbench) supports down to PHP 8.2. The best solution would be to include the constant in the PHP 8.4 polyfill of Symfony so that it can be used safely, but I'm not sure if the Symfony-maintainers are open for that. I'm willing to prepare a PR for that this weekend.

It's up to @patrickbrouwers if this is a show stopper for this PR. In my opinion it is not as this deprecation is only in the test suite and PHP 8.5 is still some months away.

@patrickbrouwers
Copy link
Member

Don't worry about the deprecation message. This is a message that will only appear the 8.5 testsuite. On future laravel/testbench updates this deprecation will be fixed.

@patrickbrouwers patrickbrouwers changed the base branch from 3.1 to 4.x September 5, 2025 08:59
@patrickbrouwers patrickbrouwers merged commit 1f93306 into SpartnerNL:4.x Sep 5, 2025
12 checks passed
@patrickbrouwers
Copy link
Member

As this looks good now, I've merged it in the 4.x branch. I'll need a bit more time to prepare the actual 4.0 release

@IonBazan IonBazan deleted the feature/phpoffice-upgrade branch September 5, 2025 10:52
@mikebrandl
Copy link

@patrickbrouwers Any news on that 4.X release?

@patrickbrouwers
Copy link
Member

I'm unfortunalty short on time atm, but you can of course always use the 4.x-dev in composer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants