diff --git a/src/Spout/Common/Entity/Cell.php b/src/Spout/Common/Entity/Cell.php
index 87157d4..91b0991 100644
--- a/src/Spout/Common/Entity/Cell.php
+++ b/src/Spout/Common/Entity/Cell.php
@@ -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
*/
diff --git a/src/Spout/Common/Helper/CellTypeHelper.php b/src/Spout/Common/Helper/CellTypeHelper.php
index 6f567c4..ab71a25 100644
--- a/src/Spout/Common/Helper/CellTypeHelper.php
+++ b/src/Spout/Common/Helper/CellTypeHelper.php
@@ -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 (strpos($value, '=') === 0);
+ }
}
diff --git a/src/Spout/Writer/XLSX/Manager/WorksheetManager.php b/src/Spout/Writer/XLSX/Manager/WorksheetManager.php
index 6025442..f60d873 100644
--- a/src/Spout/Writer/XLSX/Manager/WorksheetManager.php
+++ b/src/Spout/Writer/XLSX/Manager/WorksheetManager.php
@@ -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,9 @@ EOD;
$cellXML = 'isString()) {
+ if ($cell->isFormula()) {
+ $cellXML .= ' >' . substr($cell->getValue(), 1) . '';
+ } elseif ($cell->isString()) {
$cellXML .= $this->getCellXMLFragmentForNonEmptyString($cell->getValue());
} elseif ($cell->isBoolean()) {
$cellXML .= ' t="b">' . (int) ($cell->getValue()) . '';