From 075573d8d053f4efeaf88a873c6138ae77cc6121 Mon Sep 17 00:00:00 2001 From: Gabriele Perego Date: Sat, 31 Aug 2013 16:03:35 +0200 Subject: [PATCH] Added ability to use the thousands separator in excel --- php-export-data.class.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/php-export-data.class.php b/php-export-data.class.php index d983cf7..b3c3254 100755 --- a/php-export-data.class.php +++ b/php-export-data.class.php @@ -10,15 +10,17 @@ abstract class ExportData { protected $stringData; // stringData so far, used if export string mode protected $tempFile; // handle to temp file (for export file mode) protected $tempFilename; // temp file name and path (for export file mode) + protected $thousandsSeparator; // handle thousands separator in excel export public $filename; // file mode: the output file name; browser mode: file name for download; string mode: not used - public function __construct($exportTo = "browser", $filename = "exportdata") { + public function __construct($exportTo = "browser", $filename = "exportdata", $thousandsSeparator = false) { if(!in_array($exportTo, array('browser','file','string') )) { throw new Exception("$exportTo is not a valid ExportData export type"); } $this->exportTo = $exportTo; $this->filename = $filename; + $this->thousandsSeparator = $thousandsSeparator; } public function initialize() { @@ -168,6 +170,7 @@ function generateHeader() { // Set up styles $output .= "\n"; $output .= "\n"; + $output .= "\n"; $output .= "\n"; // worksheet header @@ -206,6 +209,7 @@ private function generateCell($item) { // as text if number is longer than that. if(preg_match("/^-?\d+(?:[.,]\d+)?$/",$item) && (strlen($item) < 15)) { $type = 'Number'; + $style = $this->thousandsSeparator ? 's63' : null; // defined in header; tells excel to format number with thousands separator } // Sniff for valid dates; should look something like 2010-07-14 or 7/14/2010 etc. Can // also have an optional time after the date.