mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-10-09 21:37:25 +00:00
committed by
Adrien Crivelli
parent
0bd3a9c60a
commit
3ee9cc5ce6
@@ -435,11 +435,15 @@ $spreadsheet = $reader->load("sample.csv");
|
||||
|
||||
#### Setting CSV options
|
||||
|
||||
Often, CSV files are not really "comma separated", or use semicolon (;)
|
||||
Often, CSV files are not really "comma separated", or use semicolon (`;`)
|
||||
as a separator. You can instruct
|
||||
\PhpOffice\PhpSpreadsheet\Reader\Csv some options before reading a CSV
|
||||
file.
|
||||
|
||||
The separator will be auto-detected, so in most cases it should not be necessary
|
||||
to specify it. But in cases where auto-detection does not fit the use-case, then
|
||||
it can be set manually.
|
||||
|
||||
Note that \PhpOffice\PhpSpreadsheet\Reader\Csv by default assumes that
|
||||
the loaded CSV file is UTF-8 encoded. If you are reading CSV files that
|
||||
were created in Microsoft Office Excel the correct input encoding may
|
||||
|
||||
@@ -523,15 +523,17 @@ CSV | YES | HTML | NO
|
||||
|
||||
### Pipe or Tab Separated Value Files
|
||||
|
||||
The CSV loader defaults to loading a file where comma is used as the
|
||||
separator, but you can modify this to load tab- or pipe-separated value
|
||||
files using the `setDelimiter()` method.
|
||||
The CSV loader will attempt to auto-detect the separator used in the file. If it
|
||||
cannot auto-detect, it will default to the comma. If this does not fit your
|
||||
use-case, you can manually specify a separator by using the `setDelimiter()`
|
||||
method.
|
||||
|
||||
``` php
|
||||
$inputFileType = 'Csv';
|
||||
$inputFileName = './sampleData/example1.tsv';
|
||||
|
||||
/** Create a new Reader of the type defined in $inputFileType **/ $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||
/** Create a new Reader of the type defined in $inputFileType **/
|
||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||
/** Set the delimiter to a TAB character **/
|
||||
$reader->setDelimiter("\t");
|
||||
// $reader->setDelimiter('|');
|
||||
|
||||
Reference in New Issue
Block a user