1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- namespace Osinet\OpenDocument\Calc;
- class Cell {
-
- const TYPE_STRING = 'string';
- const TYPE_FLOAT = 'float';
- const TYPE_EMPTY = 'empty';
- public string $dataType;
- public ?string $dataValue;
- public ?string $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): void {
- $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}");
- }
- }
-
- function __toString() {
- return (string) $this->displayValue;
- }
- }
|