xml = new \DOMDocument(); $this->xml->preserveWhiteSpace = FALSE; $this->xml->load($path); $this->xpath = new \DOMXPath($this->xml); $this->xpath->registerNameSpace('office', self::NS_OFFICE); $this->xpath->registerNameSpace('table', self::NS_TABLE); } /** * Return a DOMNodeList of the worksheets available in the document * * @return \DOMNodeList */ function getCalcSheets() { $sq = '//table:table'; $list = $this->xpath->query($sq); unset($sq); return $list; } /** * Return the names of the worksheets available in the document * * @return array */ function getCalcSheetNames() { $dnlSheets = $this->getCalcSheets(); $ret = array(); foreach ($dnlSheets as $node) { $ret[] = $node->getAttributeNS(self::NS_TABLE, 'name'); } unset($dnlSheets); return $ret; } /** * Return the rows in the spreadsheet as a DOMNodeList. * * WARNING: this means ALL the rows, in all the sheets, not just the first sheet * * @param string $namedRange * Optional name of range, notably Sheet name * @return \DOMNodeList */ function getRows ($namedRange = NULL) { $query = empty($namedRange) ? '//table:table-row' : '//table:table[@table:name="' . $namedRange . '"]/table:table-row'; $ret = $this->xpath->query($query); unset($query); return $ret; } }