Skip to content

Commit 79f9521

Browse files
author
MarkBaker
committed
Detect the presence of a sep=; line in CSV imports, and set the delimiter accordingly
1 parent a806b79 commit 79f9521

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Classes/PHPExcel/Reader/CSV.php

+19
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,23 @@ protected function skipBOM()
157157
}
158158
}
159159

160+
/**
161+
* Identify any separator that is explicitly set in the file
162+
*
163+
*/
164+
protected function checkSeparator()
165+
{
166+
$line = fgets($this->fileHandle);
167+
if ($line === false) {
168+
return;
169+
}
170+
171+
if ((strlen(trim($line)) == 5) && (strpos($line, 'sep=') !== 0)) {
172+
return $this->skipBOM();
173+
}
174+
$this->delimiter = substr($line, 4, 1);
175+
}
176+
160177
/**
161178
* Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns)
162179
*
@@ -175,6 +192,7 @@ public function listWorksheetInfo($pFilename)
175192

176193
// Skip BOM, if any
177194
$this->skipBOM();
195+
$this->checkSeparator();
178196

179197
$escapeEnclosures = array( "\\" . $this->enclosure, $this->enclosure . $this->enclosure );
180198

@@ -239,6 +257,7 @@ public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel)
239257

240258
// Skip BOM, if any
241259
$this->skipBOM();
260+
$this->checkSeparator();
242261

243262
// Create new PHPExcel object
244263
while ($objPHPExcel->getSheetCount() <= $this->sheetIndex) {

0 commit comments

Comments
 (0)