-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #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.
- Loading branch information
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
tests/PhpSpreadsheetTests/Worksheet/Table/Issue3820Test.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpOffice\PhpSpreadsheetTests\Worksheet\Table; | ||
|
||
use PhpOffice\PhpSpreadsheet\Worksheet\Table; | ||
|
||
class Issue3820Test extends SetupTeardown | ||
{ | ||
public function testTableOnOtherSheet(): void | ||
{ | ||
// Clone worksheet failed when table was on sheet | ||
$spreadsheet = $this->getSpreadsheet(); | ||
$sheet = $this->getSheet(); | ||
$sheet->setTitle('Original'); | ||
$sheet->fromArray( | ||
[ | ||
['MyCol', 'Colonne2', 'Colonne3'], | ||
[10, 20], | ||
[2], | ||
[3], | ||
[4], | ||
], | ||
null, | ||
'B1', | ||
true | ||
); | ||
$table = new Table('B1:D5', 'Tableau1'); | ||
$sheet->addTable($table); | ||
$clonedSheet = clone $sheet; | ||
$clonedSheet->setTitle('Cloned'); | ||
$spreadsheet->addsheet($clonedSheet); | ||
$originalTable = $spreadsheet->getTableByName('Tableau1'); | ||
$newTable = $spreadsheet->getTableByName('Tableau1clone'); | ||
self::assertNotNull($newTable); | ||
self::assertSame($table, $originalTable); | ||
self::assertSame('Cloned', $newTable->getWorksheet()?->getTitle()); | ||
self::assertSame('B1:D5', $newTable->getRange()); | ||
} | ||
} |