modifs.mineures sans commentaires
This commit is contained in:
parent
76a5b9a850
commit
36a257b68c
|
@ -89,6 +89,7 @@ class SpoutBuilder extends AbstractBuilder {
|
||||||
$this->wroteHeaders = false;
|
$this->wroteHeaders = false;
|
||||||
$this->built = false;
|
$this->built = false;
|
||||||
}
|
}
|
||||||
|
$wsname ??= $params["wsname"] ?? null;
|
||||||
if ($wsname !== null) $ws->setName($wsname);
|
if ($wsname !== null) $ws->setName($wsname);
|
||||||
$sheetView = (new SheetView())
|
$sheetView = (new SheetView())
|
||||||
->setFreezeRow(2);
|
->setFreezeRow(2);
|
||||||
|
|
|
@ -11,18 +11,41 @@ class SpoutReader extends AbstractReader {
|
||||||
function __construct($input, ?array $params=null) {
|
function __construct($input, ?array $params=null) {
|
||||||
parent::__construct($input, $params);
|
parent::__construct($input, $params);
|
||||||
$this->ssType = $params["ss_type"] ?? null;
|
$this->ssType = $params["ss_type"] ?? null;
|
||||||
$this->wsname = $params["wsname"] ?? static::WSNAME;
|
$this->allSheets = $params["all_sheets"] ?? true;
|
||||||
|
$wsname = static::WSNAME;
|
||||||
|
if ($params !== null && array_key_exists("wsname", $params)) {
|
||||||
|
# spécifié par l'utilisateur: $allSheets = false
|
||||||
|
$this->setWsname($params["wsname"]);
|
||||||
|
} elseif ($wsname !== null) {
|
||||||
|
# valeur non nulle de la classe: $allSheets = false
|
||||||
|
$this->setWsname($wsname);
|
||||||
|
} else {
|
||||||
|
# pas de valeur définie dans la classe, laisser $allSheets à sa valeur
|
||||||
|
# actuelle
|
||||||
|
$this->wsname = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ?string $ssType;
|
protected ?string $ssType;
|
||||||
|
|
||||||
|
/** @var bool faut-il retourner les lignes de toutes les feuilles? */
|
||||||
|
protected bool $allSheets;
|
||||||
|
|
||||||
|
function setAllSheets(bool $allSheets=true): self {
|
||||||
|
$this->allSheets = $allSheets;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
protected $wsname;
|
protected $wsname;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string|int|null $wsname
|
* @param string|int|null $wsname
|
||||||
|
*
|
||||||
|
* NB: appeler cette méthode réinitialise $allSheets à false
|
||||||
*/
|
*/
|
||||||
function setWsname($wsname): self {
|
function setWsname($wsname): self {
|
||||||
$this->wsname = $wsname;
|
$this->wsname = $wsname;
|
||||||
|
$this->allSheets = true;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,27 +63,35 @@ class SpoutReader extends AbstractReader {
|
||||||
}
|
}
|
||||||
$ss->open($this->input);
|
$ss->open($this->input);
|
||||||
try {
|
try {
|
||||||
$found = false;
|
$allSheets = $this->allSheets;
|
||||||
|
$wsname = $this->wsname;
|
||||||
|
$first = true;
|
||||||
foreach ($ss->getSheetIterator() as $ws) {
|
foreach ($ss->getSheetIterator() as $ws) {
|
||||||
if ($this->wsname === null || $this->wsname === $ws->getName()) {
|
if ($allSheets) $found = true;
|
||||||
$found = true;
|
else $found = $wsname === null || $wsname === $ws->getName();
|
||||||
break;
|
if ($found) {
|
||||||
|
if ($first) {
|
||||||
|
$first = false;
|
||||||
|
} else {
|
||||||
|
yield null;
|
||||||
|
# on garde le même schéma le cas échéant, mais supprimer headers
|
||||||
|
# pour permettre son recalcul
|
||||||
|
$this->headers = null;
|
||||||
|
}
|
||||||
|
$this->isrc = $this->idest = 0;
|
||||||
|
foreach ($ws->getRowIterator() as $row) {
|
||||||
|
$row = $row->toArray();
|
||||||
|
foreach ($row as &$col) {
|
||||||
|
$this->verifixCol($col);
|
||||||
|
}; unset($col);
|
||||||
|
if ($this->cook($row)) {
|
||||||
|
yield $row;
|
||||||
|
$this->idest++;
|
||||||
|
}
|
||||||
|
$this->isrc++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!$found) return;
|
|
||||||
|
|
||||||
$this->isrc = $this->idest = 0;
|
|
||||||
foreach ($ws->getRowIterator() as $row) {
|
|
||||||
$row = $row->toArray();
|
|
||||||
foreach ($row as &$col) {
|
|
||||||
$this->verifixCol($col);
|
|
||||||
}; unset($col);
|
|
||||||
if ($this->cook($row)) {
|
|
||||||
yield $row;
|
|
||||||
$this->idest++;
|
|
||||||
}
|
|
||||||
$this->isrc++;
|
|
||||||
}
|
|
||||||
} finally {
|
} finally {
|
||||||
$ss->close();
|
$ss->close();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue