From d88314ac8271493d88da56b99ccec5522c4808bc Mon Sep 17 00:00:00 2001 From: Enyosolutions Date: Mon, 12 Sep 2016 10:15:33 -0500 Subject: [PATCH] Adding support for custom delimiters for csv Adding support for custom delimiters by allowing to provide some options in the constructor. --- SpreadsheetReader.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/SpreadsheetReader.php b/SpreadsheetReader.php index b019f8f..c5d0522 100644 --- a/SpreadsheetReader.php +++ b/SpreadsheetReader.php @@ -36,14 +36,24 @@ class SpreadsheetReader implements SeekableIterator, Countable * @param string Path to file * @param string Original filename (in case of an uploaded file), used to determine file type, optional * @param string MIME type from an upload, used to determine file type, optional + * @param string $Options array of options containing Delimiter and Enclosure, used to determine change csv file separator, optional */ - public function __construct($Filepath, $OriginalFilename = false, $MimeType = false) + public function __construct($Filepath, $OriginalFilename = false, $MimeType = false, $Options = false) { if (!is_readable($Filepath)) { throw new Exception('SpreadsheetReader: File ('.$Filepath.') not readable'); } + if ($Options){ + $Options = array_merge($this-> Options, $Options); + } + else + { + $Options = $this-> Options; + } + + // To avoid timezone warnings and exceptions for formatting dates retrieved from files $DefaultTZ = @date_default_timezone_get(); if ($DefaultTZ) @@ -167,14 +177,14 @@ public function __construct($Filepath, $OriginalFilename = false, $MimeType = fa break; case self::TYPE_CSV: self::Load(self::TYPE_CSV); - $this -> Handle = new SpreadsheetReader_CSV($Filepath, $this -> Options); + $this -> Handle = new SpreadsheetReader_CSV($Filepath, $Options); break; case self::TYPE_XLS: // Everything already happens above break; case self::TYPE_ODS: self::Load(self::TYPE_ODS); - $this -> Handle = new SpreadsheetReader_ODS($Filepath, $this -> Options); + $this -> Handle = new SpreadsheetReader_ODS($Filepath, $Options); break; } }