123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- namespace OSInet\Open_Document\Calc;
- use OSInet\Open_Document\Calc\Reader;
- class Cell {
-
- const TYPE_STRING = 'string';
- const TYPE_FLOAT = 'float';
- const TYPE_EMPTY = 'empty';
- public $dataType;
- public $dataValue;
- public $displayValue;
-
- function __construct(\DOMNode $cellNode) {
- if ($cellNode instanceof \DOMElement) {
- $this->dataType = $cellNode->getAttributeNS(Reader::NS_OFFICE, 'value-type');
- if ($cellNode->childNodes->length == 0) {
- $this->dataType = self::TYPE_EMPTY;
- $this->dataValue = NULL;
- $this->displayValue = '';
- }
- else {
- $p = $cellNode->childNodes->item(0);
- $this->displayValue = $p->textContent;
- unset($p);
-
- if ($this->dataType == self::TYPE_STRING) {
-
- }
- else {
- $this->dataValue = $cellNode->getAttributeNS(Reader::NS_OFFICE, 'value');
- }
- }
- }
-
- }
-
- function set($x = NULL) {
- $type = gettype($x);
- switch ($type) {
- case 'NULL':
- $this->dataType = self::TYPE_EMPTY;
- $this->dataValue = NULL;
- $this->displayValue = NULL;
- break;
- case 'string':
- $this->dataType = self::TYPE_STRING;
- $this->dataValue = NULL;
- $this->displayValue = $x;
- break;
- case 'double':
- $this->dataType = self::TYPE_FLOAT;
- $this->dataValue = $x;
- $this->displayValue = number_format($x);
- break;
- default:
- $this->set();
- throw new \Exception('Cell::set unsupported value type ', $type);
- break;
- }
- }
-
- function __toString() {
- return (string) $this->displayValue;
- }
- }
|