diff --git a/src/PhpSpreadsheet/ReferenceHelper.php b/src/PhpSpreadsheet/ReferenceHelper.php index 8caaab18..59247f89 100644 --- a/src/PhpSpreadsheet/ReferenceHelper.php +++ b/src/PhpSpreadsheet/ReferenceHelper.php @@ -525,6 +525,12 @@ class ReferenceHelper if ($objDrawing->getCoordinates() != $newReference) { $objDrawing->setCoordinates($newReference); } + if ($objDrawing->getCoordinates2() !== '') { + $newReference = $this->updateCellReference($objDrawing->getCoordinates2()); + if ($objDrawing->getCoordinates2() != $newReference) { + $objDrawing->setCoordinates2($newReference); + } + } } // Update workbook: define names diff --git a/src/PhpSpreadsheet/Worksheet/BaseDrawing.php b/src/PhpSpreadsheet/Worksheet/BaseDrawing.php index 815536b5..369e4162 100644 --- a/src/PhpSpreadsheet/Worksheet/BaseDrawing.php +++ b/src/PhpSpreadsheet/Worksheet/BaseDrawing.php @@ -9,8 +9,8 @@ use PhpOffice\PhpSpreadsheet\IComparable; class BaseDrawing implements IComparable { const EDIT_AS_ABSOLUTE = 'absolute'; - const EDIT_AS_ONECELL = 'onecell'; - const EDIT_AS_TWOCELL = 'twocell'; + const EDIT_AS_ONECELL = 'oneCell'; + const EDIT_AS_TWOCELL = 'twoCell'; private const VALID_EDIT_AS = [ self::EDIT_AS_ABSOLUTE, self::EDIT_AS_ONECELL, @@ -530,6 +530,6 @@ class BaseDrawing implements IComparable public function validEditAs(): bool { - return in_array($this->editAs, self::VALID_EDIT_AS); + return in_array($this->editAs, self::VALID_EDIT_AS, true); } } diff --git a/tests/PhpSpreadsheetTests/Writer/Xlsx/DrawingsInsertRowsTest.php b/tests/PhpSpreadsheetTests/Writer/Xlsx/DrawingsInsertRowsTest.php new file mode 100644 index 00000000..e2cbbff3 --- /dev/null +++ b/tests/PhpSpreadsheetTests/Writer/Xlsx/DrawingsInsertRowsTest.php @@ -0,0 +1,45 @@ +load($inputFilename); + $sheet = $spreadsheet->getActiveSheet(); + $drawingCollection = $sheet->getDrawingCollection(); + self::assertCount(1, $drawingCollection); + $drawing = $drawingCollection[0]; + self::assertNotNull($drawing); + self::assertSame('D10', $drawing->getCoordinates()); + self::assertSame('F11', $drawing->getCoordinates2()); + self::assertSame('oneCell', $drawing->getEditAs()); + + $sheet->insertNewRowBefore(5); + $sheet->insertNewRowBefore(6); + + // Save spreadsheet to file and read it back + $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx'); + $spreadsheet->disconnectWorksheets(); + $rsheet = $reloadedSpreadsheet->getActiveSheet(); + $drawingCollection2 = $rsheet->getDrawingCollection(); + self::assertCount(1, $drawingCollection2); + $drawing2 = $drawingCollection2[0]; + self::assertNotNull($drawing2); + self::assertSame('D12', $drawing2->getCoordinates()); + self::assertSame('F13', $drawing2->getCoordinates2()); + self::assertSame('oneCell', $drawing2->getEditAs()); + + $reloadedSpreadsheet->disconnectWorksheets(); + } +} diff --git a/tests/PhpSpreadsheetTests/Writer/Xlsx/DrawingsTest.php b/tests/PhpSpreadsheetTests/Writer/Xlsx/DrawingsTest.php index f089b9ee..14b816d2 100644 --- a/tests/PhpSpreadsheetTests/Writer/Xlsx/DrawingsTest.php +++ b/tests/PhpSpreadsheetTests/Writer/Xlsx/DrawingsTest.php @@ -554,10 +554,10 @@ class DrawingsTest extends AbstractFunctional { return [ 'absolute' => ['absolute'], - 'onecell' => ['onecell'], - 'twocell' => ['twocell'], - 'unset (will be treated as twocell)' => [''], - 'unknown (will be treated as twocell)' => ['unknown', ''], + 'onecell' => ['oneCell'], + 'twocell' => ['twoCell'], + 'unset (will be treated as twoCell)' => [''], + 'unknown (will be treated as twoCell)' => ['unknown', ''], ]; } diff --git a/tests/data/Writer/XLSX/issue.2908.xlsx b/tests/data/Writer/XLSX/issue.2908.xlsx new file mode 100644 index 00000000..3dcd7923 Binary files /dev/null and b/tests/data/Writer/XLSX/issue.2908.xlsx differ