This commit is contained in:
David Bonting authored and GitHub committed 2022-05-26 15:55:27 +02:00
commit ccb7bdb162
3 files changed
+31 -4

No files matched your search

+11
View File
@@ -139,6 +139,9 @@ class Cell
*/
protected function detectType($value)
{
if (CellTypeHelper::isFormula($value)) {
return self::TYPE_FORMULA;
}
if (CellTypeHelper::isBoolean($value)) {
return self::TYPE_BOOLEAN;
}
@@ -198,6 +201,14 @@ class Cell
return $this->type === self::TYPE_DATE;
}
/**
* @return bool
*/
public function isFormula()
{
return $this->type === self::TYPE_FORMULA;
}
/**
* @return bool
*/
+12 -2
View File
@@ -60,9 +60,19 @@ class CellTypeHelper
*/
public static function isDateTimeOrDateInterval($value)
{
return (
$value instanceof \DateTimeInterface ||
return ($value instanceof \DateTimeInterface ||
$value instanceof \DateInterval
);
}
/**
* Returns whether the given value looks like a formula
*
* @param $value
* @return bool whether the given value looks like a formula
*/
public static function isFormula($value)
{
return (is_array($value) || strpos($value, '=') === 0);
}
}
@@ -179,7 +179,7 @@ EOD;
* @throws InvalidArgumentException If the given value cannot be processed
* @return RegisteredStyle
*/
private function applyStyleAndRegister(Cell $cell, Style $rowStyle) : RegisteredStyle
private function applyStyleAndRegister(Cell $cell, Style $rowStyle): RegisteredStyle
{
$isMatchingRowStyle = false;
if ($cell->getStyle()->isEmpty()) {
@@ -228,7 +228,13 @@ EOD;
$cellXML = '<c r="' . $columnLetters . $rowIndexOneBased . '"';
$cellXML .= ' s="' . $styleId . '"';
if ($cell->isString()) {
if ($cell->isFormula()) {
if (is_array($cell->getValue())) {
$cellXML .= ' ><f>' . substr($cell->getValue()[0], 1) . '</f><v>' . $cell->getValue()[1] . '</v></c>';
} else {
$cellXML .= ' ><f>' . substr($cell->getValue(), 1) . '</f></c>';
}
} elseif ($cell->isString()) {
$cellXML .= $this->getCellXMLFragmentForNonEmptyString($cell->getValue());
} elseif ($cell->isBoolean()) {
$cellXML .= ' t="b"><v>' . (int) ($cell->getValue()) . '</v></c>';