Browse Source

FEAT added getCalcSheets
FEAT added getCalcSheetNames

These allow client code to query the name of worksheets in order to offer a selection to the user and avoid querying the whole set of sheets.

Frederic G. Marand 16 years ago
parent
commit
1956657f90
1 changed files with 39 additions and 6 deletions
  1. 39 6
      ooo/Calc_Reader.php

+ 39 - 6
ooo/Calc_Reader.php

@@ -4,7 +4,7 @@
  *
  * Requires PHP 5.2
  *
- * @version $Id: Calc_Reader.php,v 1.3 2007-08-06 16:32:48 marand Exp $
+ * @version $Id: Calc_Reader.php,v 1.4 2007-09-02 20:50:12 marand Exp $
  * @license CeCILL 2.0
  * @copyright 2005-2006 Ouest Systemes Informatiques
  */
@@ -18,17 +18,17 @@ class Calc_Reader
   {
   const NS_TABLE  = "urn:oasis:names:tc:opendocument:xmlns:table:1.0";
   const NS_OFFICE = "urn:oasis:names:tc:opendocument:xmlns:office:1.0";
-  
+
   /**
    * @var DOMDocument $xml
    */
   public $xml;
-  
+
   /**
    * @var DOMXPath $xpath
    */
   public $xpath;
-  
+
   function __construct($path)
     {
     $this->xml = new DOMDocument();
@@ -37,7 +37,40 @@ class Calc_Reader
 
     $this->xpath = new DOMXPath($this->xml);
     $this->xpath->registerNameSpace('office', Calc_Reader::NS_OFFICE);
-    $this->xpath->registerNameSpace('table', Calc_Reader::NS_TABLE);      
+    $this->xpath->registerNameSpace('table', Calc_Reader::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(Calc_Reader::NS_TABLE, 'name');
+      }
+
+    unset($dnlSheets);
+    return $ret;
     }
 
   /**
@@ -49,7 +82,7 @@ class Calc_Reader
    */
   function getRows ($namedRange = NULL)
     {
-    $query = empty($namedRange) 
+    $query = empty($namedRange)
       ? '//table:table-row'
       : '//table:table[@table:name="' . $namedRange . '"]/table:table-row';