Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/PhpSpreadsheet/ReferenceHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,12 @@ function ($coordinate) use ($cellCollection) {
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
Expand Down
6 changes: 3 additions & 3 deletions src/PhpSpreadsheet/Worksheet/BaseDrawing.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
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,
Expand Down Expand Up @@ -530,6 +530,6 @@ public function setEditAs(string $editAs): self

public function validEditAs(): bool
{
return in_array($this->editAs, self::VALID_EDIT_AS);
return in_array($this->editAs, self::VALID_EDIT_AS, true);
}
}
45 changes: 45 additions & 0 deletions tests/PhpSpreadsheetTests/Writer/Xlsx/DrawingsInsertRowsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace PhpOffice\PhpSpreadsheetTests\Writer\Xlsx;

use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional;

class DrawingsInsertRowsTest extends AbstractFunctional
{
/**
* Test save and load XLSX file with drawing on 2nd worksheet.
*/
public function testSaveAfterInsertingRows(): void
{
// Read spreadsheet from file
$inputFilename = 'tests/data/Writer/XLSX/issue.2908.xlsx';
$reader = new Xlsx();
$spreadsheet = $reader->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();
}
}
8 changes: 4 additions & 4 deletions tests/PhpSpreadsheetTests/Writer/Xlsx/DrawingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -554,10 +554,10 @@ public function providerEditAs(): array
{
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', ''],
];
}

Expand Down
Binary file added tests/data/Writer/XLSX/issue.2908.xlsx
Binary file not shown.