123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- $erCalc_Cell = error_reporting(E_ALL | E_STRICT);
- class Calc_Cell
- {
-
- const TYPE_STRING = 'string';
- const TYPE_FLOAT = 'float';
- const TYPE_EMPTY = 'empty';
-
- public $dataType;
- public $dataValue;
- public $displayValue;
-
-
- function __construct(DOMNode $cellNode)
- {
- if (is_a($cellNode, 'DOMElement'))
- {
- $this->dataType = $cellNode->getAttributeNS(Calc_Reader::NS_OFFICE, 'value-type');
-
- $this->dataValue = $cellNode->getAttributeNS(Calc_Reader::NS_OFFICE, 'value');
- $p = $cellNode->childNodes->item(0);
- $this->displayValue = $p->textContent;
- unset($p);
- }
- else
- {
- $this->dataType = Calc_Cell::TYPE_EMPTY;
- $this->dataValue = NULL;
- $this->displayValue = '';
- }
- }
-
-
- function set($x = NULL)
- {
- $type = gettype($x);
- switch ($type)
- {
- case 'NULL':
- $this->dataType = Calc_Cell::TYPE_EMPTY;
- $this->dataValue = NULL;
- $this->displayValue = NULL;
- break;
- case 'string':
- $this->dataType = Calc_Cell::TYPE_STRING;
- $this->dataValue = NULL;
- $this->displayValue = $x;
- break;
- case 'double':
- $this->dataType = Calc_Cell::TYPE_FLOAT;
- $this->dataValue = $x;
- $this->displayValue = number_format($x);
- break;
- default:
- $this->set();
- throw new Exception('Calc_Cell::set unsupported value type ', $type);
- break;
- }
- }
-
-
- function __toString()
- {
- return (string) $this->displayValue;
- }
- }
- error_reporting($erCalc_Cell);
- unset($erCalc_Cell);
|