php__phplib/apps/odf_calc_reader/odf_calc_reader.php
Frederic G. MARAND 6a058cd843 Converted the OSInet ODF Calc reader classes to PSR0
- classes are now namespace.
- added a demo in apps/odf_calc_reader.
- added associated cleanup in Makefile.
2012-05-05 22:58:31 +02:00

41 lines
1 KiB
PHP

<?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;
}