Commit c966bf0e authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

- [FIX] Correction de détection des numéros de lignes

- [FIX] Remontée de NULL si valeur vide dans une cellule pour getValue au lieu de 0
- Amélioration : possibilité de fournir des coordonnées de colonnes sous forme de lettre directement
parent ca1f4e33
Loading
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
CHANGELOG
=========

6.0.3
------------------
- [FIX] Correction de détection des numéros de lignes
- [FIX] Remontée de NULL si valeur vide dans une cellule pour getValue au lieu de 0
- Amélioration : possibilité de fournir des coordonnées de colonnes sous forme de lettre directement

6.0.2
------------------

+5 −1
Original line number Diff line number Diff line
@@ -56,7 +56,11 @@ class Calc
            $spreadsheet = $this->document->find($content, 'office:spreadsheet')[0];
            $node        = $this->document->find($spreadsheet, 'table:table')[$index];

            if ($node) {
                $this->sheets[$index] = new Sheet($this, $index, $node);
            }else{
                throw new \Exception('La feuille '.$index.' n\'existe pas');
            }
        }

        return $this->sheets[$index];
+8 −4
Original line number Diff line number Diff line
@@ -15,7 +15,6 @@ class Cell




    /**
     * @inheritDoc
     */
@@ -160,9 +159,14 @@ class Cell
     */
    public function getValue()
    {
        if (!$this->node->nodeValue) {
            return null;
        }
        if ($this->node->hasAttributes()) {
            $value = $this->node->attributes->getNamedItem('value');
            if ($value) return $value->value;
            $value = $this->node->nodeValue;
            return $value;
        }

        return null;
+18 −6
Original line number Diff line number Diff line
@@ -57,7 +57,9 @@ class Sheet
        $this->cellsByName = [];
        $this->maxRow      = 0;
        $this->maxCol      = 0;
        $rowIndex          = 1;
        $rowIndex          = 0;

        /** @var DOMNode[] $rcs */
        $rcs               = $this->node->childNodes;
        foreach ($rcs as $rc) {
            switch ($rc->tagName) {
@@ -66,7 +68,8 @@ class Sheet
                case 'table:table-column':
                break;
                case 'table:table-row':
                    $this->readRow($rc, $rowIndex++);
                    $rowSpan = $rc->attributes->getNamedItem('number-rows-repeated')?->value ?: 1;
                    $this->readRow($rc, $rowIndex += $rowSpan);
                break;
            }
        }
@@ -118,8 +121,11 @@ class Sheet



    private function addCell(Cell $cell, $col, $row)
    private function addCell(Cell $cell, int|string $col, int $row): void
    {
        if (is_string($col)){
            $col = Calc::letterToNumber($col);
        }
        if (!isset($this->cells[$col])) {
            $this->cells[$col] = [];
        }
@@ -190,15 +196,21 @@ class Sheet



    public function hasCellByCoords(int $col, int $row): bool
    public function hasCellByCoords(int|string $col, int $row): bool
    {
        if (is_string($col)){
            $col = Calc::letterToNumber($col);
        }
        return array_key_exists($col, $this->cells) && array_key_exists($row, $this->cells[$col]) && $this->cells[$col][$row] instanceof Cell;
    }



    public function getCellByCoords(int $col, int $row): ?Cell
    public function getCellByCoords(int|string $col, int $row): ?Cell
    {
        if (is_string($col)){
            $col = Calc::letterToNumber($col);
        }
        if ($this->hasCellByCoords($col, $row)) {
            return $this->cells[$col][$row];
        }
@@ -239,7 +251,7 @@ class Sheet
            for ($c = 1; $c <= $this->getMaxCol(); $c++) {
                $cell = $this->getCellByCoords($c, $r);
                if ($cell && $cell->getRow() == $r && $cell->getCol() == $c) {
                    $h .= '<td rowspan="' . $cell->getRowSpan() . '" colspan="' . $cell->getColSpan() . '">' . ($cell ? $cell->getContent() : '') . '</td>';
                    $h .= '<td rowspan="' . $cell->getRowSpan() . '" colspan="' . $cell->getColSpan() . '">' . ($cell ? $cell->getValue() : '') . '</td>';
                }elseif(!$cell){
                    $h .= '<td></td>';
                }