Calc_Reader.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * Utility class to access OpenDocument spreadsheets read-only
  4. *
  5. * Requires PHP 5.2
  6. *
  7. * @version $Id: Calc_Reader.php,v 1.2 2007-08-06 06:17:06 marand Exp $
  8. * @license CeCILL 2.0
  9. * @copyright 2005-2006 Ouest Systemes Informatiques
  10. */
  11. $erCalc_Reader = error_reporting(E_ALL | E_STRICT);
  12. /**
  13. * Utility class to access OpenDocument spreadsheets read-only
  14. */
  15. class Calc_Reader
  16. {
  17. const NS_TABLE = "urn:oasis:names:tc:opendocument:xmlns:table:1.0";
  18. const NS_OFFICE = "urn:oasis:names:tc:opendocument:xmlns:office:1.0";
  19. /**
  20. * @var DOMDocument $xml
  21. */
  22. public $xml;
  23. /**
  24. * @var DOMXPath $xpath
  25. */
  26. public $xpath;
  27. function __construct($path)
  28. {
  29. $this->xml = new DOMDocument();
  30. $this->xml->preserveWhiteSpace = FALSE;
  31. $this->xml->load($path);
  32. $this->xpath = new DOMXPath($this->xml);
  33. $this->xpath->registerNameSpace('office', Calc_Reader::NS_OFFICE);
  34. $this->xpath->registerNameSpace('table', Calc_Reader::NS_TABLE);
  35. }
  36. /**
  37. * Return the rows in the spreadsheet as a DOMNodeList
  38. * WARNING: this means ALL the rows, in all the sheets, not just the first sheet
  39. *
  40. * @return DOMNodeList
  41. */
  42. function getRows ()
  43. {
  44. $query = '//table:table-row';
  45. $ret = $this->xpath->query($query);
  46. unset($query);
  47. return $ret;
  48. }
  49. }
  50. error_reporting($erCalc_Reader);
  51. unset ($erCalc_Reader);