Adjust Both Coordinates for Two-Cell Anchors (#2909)
Fix #2908. When support for two-cell anchors was added for drawings, we neglected to adjust the second cell address when rows or columns are added or deleted. It also appears that "twoCell" and "oneCell" were introduced as lower-case literals when support for the editAs attribute was subsequently introduced.
This commit is contained in:
parent
a89572107a
commit
b5b83abc0e
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
@ -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', ''],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Reference in New Issue