1
0

odf_calc_reader.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /**
  3. * This code uses several external classes:
  4. *
  5. * - PSR0-compliant
  6. * - OSInet Open_Document package.
  7. * - PHP 5.3
  8. */
  9. use \OSInet\Open_Document\Calc\Reader as ODFReader;
  10. use \OSInet\Open_Document\Calc\Row as ODFRow;
  11. use \OSInet\Open_Document\Calc\Cell;
  12. error_reporting(-1);
  13. // Include the OSInet PSR0 sample autoloader.
  14. require __DIR__ .'/../../misc/psr0.php';
  15. // Initialize PSR0 autoloader for remaining classes.
  16. spl_autoload_register('psr0_autoload', TRUE);
  17. // Use the path of "content.xml" in an unpacked ODF spreadsheet.
  18. // Suggested: use the supplied odf_sample.odf, unpacked
  19. $path = $argv[1];
  20. $reader = new ODFReader($path);
  21. echo "This file contains the following sheets:\n";
  22. $sheetNames = $reader->getCalcSheetNames();
  23. print_r($sheetNames);
  24. echo PHP_EOL;
  25. $rows = $reader->getRows();
  26. foreach ($rows as $rowNum => $nodeList) {
  27. $row = new ODFRow($nodeList);
  28. printf("%3d", $rowNum);
  29. $cells = $row->getCells();
  30. for ($i = 0 ; $i < count($cells) ; $i++) {
  31. printf('|%11s', $cells[$i]->displayValue);
  32. }
  33. echo PHP_EOL;
  34. }