Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
 
3
namespace PhpOffice\PhpSpreadsheet\Reader\Ods;
4
 
5
use DOMElement;
6
use DOMNode;
7
 
8
class AutoFilter extends BaseLoader
9
{
10
    public function read(DOMElement $workbookData): void
11
    {
12
        $this->readAutoFilters($workbookData);
13
    }
14
 
15
    protected function readAutoFilters(DOMElement $workbookData): void
16
    {
17
        $databases = $workbookData->getElementsByTagNameNS($this->tableNs, 'database-ranges');
18
 
19
        foreach ($databases as $autofilters) {
20
            foreach ($autofilters->childNodes as $autofilter) {
21
                $autofilterRange = $this->getAttributeValue($autofilter, 'target-range-address');
22
                if ($autofilterRange !== null) {
23
                    $baseAddress = FormulaTranslator::convertToExcelAddressValue($autofilterRange);
24
                    $this->spreadsheet->getActiveSheet()->setAutoFilter($baseAddress);
25
                }
26
            }
27
        }
28
    }
29
 
30
    protected function getAttributeValue(?DOMNode $node, string $attributeName): ?string
31
    {
32
        if ($node !== null && $node->attributes !== null) {
33
            $attribute = $node->attributes->getNamedItemNS(
34
                $this->tableNs,
35
                $attributeName
36
            );
37
 
38
            if ($attribute !== null) {
39
                return $attribute->nodeValue;
40
            }
41
        }
42
 
43
        return null;
44
    }
45
}