-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Spreadsheet copy removes worksheets from source #1483
Comments
Hi! Try this patch:
Does it solve the problem? |
Works like a charm, thanks. I've end up doing a ugly fix myself while this is reaches a new release. Maybe it's useful for somebody: function ugly_copy_spreadsheet(Spreadsheet $spreadsheet){
$copied = clone $spreadsheet;
$copied->disconnectWorksheets();
for($i=0; $i<$spreadsheet->getSheetCount(); $i++){
$sheet_copy = $spreadsheet->getSheet($i)->copy;
// Do: $sheet_copy->parent = null;
$reflector = new ReflectionClass($sheet_copy);
$parent_property = $reflector->getProperty('parent');
$parent_property->setAccessible(true);
$parent_property->setValue($sheet_copy, null);
$copied->addSheet($sheet_copy);
}
return $copied;
} |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
Supplied code works correctly now. Fixed by PR #2951 in July 2022. |
This is:
What is the expected behavior?
I am creating a duplicate of a spreadsheet and I expect to have a copy of the sheets while keeping the original ones.
What is the current behavior?
Copy methods removes the original sheets from the source spreadsheet. The problem is that the
Worksheet@rebindParent
method that callsSpreadsheet@removeSheetByIndex
. I understand this method is useful when moving a sheet from one spreadsheet to another, but does not work for copies.What are the steps to reproduce?
This is a simple code to reproduce
Which versions of PhpSpreadsheet and PHP are affected?
At least 1.8 and 1.12
I as using 1.8 in my project and upgraded to the last 1.12 and I found the problem in both of them.
The text was updated successfully, but these errors were encountered: