<?php
/**
 * This code uses several external classes:
 *
 * - PSR0-compliant
 *   - OSInet Open_Document package.
 * - PHP 5.3
 */

use \OSInet\Open_Document\Calc\Reader as ODFReader;
use \OSInet\Open_Document\Calc\Row as ODFRow;
use \OSInet\Open_Document\Calc\Cell;

error_reporting(-1);

// Include the OSInet PSR0 sample autoloader.
require __DIR__ .'/../../misc/psr0.php';

// Initialize PSR0 autoloader for remaining classes.
spl_autoload_register('psr0_autoload', TRUE);

// Use the path of "content.xml" in an unpacked ODF spreadsheet.
// Suggested: use the supplied odf_sample.odf, unpacked
$path = $argv[1];

$reader = new ODFReader($path);
echo "This file contains the following sheets:\n";
$sheetNames = $reader->getCalcSheetNames();
print_r($sheetNames);
echo PHP_EOL;

$rows = $reader->getRows();
foreach ($rows as $rowNum => $nodeList) {
  $row = new ODFRow($nodeList);
  printf("%3d", $rowNum);
  $cells = $row->getCells();
  for ($i = 0 ; $i < count($cells) ; $i++) {
    printf('|%11s', $cells[$i]->displayValue);
  }
  echo PHP_EOL;
}