Skip to content

Commit

Permalink
fix count columns in multiple headers
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrajodas committed Dec 3, 2020
1 parent 9be4ceb commit 74052bb
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Keboola/GoogleDriveExtractor/Extractor/Output.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ public function write(array $data, int $offset): void
if ($this->header === null) {
$headerRowNum = $this->sheetCfg['header']['rows'] - 1;
$this->header = $data[$headerRowNum];
$headerLength = $this->getHeaderLength($data, (int) $headerRowNum);
} else {
$headerLength = count($this->header);
}

$headerLength = count($this->header);

foreach ($data as $k => $row) {
// backward compatibility fix
if ($this->sheetCfg['header']['rows'] === 1 && $k === 0 && $offset === 1) {
Expand Down Expand Up @@ -94,4 +95,13 @@ protected function normalizeCsvHeader(array $header): array
}
return $header;
}

private function getHeaderLength(array $data, int $headerRowNum): int
{
$headerLength = 0;
for ($i = 0; $i <= $headerRowNum; $i++) {
$headerLength = max($headerLength, count($data[$i]));
}
return $headerLength;
}
}

0 comments on commit 74052bb

Please sign in to comment.