Skip to content

Commit

Permalink
new: getColAttributes(): array
Browse files Browse the repository at this point in the history
  • Loading branch information
aVadim483 committed Jun 7, 2024
1 parent adce7d5 commit f7d54be
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/FastExcelReader/Sheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class Sheet implements InterfaceSheetReader

protected ?array $dimension = null;

protected ?array $cols = null;

protected ?bool $active = null;
protected array $area = [];

Expand All @@ -46,6 +48,7 @@ class Sheet implements InterfaceSheetReader

protected array $sharedFormulas = [];


public function __construct($sheetName, $sheetId, $file, $path, $excel)
{
$this->excel = $excel;
Expand Down Expand Up @@ -295,6 +298,21 @@ protected function _readHeader()
if ($xmlReader->nodeType === \XMLReader::ELEMENT && $xmlReader->name === 'sheetView') {
$this->active = (int)$xmlReader->getAttribute('sheetView');
}
if ($xmlReader->nodeType === \XMLReader::ELEMENT && $xmlReader->name === 'col') {
$this->active = (int)$xmlReader->getAttribute('sheetView');
if ($xmlReader->hasAttributes) {
$colAttributes = [];
while ($xmlReader->moveToNextAttribute()) {
$colAttributes[$xmlReader->name] = $xmlReader->value;
}
$this->cols[] = $colAttributes;
$xmlReader->moveToElement();
}

}
if ($xmlReader->name === 'sheetData') {
break;
}
}
$xmlReader->close();
}
Expand Down Expand Up @@ -394,6 +412,27 @@ public function countCols(?string $range = null): int
return $this->countColumns($range);
}

/**
* @return array
*/
public function getColAttributes(): array
{
$result = [];
if ($this->cols) {
foreach ($this->cols as $colAttributes) {
if (isset($colAttributes['min'])) {
$col = Helper::colLetter($colAttributes['min']);
$result[$col] = $colAttributes;
}
else {
$result[] = $colAttributes;
}
}
}

return $result;
}

/**
* @param $dateFormat
*
Expand Down

0 comments on commit f7d54be

Please sign in to comment.