modifs.mineures sans commentaires

This commit is contained in:
Jephté Clain 2024-06-24 23:30:32 +04:00
parent 76a5b9a850
commit 36a257b68c
2 changed files with 51 additions and 19 deletions

View File

@ -89,6 +89,7 @@ class SpoutBuilder extends AbstractBuilder {
$this->wroteHeaders = false;
$this->built = false;
}
$wsname ??= $params["wsname"] ?? null;
if ($wsname !== null) $ws->setName($wsname);
$sheetView = (new SheetView())
->setFreezeRow(2);

View File

@ -11,18 +11,41 @@ class SpoutReader extends AbstractReader {
function __construct($input, ?array $params=null) {
parent::__construct($input, $params);
$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;
/** @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;
/**
* @param string|int|null $wsname
*
* NB: appeler cette méthode réinitialise $allSheets à false
*/
function setWsname($wsname): self {
$this->wsname = $wsname;
$this->allSheets = true;
return $this;
}
@ -40,15 +63,21 @@ class SpoutReader extends AbstractReader {
}
$ss->open($this->input);
try {
$found = false;
$allSheets = $this->allSheets;
$wsname = $this->wsname;
$first = true;
foreach ($ss->getSheetIterator() as $ws) {
if ($this->wsname === null || $this->wsname === $ws->getName()) {
$found = true;
break;
if ($allSheets) $found = true;
else $found = $wsname === null || $wsname === $ws->getName();
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;
}
}
if (!$found) return;
$this->isrc = $this->idest = 0;
foreach ($ws->getRowIterator() as $row) {
$row = $row->toArray();
@ -61,6 +90,8 @@ class SpoutReader extends AbstractReader {
}
$this->isrc++;
}
}
}
} finally {
$ss->close();
}