odf_calc_reader.php 813 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. /**
  3. * @file
  4. * Demo application for LibreOffice Calc reader.
  5. *
  6. * Pass the path of "content.xml" in an unpacked ODF spreadsheet.
  7. * Suggested: use the supplied odf_sample.ods, unpacked
  8. */
  9. declare(strict_types=1);
  10. use Osinet\OpenDocument\Calc\Reader;
  11. use Osinet\OpenDocument\Calc\Row;
  12. error_reporting(-1);
  13. require __DIR__ . '/../../vendor/autoload.php';
  14. $path = $argv[1];
  15. $reader = new Reader($path);
  16. echo "This file contains the following sheets:\n";
  17. $sheetNames = $reader->getCalcSheetNames();
  18. print_r($sheetNames);
  19. echo PHP_EOL;
  20. $rows = $reader->getRows();
  21. foreach ($rows as $rowNum => $nodeList) {
  22. $row = new Row($nodeList);
  23. printf("%3d", $rowNum);
  24. $cells = $row->getCells();
  25. for ($i = 0; $i < count($cells); $i++) {
  26. printf('|%11s', $cells[$i]->displayValue);
  27. }
  28. echo PHP_EOL;
  29. }