Skip to content

Commit

Permalink
Fix getPrevious getNext functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Alkarex committed Sep 19, 2023
1 parent c62b1d3 commit 5dd9b65
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/XlsxFastEditorCell.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function getPreviousCell(): ?XlsxFastEditorCell
if ($c->localName === 'c') {
return new XlsxFastEditorCell($this->editor, $this->sheetNumber, $c);
}
$c = $this->c->previousElementSibling;
$c = $c->previousElementSibling;
}
return null;
}
Expand All @@ -84,10 +84,10 @@ public function getNextCell(): ?XlsxFastEditorCell
{
$c = $this->c->nextElementSibling;
while ($c !== null) {
if ($c->localName === 'r') {
if ($c->localName === 'c') {
return new XlsxFastEditorCell($this->editor, $this->sheetNumber, $c);
}
$c = $this->c->nextElementSibling;
$c = $c->nextElementSibling;
}
return null;
}
Expand Down
8 changes: 4 additions & 4 deletions src/XlsxFastEditorRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ public function getPreviousRow(): ?XlsxFastEditorRow
{
$r = $this->r->previousElementSibling;
while ($r !== null) {
if ($r->localName === 'r') {
if ($r->localName === 'row') {
return new XlsxFastEditorRow($this->editor, $this->sheetNumber, $r);
}
$r = $this->r->previousElementSibling;
$r = $r->previousElementSibling;
}
return null;
}
Expand All @@ -72,10 +72,10 @@ public function getNextRow(): ?XlsxFastEditorRow
{
$r = $this->r->nextElementSibling;
while ($r !== null) {
if ($r->localName === 'r') {
if ($r->localName === 'row') {
return new XlsxFastEditorRow($this->editor, $this->sheetNumber, $r);
}
$r = $this->r->nextElementSibling;
$r = $r->nextElementSibling;
}
return null;
}
Expand Down
5 changes: 5 additions & 0 deletions tests/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@

$row4 = $xlsxFastEditor->getRow($sheet1, 4);
assert($row4 !== null);
assert($row4->getPreviousRow()?->getNextRow()?->number() === 4);
assert($row4->getCellOrNull('D4')?->name() === 'D4');
assert($row4->getCellOrNull('d4')?->name() === 'D4');
assert($row4->getCellOrNull('D')?->name() === 'D4');
Expand All @@ -75,6 +76,10 @@
}
assert($ex instanceof \InvalidArgumentException);

$cellD4 = $row4->getCell('D4');
assert($cellD4 !== null);
assert($cellD4->getPreviousCell()?->getNextCell()?->name() === 'D4');

assert(XlsxFastEditor::cellOrderCompare('B3', 'AA23') < 0);
assert(XlsxFastEditor::cellOrderCompare('AA23', 'AB23') < 0);
assert(XlsxFastEditor::cellOrderCompare('BB22', 'BB123') < 0);
Expand Down

0 comments on commit 5dd9b65

Please sign in to comment.