ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
PhpOffice\PhpSpreadsheet\Reader\Csv Class Reference
+ Inheritance diagram for PhpOffice\PhpSpreadsheet\Reader\Csv:
+ Collaboration diagram for PhpOffice\PhpSpreadsheet\Reader\Csv:

Public Member Functions

 __construct ()
 Create a new CSV Reader instance. More...
 
 setInputEncoding (string $pValue)
 
 getInputEncoding ()
 
 setFallbackEncoding (string $pValue)
 
 getFallbackEncoding ()
 
 listWorksheetInfo (string $pFilename)
 Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns). More...
 
 load ($pFilename)
 Loads Spreadsheet from file. More...
 
 loadIntoExisting (string $pFilename, Spreadsheet $spreadsheet)
 Loads PhpSpreadsheet from file into PhpSpreadsheet instance. More...
 
 getDelimiter ()
 
 setDelimiter (string $delimiter)
 
 getEnclosure ()
 
 setEnclosure (string $enclosure)
 
 getSheetIndex ()
 
 setSheetIndex (int $pValue)
 
 setContiguous (bool $contiguous)
 
 getContiguous ()
 
 setEscapeCharacter (string $escapeCharacter)
 
 getEscapeCharacter ()
 
 canRead ($pFilename)
 Can the current IReader read the file? More...
 
- Public Member Functions inherited from PhpOffice\PhpSpreadsheet\Reader\BaseReader
 __construct ()
 IReader constructor. More...
 
 getReadDataOnly ()
 Read data only? If this is true, then the Reader will only read data values for cells, it will not read any formatting information. More...
 
 setReadDataOnly ($pValue)
 Set read data only Set to true, to advise the Reader only to read data values for cells, and to ignore any formatting information. More...
 
 getReadEmptyCells ()
 Read empty cells? If this is true (the default), then the Reader will read data values for all cells, irrespective of value. More...
 
 setReadEmptyCells ($pValue)
 Set read empty cells Set to true (the default) to advise the Reader read data values for all cells, irrespective of value. More...
 
 getIncludeCharts ()
 Read charts in workbook? If this is true, then the Reader will include any charts that exist in the workbook. More...
 
 setIncludeCharts ($pValue)
 Set read charts in workbook Set to true, to advise the Reader to include any charts that exist in the workbook. More...
 
 getLoadSheetsOnly ()
 Get which sheets to load Returns either an array of worksheet names (the list of worksheets that should be loaded), or a null indicating that all worksheets in the workbook should be loaded. More...
 
 setLoadSheetsOnly ($value)
 Set which sheets to load. More...
 
 setLoadAllSheets ()
 Set all sheets to load Tells the Reader to load all worksheets from the workbook. More...
 
 getReadFilter ()
 Read filter. More...
 
 setReadFilter (IReadFilter $pValue)
 Set read filter. More...
 
 getSecurityScanner ()
 

Static Public Member Functions

static setConstructorCallback (?callable $callback)
 Set a callback to change the defaults. More...
 
static getConstructorCallback ()
 
static guessEncoding (string $filename, string $dflt=self::DEFAULT_FALLBACK_ENCODING)
 

Data Fields

const DEFAULT_FALLBACK_ENCODING = 'CP1252'
 
const GUESS_ENCODING = 'guess'
 
const UTF8_BOM = "\xEF\xBB\xBF"
 
const UTF8_BOM_LEN = 3
 
const UTF16BE_BOM = "\xfe\xff"
 
const UTF16BE_BOM_LEN = 2
 
const UTF16BE_LF = "\x00\x0a"
 
const UTF16LE_BOM = "\xff\xfe"
 
const UTF16LE_BOM_LEN = 2
 
const UTF16LE_LF = "\x0a\x00"
 
const UTF32BE_BOM = "\x00\x00\xfe\xff"
 
const UTF32BE_BOM_LEN = 4
 
const UTF32BE_LF = "\x00\x00\x00\x0a"
 
const UTF32LE_BOM = "\xff\xfe\x00\x00"
 
const UTF32LE_BOM_LEN = 4
 
const UTF32LE_LF = "\x0a\x00\x00\x00"
 

Protected Member Functions

 skipBOM ()
 Move filepointer past any BOM marker. More...
 
 checkSeparator ()
 Identify any separator that is explicitly set in the file. More...
 
 inferSeparator ()
 Infer the separator if it isn't explicitly set in the file or specified by the user. More...
 
- Protected Member Functions inherited from PhpOffice\PhpSpreadsheet\Reader\BaseReader
 openFile ($pFilename)
 Open file for reading. More...
 

Private Member Functions

 openFileOrMemory (string $pFilename)
 

Static Private Member Functions

static extractStringLower ($extension)
 Scrutinizer believes, incorrectly, that the specific pathinfo call in canRead can return something other than an array. More...
 
static guessEncodingTestNoBom (string &$encoding, string &$contents, string $compare, string $setEncoding)
 
static guessEncodingNoBom (string $filename)
 
static guessEncodingTestBom (string &$encoding, string $first4, string $compare, string $setEncoding)
 
static guessEncodingBom (string $filename)
 

Private Attributes

 $inputEncoding = 'UTF-8'
 
 $fallbackEncoding = self::DEFAULT_FALLBACK_ENCODING
 
 $delimiter
 
 $enclosure = '"'
 
 $sheetIndex = 0
 
 $contiguous = false
 
 $escapeCharacter = '\\'
 

Static Private Attributes

static $constructorCallback
 

Additional Inherited Members

- Protected Attributes inherited from PhpOffice\PhpSpreadsheet\Reader\BaseReader
 $readDataOnly = false
 
 $readEmptyCells = true
 
 $includeCharts = false
 
 $loadSheetsOnly
 
 $readFilter
 
 $fileHandle
 
 $securityScanner
 

Detailed Description

Definition at line 11 of file Csv.php.

Constructor & Destructor Documentation

◆ __construct()

PhpOffice\PhpSpreadsheet\Reader\Csv::__construct ( )

Create a new CSV Reader instance.

Implements PhpOffice\PhpSpreadsheet\Reader\IReader.

Definition at line 89 of file Csv.php.

90  {
91  parent::__construct();
92  $callback = self::$constructorCallback;
93  if ($callback !== null) {
94  $callback($this);
95  }
96  }

Member Function Documentation

◆ canRead()

PhpOffice\PhpSpreadsheet\Reader\Csv::canRead (   $pFilename)

Can the current IReader read the file?

Parameters
string$pFilename
Returns
bool

Implements PhpOffice\PhpSpreadsheet\Reader\IReader.

Definition at line 418 of file Csv.php.

References $type, and PhpOffice\PhpSpreadsheet\Reader\BaseReader\openFile().

Referenced by PhpOffice\PhpSpreadsheet\Reader\Csv\openFileOrMemory().

419  {
420  // Check if file exists
421  try {
422  $this->openFile($pFilename);
423  } catch (InvalidArgumentException $e) {
424  return false;
425  }
426 
427  fclose($this->fileHandle);
428 
429  // Trust file extension if any
430  $extension = self::extractStringLower(pathinfo($pFilename, PATHINFO_EXTENSION));
431  if (in_array($extension, ['csv', 'tsv'])) {
432  return true;
433  }
434 
435  // Attempt to guess mimetype
436  $type = mime_content_type($pFilename);
437  $supportedTypes = [
438  'application/csv',
439  'text/csv',
440  'text/plain',
441  'inode/x-empty',
442  ];
443 
444  return in_array($type, $supportedTypes, true);
445  }
$type
openFile($pFilename)
Open file for reading.
Definition: BaseReader.php:145
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkSeparator()

PhpOffice\PhpSpreadsheet\Reader\Csv::checkSeparator ( )
protected

Identify any separator that is explicitly set in the file.

Definition at line 153 of file Csv.php.

References PhpOffice\PhpSpreadsheet\Reader\Csv\skipBOM().

Referenced by PhpOffice\PhpSpreadsheet\Reader\Csv\listWorksheetInfo(), and PhpOffice\PhpSpreadsheet\Reader\Csv\loadIntoExisting().

153  : void
154  {
155  $line = fgets($this->fileHandle);
156  if ($line === false) {
157  return;
158  }
159 
160  if ((strlen(trim($line, "\r\n")) == 5) && (stripos($line, 'sep=') === 0)) {
161  $this->delimiter = substr($line, 4, 1);
162 
163  return;
164  }
165 
166  $this->skipBOM();
167  }
skipBOM()
Move filepointer past any BOM marker.
Definition: Csv.php:141
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ extractStringLower()

static PhpOffice\PhpSpreadsheet\Reader\Csv::extractStringLower (   $extension)
staticprivate

Scrutinizer believes, incorrectly, that the specific pathinfo call in canRead can return something other than an array.

Phpstan knows better. This function satisfies both.

Parameters
mixed$extension

Definition at line 406 of file Csv.php.

406  : string
407  {
408  return is_string($extension) ? strtolower($extension) : '';
409  }

◆ getConstructorCallback()

static PhpOffice\PhpSpreadsheet\Reader\Csv::getConstructorCallback ( )
static

Definition at line 109 of file Csv.php.

109  : ?callable
110  {
111  return self::$constructorCallback;
112  }

◆ getContiguous()

PhpOffice\PhpSpreadsheet\Reader\Csv::getContiguous ( )

Definition at line 381 of file Csv.php.

References PhpOffice\PhpSpreadsheet\Reader\Csv\$contiguous.

381  : bool
382  {
383  return $this->contiguous;
384  }

◆ getDelimiter()

PhpOffice\PhpSpreadsheet\Reader\Csv::getDelimiter ( )

Definition at line 335 of file Csv.php.

References PhpOffice\PhpSpreadsheet\Reader\Csv\$delimiter.

335  : ?string
336  {
337  return $this->delimiter;
338  }

◆ getEnclosure()

PhpOffice\PhpSpreadsheet\Reader\Csv::getEnclosure ( )

Definition at line 347 of file Csv.php.

References PhpOffice\PhpSpreadsheet\Reader\Csv\$enclosure.

347  : string
348  {
349  return $this->enclosure;
350  }

◆ getEscapeCharacter()

PhpOffice\PhpSpreadsheet\Reader\Csv::getEscapeCharacter ( )

Definition at line 393 of file Csv.php.

References PhpOffice\PhpSpreadsheet\Reader\Csv\$escapeCharacter.

393  : string
394  {
395  return $this->escapeCharacter;
396  }

◆ getFallbackEncoding()

PhpOffice\PhpSpreadsheet\Reader\Csv::getFallbackEncoding ( )

Definition at line 133 of file Csv.php.

References PhpOffice\PhpSpreadsheet\Reader\Csv\$fallbackEncoding.

133  : string
134  {
136  }

◆ getInputEncoding()

PhpOffice\PhpSpreadsheet\Reader\Csv::getInputEncoding ( )

Definition at line 121 of file Csv.php.

References PhpOffice\PhpSpreadsheet\Reader\Csv\$inputEncoding.

121  : string
122  {
123  return $this->inputEncoding;
124  }

◆ getSheetIndex()

PhpOffice\PhpSpreadsheet\Reader\Csv::getSheetIndex ( )

Definition at line 362 of file Csv.php.

References PhpOffice\PhpSpreadsheet\Reader\Csv\$sheetIndex.

362  : int
363  {
364  return $this->sheetIndex;
365  }

◆ guessEncoding()

static PhpOffice\PhpSpreadsheet\Reader\Csv::guessEncoding ( string  $filename,
string  $dflt = self::DEFAULT_FALLBACK_ENCODING 
)
static

Definition at line 496 of file Csv.php.

496  : string
497  {
498  $encoding = self::guessEncodingBom($filename);
499  if ($encoding === '') {
500  $encoding = self::guessEncodingNoBom($filename);
501  }
502 
503  return ($encoding === '') ? $dflt : $encoding;
504  }
$filename
Definition: buildRTE.php:89

◆ guessEncodingBom()

static PhpOffice\PhpSpreadsheet\Reader\Csv::guessEncodingBom ( string  $filename)
staticprivate

Definition at line 481 of file Csv.php.

481  : string
482  {
483  $encoding = '';
484  $first4 = file_get_contents($filename, false, null, 0, 4);
485  if ($first4 !== false) {
486  self::guessEncodingTestBom($encoding, $first4, self::UTF8_BOM, 'UTF-8');
487  self::guessEncodingTestBom($encoding, $first4, self::UTF16BE_BOM, 'UTF-16BE');
488  self::guessEncodingTestBom($encoding, $first4, self::UTF32BE_BOM, 'UTF-32BE');
489  self::guessEncodingTestBom($encoding, $first4, self::UTF32LE_BOM, 'UTF-32LE');
490  self::guessEncodingTestBom($encoding, $first4, self::UTF16LE_BOM, 'UTF-16LE');
491  }
492 
493  return $encoding;
494  }
$filename
Definition: buildRTE.php:89

◆ guessEncodingNoBom()

static PhpOffice\PhpSpreadsheet\Reader\Csv::guessEncodingNoBom ( string  $filename)
staticprivate

Definition at line 457 of file Csv.php.

457  : string
458  {
459  $encoding = '';
460  $contents = file_get_contents($filename);
461  self::guessEncodingTestNoBom($encoding, $contents, self::UTF32BE_LF, 'UTF-32BE');
462  self::guessEncodingTestNoBom($encoding, $contents, self::UTF32LE_LF, 'UTF-32LE');
463  self::guessEncodingTestNoBom($encoding, $contents, self::UTF16BE_LF, 'UTF-16BE');
464  self::guessEncodingTestNoBom($encoding, $contents, self::UTF16LE_LF, 'UTF-16LE');
465  if ($encoding === '' && preg_match('//u', $contents) === 1) {
466  $encoding = 'UTF-8';
467  }
468 
469  return $encoding;
470  }
$filename
Definition: buildRTE.php:89

◆ guessEncodingTestBom()

static PhpOffice\PhpSpreadsheet\Reader\Csv::guessEncodingTestBom ( string &  $encoding,
string  $first4,
string  $compare,
string  $setEncoding 
)
staticprivate

Definition at line 472 of file Csv.php.

472  : void
473  {
474  if ($encoding === '') {
475  if ($compare === substr($first4, 0, strlen($compare))) {
476  $encoding = $setEncoding;
477  }
478  }
479  }

◆ guessEncodingTestNoBom()

static PhpOffice\PhpSpreadsheet\Reader\Csv::guessEncodingTestNoBom ( string &  $encoding,
string &  $contents,
string  $compare,
string  $setEncoding 
)
staticprivate

Definition at line 447 of file Csv.php.

447  : void
448  {
449  if ($encoding === '') {
450  $pos = strpos($contents, $compare);
451  if ($pos !== false && $pos % strlen($compare) === 0) {
452  $encoding = $setEncoding;
453  }
454  }
455  }

◆ inferSeparator()

PhpOffice\PhpSpreadsheet\Reader\Csv::inferSeparator ( )
protected

Infer the separator if it isn't explicitly set in the file or specified by the user.

Definition at line 172 of file Csv.php.

References PhpOffice\PhpSpreadsheet\Reader\Csv\skipBOM().

Referenced by PhpOffice\PhpSpreadsheet\Reader\Csv\listWorksheetInfo(), and PhpOffice\PhpSpreadsheet\Reader\Csv\loadIntoExisting().

172  : void
173  {
174  if ($this->delimiter !== null) {
175  return;
176  }
177 
178  $inferenceEngine = new Delimiter($this->fileHandle, $this->escapeCharacter, $this->enclosure);
179 
180  // If number of lines is 0, nothing to infer : fall back to the default
181  if ($inferenceEngine->linesCounted() === 0) {
182  $this->delimiter = $inferenceEngine->getDefaultDelimiter();
183  $this->skipBOM();
184 
185  return;
186  }
187 
188  $this->delimiter = $inferenceEngine->infer();
189 
190  // If no delimiter could be detected, fall back to the default
191  if ($this->delimiter === null) {
192  $this->delimiter = $inferenceEngine->getDefaultDelimiter();
193  }
194 
195  $this->skipBOM();
196  }
skipBOM()
Move filepointer past any BOM marker.
Definition: Csv.php:141
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ listWorksheetInfo()

PhpOffice\PhpSpreadsheet\Reader\Csv::listWorksheetInfo ( string  $pFilename)

Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns).

Definition at line 201 of file Csv.php.

References PhpOffice\PhpSpreadsheet\Reader\BaseReader\$fileHandle, PhpOffice\PhpSpreadsheet\Reader\Csv\checkSeparator(), PhpOffice\PhpSpreadsheet\Reader\Csv\inferSeparator(), PhpOffice\PhpSpreadsheet\Reader\Csv\openFileOrMemory(), PhpOffice\PhpSpreadsheet\Reader\Csv\skipBOM(), and PhpOffice\PhpSpreadsheet\Cell\Coordinate\stringFromColumnIndex().

201  : array
202  {
203  // Open file
204  $this->openFileOrMemory($pFilename);
206 
207  // Skip BOM, if any
208  $this->skipBOM();
209  $this->checkSeparator();
210  $this->inferSeparator();
211 
212  $worksheetInfo = [];
213  $worksheetInfo[0]['worksheetName'] = 'Worksheet';
214  $worksheetInfo[0]['lastColumnLetter'] = 'A';
215  $worksheetInfo[0]['lastColumnIndex'] = 0;
216  $worksheetInfo[0]['totalRows'] = 0;
217  $worksheetInfo[0]['totalColumns'] = 0;
218 
219  // Loop through each line of the file in turn
220  $rowData = fgetcsv($fileHandle, 0, $this->delimiter ?? '', $this->enclosure, $this->escapeCharacter);
221  while (is_array($rowData)) {
222  ++$worksheetInfo[0]['totalRows'];
223  $worksheetInfo[0]['lastColumnIndex'] = max($worksheetInfo[0]['lastColumnIndex'], count($rowData) - 1);
224  $rowData = fgetcsv($fileHandle, 0, $this->delimiter ?? '', $this->enclosure, $this->escapeCharacter);
225  }
226 
227  $worksheetInfo[0]['lastColumnLetter'] = Coordinate::stringFromColumnIndex($worksheetInfo[0]['lastColumnIndex'] + 1);
228  $worksheetInfo[0]['totalColumns'] = $worksheetInfo[0]['lastColumnIndex'] + 1;
229 
230  // Close file
231  fclose($fileHandle);
232 
233  return $worksheetInfo;
234  }
inferSeparator()
Infer the separator if it isn't explicitly set in the file or specified by the user.
Definition: Csv.php:172
checkSeparator()
Identify any separator that is explicitly set in the file.
Definition: Csv.php:153
static stringFromColumnIndex($columnIndex)
String from column index.
Definition: Coordinate.php:313
openFileOrMemory(string $pFilename)
Definition: Csv.php:252
skipBOM()
Move filepointer past any BOM marker.
Definition: Csv.php:141
+ Here is the call graph for this function:

◆ load()

PhpOffice\PhpSpreadsheet\Reader\Csv::load (   $pFilename)

Loads Spreadsheet from file.

Parameters
string$pFilename
Returns
Spreadsheet

Implements PhpOffice\PhpSpreadsheet\Reader\IReader.

Definition at line 243 of file Csv.php.

References PhpOffice\PhpSpreadsheet\Reader\Csv\loadIntoExisting().

244  {
245  // Create new Spreadsheet
246  $spreadsheet = new Spreadsheet();
247 
248  // Load into this instance
249  return $this->loadIntoExisting($pFilename, $spreadsheet);
250  }
loadIntoExisting(string $pFilename, Spreadsheet $spreadsheet)
Loads PhpSpreadsheet from file into PhpSpreadsheet instance.
Definition: Csv.php:278
+ Here is the call graph for this function:

◆ loadIntoExisting()

PhpOffice\PhpSpreadsheet\Reader\Csv::loadIntoExisting ( string  $pFilename,
Spreadsheet  $spreadsheet 
)

Loads PhpSpreadsheet from file into PhpSpreadsheet instance.

Definition at line 278 of file Csv.php.

References PhpOffice\PhpSpreadsheet\Reader\BaseReader\$fileHandle, PhpOffice\PhpSpreadsheet\Reader\Csv\$sheetIndex, PhpOffice\PhpSpreadsheet\Reader\Csv\checkSeparator(), PhpOffice\PhpSpreadsheet\Spreadsheet\createSheet(), PhpOffice\PhpSpreadsheet\Spreadsheet\getSheetCount(), PhpOffice\PhpSpreadsheet\Reader\Csv\inferSeparator(), PhpOffice\PhpSpreadsheet\Reader\Csv\openFileOrMemory(), PhpOffice\PhpSpreadsheet\Spreadsheet\setActiveSheetIndex(), and PhpOffice\PhpSpreadsheet\Reader\Csv\skipBOM().

Referenced by PhpOffice\PhpSpreadsheet\Reader\Csv\load().

278  : Spreadsheet
279  {
280  $lineEnding = ini_get('auto_detect_line_endings') ?: '0';
281  ini_set('auto_detect_line_endings', '1');
282 
283  // Open file
284  $this->openFileOrMemory($pFilename);
286 
287  // Skip BOM, if any
288  $this->skipBOM();
289  $this->checkSeparator();
290  $this->inferSeparator();
291 
292  // Create new PhpSpreadsheet object
293  while ($spreadsheet->getSheetCount() <= $this->sheetIndex) {
294  $spreadsheet->createSheet();
295  }
296  $sheet = $spreadsheet->setActiveSheetIndex($this->sheetIndex);
297 
298  // Set our starting row based on whether we're in contiguous mode or not
299  $currentRow = 1;
300  $outRow = 0;
301 
302  // Loop through each line of the file in turn
303  $rowData = fgetcsv($fileHandle, 0, $this->delimiter ?? '', $this->enclosure, $this->escapeCharacter);
304  while (is_array($rowData)) {
305  $noOutputYet = true;
306  $columnLetter = 'A';
307  foreach ($rowData as $rowDatum) {
308  if ($rowDatum != '' && $this->readFilter->readCell($columnLetter, $currentRow)) {
309  if ($this->contiguous) {
310  if ($noOutputYet) {
311  $noOutputYet = false;
312  ++$outRow;
313  }
314  } else {
315  $outRow = $currentRow;
316  }
317  // Set cell value
318  $sheet->getCell($columnLetter . $outRow)->setValue($rowDatum);
319  }
320  ++$columnLetter;
321  }
322  $rowData = fgetcsv($fileHandle, 0, $this->delimiter ?? '', $this->enclosure, $this->escapeCharacter);
323  ++$currentRow;
324  }
325 
326  // Close file
327  fclose($fileHandle);
328 
329  ini_set('auto_detect_line_endings', $lineEnding);
330 
331  // Return
332  return $spreadsheet;
333  }
inferSeparator()
Infer the separator if it isn&#39;t explicitly set in the file or specified by the user.
Definition: Csv.php:172
checkSeparator()
Identify any separator that is explicitly set in the file.
Definition: Csv.php:153
openFileOrMemory(string $pFilename)
Definition: Csv.php:252
skipBOM()
Move filepointer past any BOM marker.
Definition: Csv.php:141
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ openFileOrMemory()

PhpOffice\PhpSpreadsheet\Reader\Csv::openFileOrMemory ( string  $pFilename)
private

Definition at line 252 of file Csv.php.

References $data, PhpOffice\PhpSpreadsheet\Reader\Csv\canRead(), PhpOffice\PhpSpreadsheet\Shared\StringHelper\convertEncoding(), PhpOffice\PhpSpreadsheet\Reader\BaseReader\openFile(), and PhpOffice\PhpSpreadsheet\Reader\Csv\skipBOM().

Referenced by PhpOffice\PhpSpreadsheet\Reader\Csv\listWorksheetInfo(), and PhpOffice\PhpSpreadsheet\Reader\Csv\loadIntoExisting().

252  : void
253  {
254  // Open file
255  $fhandle = $this->canRead($pFilename);
256  if (!$fhandle) {
257  throw new Exception($pFilename . ' is an Invalid Spreadsheet file.');
258  }
259  if ($this->inputEncoding === self::GUESS_ENCODING) {
260  $this->inputEncoding = self::guessEncoding($pFilename, $this->fallbackEncoding);
261  }
262  $this->openFile($pFilename);
263  if ($this->inputEncoding !== 'UTF-8') {
264  fclose($this->fileHandle);
265  $entireFile = file_get_contents($pFilename);
266  $this->fileHandle = fopen('php://memory', 'r+b');
267  if ($this->fileHandle !== false && $entireFile !== false) {
268  $data = StringHelper::convertEncoding($entireFile, 'UTF-8', $this->inputEncoding);
269  fwrite($this->fileHandle, $data);
270  $this->skipBOM();
271  }
272  }
273  }
static convertEncoding($value, $to, $from)
Convert string from one encoding to another.
canRead($pFilename)
Can the current IReader read the file?
Definition: Csv.php:418
openFile($pFilename)
Open file for reading.
Definition: BaseReader.php:145
$data
Definition: bench.php:6
skipBOM()
Move filepointer past any BOM marker.
Definition: Csv.php:141
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setConstructorCallback()

static PhpOffice\PhpSpreadsheet\Reader\Csv::setConstructorCallback ( ?callable  $callback)
static

Set a callback to change the defaults.

The callback must accept the Csv Reader object as the first parameter, and it should return void.

Definition at line 104 of file Csv.php.

104  : void
105  {
106  self::$constructorCallback = $callback;
107  }

◆ setContiguous()

PhpOffice\PhpSpreadsheet\Reader\Csv::setContiguous ( bool  $contiguous)

Definition at line 374 of file Csv.php.

374  : self
375  {
376  $this->contiguous = (bool) $contiguous;
377 
378  return $this;
379  }

◆ setDelimiter()

PhpOffice\PhpSpreadsheet\Reader\Csv::setDelimiter ( string  $delimiter)

Definition at line 340 of file Csv.php.

References PhpOffice\PhpSpreadsheet\Reader\Csv\$delimiter.

340  : self
341  {
342  $this->delimiter = $delimiter;
343 
344  return $this;
345  }

◆ setEnclosure()

PhpOffice\PhpSpreadsheet\Reader\Csv::setEnclosure ( string  $enclosure)

Definition at line 352 of file Csv.php.

References PhpOffice\PhpSpreadsheet\Reader\Csv\$enclosure.

352  : self
353  {
354  if ($enclosure == '') {
355  $enclosure = '"';
356  }
357  $this->enclosure = $enclosure;
358 
359  return $this;
360  }

◆ setEscapeCharacter()

PhpOffice\PhpSpreadsheet\Reader\Csv::setEscapeCharacter ( string  $escapeCharacter)

Definition at line 386 of file Csv.php.

References PhpOffice\PhpSpreadsheet\Reader\Csv\$escapeCharacter.

386  : self
387  {
388  $this->escapeCharacter = $escapeCharacter;
389 
390  return $this;
391  }

◆ setFallbackEncoding()

PhpOffice\PhpSpreadsheet\Reader\Csv::setFallbackEncoding ( string  $pValue)

Definition at line 126 of file Csv.php.

126  : self
127  {
128  $this->fallbackEncoding = $pValue;
129 
130  return $this;
131  }

◆ setInputEncoding()

PhpOffice\PhpSpreadsheet\Reader\Csv::setInputEncoding ( string  $pValue)

Definition at line 114 of file Csv.php.

114  : self
115  {
116  $this->inputEncoding = $pValue;
117 
118  return $this;
119  }

◆ setSheetIndex()

PhpOffice\PhpSpreadsheet\Reader\Csv::setSheetIndex ( int  $pValue)

Definition at line 367 of file Csv.php.

367  : self
368  {
369  $this->sheetIndex = $pValue;
370 
371  return $this;
372  }

◆ skipBOM()

PhpOffice\PhpSpreadsheet\Reader\Csv::skipBOM ( )
protected

Move filepointer past any BOM marker.

Definition at line 141 of file Csv.php.

Referenced by PhpOffice\PhpSpreadsheet\Reader\Csv\checkSeparator(), PhpOffice\PhpSpreadsheet\Reader\Csv\inferSeparator(), PhpOffice\PhpSpreadsheet\Reader\Csv\listWorksheetInfo(), PhpOffice\PhpSpreadsheet\Reader\Csv\loadIntoExisting(), and PhpOffice\PhpSpreadsheet\Reader\Csv\openFileOrMemory().

141  : void
142  {
143  rewind($this->fileHandle);
144 
145  if (fgets($this->fileHandle, self::UTF8_BOM_LEN + 1) !== self::UTF8_BOM) {
146  rewind($this->fileHandle);
147  }
148  }
+ Here is the caller graph for this function:

Field Documentation

◆ $constructorCallback

PhpOffice\PhpSpreadsheet\Reader\Csv::$constructorCallback
staticprivate

Definition at line 84 of file Csv.php.

◆ $contiguous

PhpOffice\PhpSpreadsheet\Reader\Csv::$contiguous = false
private

Definition at line 70 of file Csv.php.

Referenced by PhpOffice\PhpSpreadsheet\Reader\Csv\getContiguous().

◆ $delimiter

PhpOffice\PhpSpreadsheet\Reader\Csv::$delimiter
private

◆ $enclosure

PhpOffice\PhpSpreadsheet\Reader\Csv::$enclosure = '"'
private

◆ $escapeCharacter

PhpOffice\PhpSpreadsheet\Reader\Csv::$escapeCharacter = '\\'
private

◆ $fallbackEncoding

PhpOffice\PhpSpreadsheet\Reader\Csv::$fallbackEncoding = self::DEFAULT_FALLBACK_ENCODING
private

Definition at line 42 of file Csv.php.

Referenced by PhpOffice\PhpSpreadsheet\Reader\Csv\getFallbackEncoding().

◆ $inputEncoding

PhpOffice\PhpSpreadsheet\Reader\Csv::$inputEncoding = 'UTF-8'
private

Definition at line 35 of file Csv.php.

Referenced by PhpOffice\PhpSpreadsheet\Reader\Csv\getInputEncoding().

◆ $sheetIndex

PhpOffice\PhpSpreadsheet\Reader\Csv::$sheetIndex = 0
private

◆ DEFAULT_FALLBACK_ENCODING

const PhpOffice\PhpSpreadsheet\Reader\Csv::DEFAULT_FALLBACK_ENCODING = 'CP1252'

Definition at line 13 of file Csv.php.

◆ GUESS_ENCODING

const PhpOffice\PhpSpreadsheet\Reader\Csv::GUESS_ENCODING = 'guess'

Definition at line 14 of file Csv.php.

◆ UTF16BE_BOM

const PhpOffice\PhpSpreadsheet\Reader\Csv::UTF16BE_BOM = "\xfe\xff"

Definition at line 17 of file Csv.php.

◆ UTF16BE_BOM_LEN

const PhpOffice\PhpSpreadsheet\Reader\Csv::UTF16BE_BOM_LEN = 2

Definition at line 18 of file Csv.php.

◆ UTF16BE_LF

const PhpOffice\PhpSpreadsheet\Reader\Csv::UTF16BE_LF = "\x00\x0a"

Definition at line 19 of file Csv.php.

◆ UTF16LE_BOM

const PhpOffice\PhpSpreadsheet\Reader\Csv::UTF16LE_BOM = "\xff\xfe"

Definition at line 20 of file Csv.php.

◆ UTF16LE_BOM_LEN

const PhpOffice\PhpSpreadsheet\Reader\Csv::UTF16LE_BOM_LEN = 2

Definition at line 21 of file Csv.php.

◆ UTF16LE_LF

const PhpOffice\PhpSpreadsheet\Reader\Csv::UTF16LE_LF = "\x0a\x00"

Definition at line 22 of file Csv.php.

◆ UTF32BE_BOM

const PhpOffice\PhpSpreadsheet\Reader\Csv::UTF32BE_BOM = "\x00\x00\xfe\xff"

Definition at line 23 of file Csv.php.

◆ UTF32BE_BOM_LEN

const PhpOffice\PhpSpreadsheet\Reader\Csv::UTF32BE_BOM_LEN = 4

Definition at line 24 of file Csv.php.

◆ UTF32BE_LF

const PhpOffice\PhpSpreadsheet\Reader\Csv::UTF32BE_LF = "\x00\x00\x00\x0a"

Definition at line 25 of file Csv.php.

◆ UTF32LE_BOM

const PhpOffice\PhpSpreadsheet\Reader\Csv::UTF32LE_BOM = "\xff\xfe\x00\x00"

Definition at line 26 of file Csv.php.

◆ UTF32LE_BOM_LEN

const PhpOffice\PhpSpreadsheet\Reader\Csv::UTF32LE_BOM_LEN = 4

Definition at line 27 of file Csv.php.

◆ UTF32LE_LF

const PhpOffice\PhpSpreadsheet\Reader\Csv::UTF32LE_LF = "\x0a\x00\x00\x00"

Definition at line 28 of file Csv.php.

◆ UTF8_BOM

const PhpOffice\PhpSpreadsheet\Reader\Csv::UTF8_BOM = "\xEF\xBB\xBF"

Definition at line 15 of file Csv.php.

◆ UTF8_BOM_LEN

const PhpOffice\PhpSpreadsheet\Reader\Csv::UTF8_BOM_LEN = 3

Definition at line 16 of file Csv.php.


The documentation for this class was generated from the following file: