Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authormattab <matthieu.aubry@gmail.com>2016-04-06 15:14:45 +0300
committermattab <matthieu.aubry@gmail.com>2016-04-06 15:14:45 +0300
commit0d64cd584601c003d4d03487e540d6274e8b5962 (patch)
tree6622ada18e8d8f4d4d26d7cd28d756ebb3e11108 /core
parent0f38083969261b95a00c59f1f5596d35365506cd (diff)
Display labels correctly in Excel / LibreOffice
Diffstat (limited to 'core')
-rw-r--r--core/DataTable/Renderer/Csv.php27
1 files changed, 26 insertions, 1 deletions
diff --git a/core/DataTable/Renderer/Csv.php b/core/DataTable/Renderer/Csv.php
index c3fb08b15a..070cfdefa5 100644
--- a/core/DataTable/Renderer/Csv.php
+++ b/core/DataTable/Renderer/Csv.php
@@ -121,7 +121,6 @@ class Csv extends Renderer
{
if (is_array($table)) {
// convert array to DataTable
-
$table = DataTable::makeFromSimpleArray($table);
}
@@ -247,6 +246,9 @@ class Csv extends Renderer
} elseif ($value === false) {
$value = 0;
}
+
+ $value = $this->formatFormulas($value);
+
if (is_string($value)
&& (strpos($value, '"') !== false
|| strpos($value, $this->separator) !== false)
@@ -264,6 +266,29 @@ class Csv extends Renderer
return $value;
}
+ protected function formatFormulas($value)
+ {
+ $formulaStartsWith = array('=', '+', '-');
+
+ // remove first % sign
+ $count = 1;
+ $valueWithoutPercentSign = str_replace('%', '', $value, $count);
+
+ if (empty($valueWithoutPercentSign)
+ || !is_string($value)
+ || is_numeric($valueWithoutPercentSign)) {
+ return $value;
+ }
+
+ $firstCharCellValue = $valueWithoutPercentSign[0];
+ $isFormula = in_array($firstCharCellValue, $formulaStartsWith);
+ if($isFormula) {
+ return "'" . $value;
+ }
+
+ return $value;
+ }
+
/**
* Sends the http headers for csv file
*/