Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for custom delimiters for csv #120

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions SpreadsheetReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
}
Expand Down