Skip to content

Commit

Permalink
fix: Allow to read data from a table located in a different sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Verschaeve committed Jul 31, 2023
1 parent d6e2e24 commit 7021ab5
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,31 @@ private function getTableByName(Cell $cell): Table
{
$table = $cell->getWorksheet()->getTableByName($this->tableName);

if (!$table) {
$table = $this->findTableFromOtherSheets($cell);
}

if ($table === null) {
throw new Exception("Table {$this->tableName} for Structured Reference cannot be located");
}

return $table;
}

private function findTableFromOtherSheets(Cell $cell): ?Table
{
$spreadsheet = $cell->getWorksheet()->getParent();

foreach ($spreadsheet->getAllSheets() as $sheet) {
$table = $sheet->getTableByName($this->tableName);
if (null !== $table) {
return $table;
}
}

return null;
}

private function getColumns(Cell $cell, array $tableRange): array
{
$worksheet = $cell->getWorksheet();
Expand Down

0 comments on commit 7021ab5

Please sign in to comment.