Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when cloning sheet inside XLSX with a table #3820

Closed
8 tasks
AnzeBlaBla opened this issue Dec 11, 2023 · 0 comments · Fixed by #3821
Closed
8 tasks

Error when cloning sheet inside XLSX with a table #3820

AnzeBlaBla opened this issue Dec 11, 2023 · 0 comments · Fixed by #3821

Comments

@AnzeBlaBla
Copy link

This is:

- [x] a bug report
- [ ] a feature request
- [x] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

When using clone on a sheet, it should clone it successfully.

What is the current behavior?

When cloning a sheet that contains a table, it throws the error: Error: Spreadsheet objects cannot be serialized

What are the steps to reproduce?

An XLSX file with a table (example attached), load it into PhpSpreadsheet and use clone on the sheet that contains the table.

Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:

<?php

require __DIR__ . '/vendor/autoload.php';

// Create new Spreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();

$sheet = clone $spreadsheet->getSheetByName('Test'); // Errors here
$sheet->setTitle('test2');
$spreadsheet->addSheet($sheet);

Example file:

example.xlsx

What features do you think are causing the issue

  • Reader

  • Writer

  • Styles

  • Data Validations

  • Formula Calculations

  • Charts

  • AutoFilter

  • Form Elements

Does an issue affect all spreadsheet file formats? If not, which formats are affected?

XLSX

Which versions of PhpSpreadsheet and PHP are affected?

I'm using 1.28.0, didn't test any other.

oleibman added a commit to oleibman/PhpSpreadsheet that referenced this issue Dec 11, 2023
Fix PHPOffice#3820. When cloning a worksheet, special handling is already included for `cellCollection` and `drawingCollection`. It needs to be added for `tableCollection` as well. In theory, `chartCollection` also needs it. However, there are no clone methods for any of the Chart objects, so that will be a substantially larger effort. There is no need to delay this fix waiting for that.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant