Skip to content

Commit 5dd9b65

Browse files
committed
Fix getPrevious getNext functions
1 parent c62b1d3 commit 5dd9b65

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

src/XlsxFastEditorCell.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function getPreviousCell(): ?XlsxFastEditorCell
7171
if ($c->localName === 'c') {
7272
return new XlsxFastEditorCell($this->editor, $this->sheetNumber, $c);
7373
}
74-
$c = $this->c->previousElementSibling;
74+
$c = $c->previousElementSibling;
7575
}
7676
return null;
7777
}
@@ -84,10 +84,10 @@ public function getNextCell(): ?XlsxFastEditorCell
8484
{
8585
$c = $this->c->nextElementSibling;
8686
while ($c !== null) {
87-
if ($c->localName === 'r') {
87+
if ($c->localName === 'c') {
8888
return new XlsxFastEditorCell($this->editor, $this->sheetNumber, $c);
8989
}
90-
$c = $this->c->nextElementSibling;
90+
$c = $c->nextElementSibling;
9191
}
9292
return null;
9393
}

src/XlsxFastEditorRow.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ public function getPreviousRow(): ?XlsxFastEditorRow
5656
{
5757
$r = $this->r->previousElementSibling;
5858
while ($r !== null) {
59-
if ($r->localName === 'r') {
59+
if ($r->localName === 'row') {
6060
return new XlsxFastEditorRow($this->editor, $this->sheetNumber, $r);
6161
}
62-
$r = $this->r->previousElementSibling;
62+
$r = $r->previousElementSibling;
6363
}
6464
return null;
6565
}
@@ -72,10 +72,10 @@ public function getNextRow(): ?XlsxFastEditorRow
7272
{
7373
$r = $this->r->nextElementSibling;
7474
while ($r !== null) {
75-
if ($r->localName === 'r') {
75+
if ($r->localName === 'row') {
7676
return new XlsxFastEditorRow($this->editor, $this->sheetNumber, $r);
7777
}
78-
$r = $this->r->nextElementSibling;
78+
$r = $r->nextElementSibling;
7979
}
8080
return null;
8181
}

tests/test.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464

6565
$row4 = $xlsxFastEditor->getRow($sheet1, 4);
6666
assert($row4 !== null);
67+
assert($row4->getPreviousRow()?->getNextRow()?->number() === 4);
6768
assert($row4->getCellOrNull('D4')?->name() === 'D4');
6869
assert($row4->getCellOrNull('d4')?->name() === 'D4');
6970
assert($row4->getCellOrNull('D')?->name() === 'D4');
@@ -75,6 +76,10 @@
7576
}
7677
assert($ex instanceof \InvalidArgumentException);
7778

79+
$cellD4 = $row4->getCell('D4');
80+
assert($cellD4 !== null);
81+
assert($cellD4->getPreviousCell()?->getNextCell()?->name() === 'D4');
82+
7883
assert(XlsxFastEditor::cellOrderCompare('B3', 'AA23') < 0);
7984
assert(XlsxFastEditor::cellOrderCompare('AA23', 'AB23') < 0);
8085
assert(XlsxFastEditor::cellOrderCompare('BB22', 'BB123') < 0);

0 commit comments

Comments
 (0)