Documentation

Csv extends BaseReader

Table of Contents

DEFAULT_FALLBACK_ENCODING  = 'CP1252'
GUESS_ENCODING  = 'guess'
UTF16BE_BOM  = "��"
UTF16BE_BOM_LEN  = 2
UTF16BE_LF  = " "
UTF16LE_BOM  = "��"
UTF16LE_BOM_LEN  = 2
UTF16LE_LF  = " "
UTF32BE_BOM  = "��"
UTF32BE_BOM_LEN  = 4
UTF32BE_LF  = " "
UTF32LE_BOM  = "��"
UTF32LE_BOM_LEN  = 4
UTF32LE_LF  = " "
UTF8_BOM  = ""
UTF8_BOM_LEN  = 3
$castFormattedNumberToNumeric  : bool
$fileHandle  : mixed
$includeCharts  : bool
Read charts that are defined in the workbook? Identifies whether the Reader should read the definitions for any charts that exist in the workbook;.
$loadSheetsOnly  : null|array<string|int, string>
Restrict which sheets should be loaded? This property holds an array of worksheet names to be loaded. If null, then all worksheets will be loaded.
$preserveNumericFormatting  : bool
$readDataOnly  : bool
Read data only? Identifies whether the Reader should only read data values for cells, and ignore any formatting information; or whether it should read both data and formatting.
$readEmptyCells  : bool
Read empty cells? Identifies whether the Reader should read data values for cells all cells, or should ignore cells containing null value or empty string.
$readFilter  : IReadFilter
IReadFilter instance.
$securityScanner  : XmlScanner
$constructorCallback  : callable|null
Callback for setting defaults in construction.
$contiguous  : bool
Load rows contiguously.
$delimiter  : string|null
Delimiter.
$enclosure  : string
Enclosure.
$escapeCharacter  : string
The character that can escape the enclosure.
$fallbackEncoding  : string
Fallback encoding if guess strikes out.
$inputEncoding  : string
Input encoding.
$preserveNullString  : bool
$sheetIndex  : int
Sheet index to read.
$testAutodetect  : bool
Attempt autodetect line endings (deprecated after PHP8.1)?
__construct()  : mixed
Create a new CSV Reader instance.
canRead()  : bool
Can the current IReader read the file?
castFormattedNumberToNumeric()  : void
getConstructorCallback()  : callable|null
getContiguous()  : bool
getDelimiter()  : string|null
getEnclosure()  : string
getEscapeCharacter()  : string
getFallbackEncoding()  : string
getIncludeCharts()  : bool
Read charts in workbook? If this is true, then the Reader will include any charts that exist in the workbook.
getInputEncoding()  : string
getLoadSheetsOnly()  : mixed
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.
getPreserveNullString()  : bool
getReadDataOnly()  : bool
Read data only? If this is true, then the Reader will only read data values for cells, it will not read any formatting information.
getReadEmptyCells()  : bool
Read empty cells? If this is true (the default), then the Reader will read data values for all cells, irrespective of value.
getReadFilter()  : IReadFilter
Read filter.
getSecurityScanner()  : mixed
getSheetIndex()  : int
guessEncoding()  : string
listWorksheetInfo()  : array<string|int, mixed>
Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns).
load()  : Spreadsheet
Loads Spreadsheet from file.
loadIntoExisting()  : Spreadsheet
Loads PhpSpreadsheet from file into PhpSpreadsheet instance.
loadSpreadsheetFromString()  : Spreadsheet
Loads Spreadsheet from string.
setConstructorCallback()  : void
Set a callback to change the defaults.
setContiguous()  : self
setDelimiter()  : self
setEnclosure()  : self
setEscapeCharacter()  : self
setFallbackEncoding()  : self
setIncludeCharts()  : IReader
Set read charts in workbook Set to true, to advise the Reader to include any charts that exist in the workbook.
setInputEncoding()  : self
setLoadAllSheets()  : IReader
Set all sheets to load Tells the Reader to load all worksheets from the workbook.
setLoadSheetsOnly()  : IReader
Set which sheets to load.
setPreserveNullString()  : self
setReadDataOnly()  : IReader
Set read data only Set to true, to advise the Reader only to read data values for cells, and to ignore any formatting information.
setReadEmptyCells()  : IReader
Set read empty cells Set to true (the default) to advise the Reader read data values for all cells, irrespective of value.
setReadFilter()  : IReader
Set read filter.
setSheetIndex()  : self
setTestAutoDetect()  : self
checkSeparator()  : void
Identify any separator that is explicitly set in the file.
inferSeparator()  : void
Infer the separator if it isn't explicitly set in the file or specified by the user.
loadSpreadsheetFromFile()  : Spreadsheet
Loads Spreadsheet from file.
openFile()  : void
Open file for reading.
processFlags()  : void
skipBOM()  : void
Move filepointer past any BOM marker.
convertBoolean()  : void
Convert string true/false to boolean, and null to null-string.
convertFormattedNumber()  : string
Convert numeric strings to int or float values.
guessEncodingBom()  : string
guessEncodingNoBom()  : string
guessEncodingTestBom()  : void
guessEncodingTestNoBom()  : void
loadStringOrFile()  : Spreadsheet
Loads PhpSpreadsheet from file into PhpSpreadsheet instance.
openDataUri()  : void
Open data uri for reading.
openFileOrMemory()  : void
setAutoDetect()  : string|null

Constants

DEFAULT_FALLBACK_ENCODING

public mixed DEFAULT_FALLBACK_ENCODING = 'CP1252'

GUESS_ENCODING

public mixed GUESS_ENCODING = 'guess'

UTF16BE_BOM

public mixed UTF16BE_BOM = "��"

UTF16BE_BOM_LEN

public mixed UTF16BE_BOM_LEN = 2

UTF16BE_LF

public mixed UTF16BE_LF = " "

UTF16LE_BOM

public mixed UTF16LE_BOM = "��"

UTF16LE_BOM_LEN

public mixed UTF16LE_BOM_LEN = 2

UTF16LE_LF

public mixed UTF16LE_LF = " "

UTF32BE_BOM

public mixed UTF32BE_BOM = "��"

UTF32BE_BOM_LEN

public mixed UTF32BE_BOM_LEN = 4

UTF32BE_LF

public mixed UTF32BE_LF = " "

UTF32LE_BOM

public mixed UTF32LE_BOM = "��"

UTF32LE_BOM_LEN

public mixed UTF32LE_BOM_LEN = 4

UTF32LE_LF

public mixed UTF32LE_LF = " "

UTF8_BOM

public mixed UTF8_BOM = ""

UTF8_BOM_LEN

public mixed UTF8_BOM_LEN = 3

Properties

$castFormattedNumberToNumeric

protected bool $castFormattedNumberToNumeric = false

$includeCharts

Read charts that are defined in the workbook? Identifies whether the Reader should read the definitions for any charts that exist in the workbook;.

protected bool $includeCharts = false

$loadSheetsOnly

Restrict which sheets should be loaded? This property holds an array of worksheet names to be loaded. If null, then all worksheets will be loaded.

protected null|array<string|int, string> $loadSheetsOnly

$preserveNumericFormatting

protected bool $preserveNumericFormatting = false

$readDataOnly

Read data only? Identifies whether the Reader should only read data values for cells, and ignore any formatting information; or whether it should read both data and formatting.

protected bool $readDataOnly = false

$readEmptyCells

Read empty cells? Identifies whether the Reader should read data values for cells all cells, or should ignore cells containing null value or empty string.

protected bool $readEmptyCells = true

$constructorCallback

Callback for setting defaults in construction.

private static callable|null $constructorCallback

$contiguous

Load rows contiguously.

private bool $contiguous = false

$delimiter

Delimiter.

private string|null $delimiter

$enclosure

Enclosure.

private string $enclosure = '"'

$escapeCharacter

The character that can escape the enclosure.

private string $escapeCharacter = '\'

$fallbackEncoding

Fallback encoding if guess strikes out.

private string $fallbackEncoding = self::DEFAULT_FALLBACK_ENCODING

$inputEncoding

Input encoding.

private string $inputEncoding = 'UTF-8'

$preserveNullString

private bool $preserveNullString = false

$sheetIndex

Sheet index to read.

private int $sheetIndex = 0

$testAutodetect

Attempt autodetect line endings (deprecated after PHP8.1)?

private bool $testAutodetect = true

Methods

__construct()

Create a new CSV Reader instance.

public __construct() : mixed
Return values
mixed

canRead()

Can the current IReader read the file?

public canRead(string $filename) : bool
Parameters
$filename : string
Return values
bool

castFormattedNumberToNumeric()

public castFormattedNumberToNumeric(bool $castFormattedNumberToNumeric[, bool $preserveNumericFormatting = false ]) : void
Parameters
$castFormattedNumberToNumeric : bool
$preserveNumericFormatting : bool = false
Return values
void

getConstructorCallback()

public static getConstructorCallback() : callable|null
Return values
callable|null

getContiguous()

public getContiguous() : bool
Return values
bool

getDelimiter()

public getDelimiter() : string|null
Return values
string|null

getEnclosure()

public getEnclosure() : string
Return values
string

getEscapeCharacter()

public getEscapeCharacter() : string
Return values
string

getFallbackEncoding()

public getFallbackEncoding() : string
Return values
string

getIncludeCharts()

Read charts in workbook? If this is true, then the Reader will include any charts that exist in the workbook.

public getIncludeCharts() : bool

Note that a ReadDataOnly value of false overrides, and charts won't be read regardless of the IncludeCharts value. If false (the default) it will ignore any charts defined in the workbook file.

Return values
bool

getInputEncoding()

public getInputEncoding() : string
Return values
string

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.

public getLoadSheetsOnly() : mixed
Return values
mixed

getPreserveNullString()

public getPreserveNullString() : bool
Return values
bool

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.

public getReadDataOnly() : bool

If false (the default) it will read data and formatting.

Return values
bool

getReadEmptyCells()

Read empty cells? If this is true (the default), then the Reader will read data values for all cells, irrespective of value.

public getReadEmptyCells() : bool

If false it will not read data for cells containing a null value or an empty string.

Return values
bool

getSecurityScanner()

public getSecurityScanner() : mixed
Return values
mixed

getSheetIndex()

public getSheetIndex() : int
Return values
int

guessEncoding()

public static guessEncoding(string $filename[, string $dflt = self::DEFAULT_FALLBACK_ENCODING ]) : string
Parameters
$filename : string
$dflt : string = self::DEFAULT_FALLBACK_ENCODING
Return values
string

listWorksheetInfo()

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

public listWorksheetInfo(string $filename) : array<string|int, mixed>
Parameters
$filename : string
Return values
array<string|int, mixed>

load()

Loads Spreadsheet from file.

public load(string $filename, int $flags) : Spreadsheet
Parameters
$filename : string
$flags : int

the optional second parameter flags may be used to identify specific elements that should be loaded, but which won't be loaded by default, using these values: IReader::LOAD_WITH_CHARTS - Include any charts that are defined in the loaded file

Return values
Spreadsheet

loadIntoExisting()

Loads PhpSpreadsheet from file into PhpSpreadsheet instance.

public loadIntoExisting(string $filename, Spreadsheet $spreadsheet) : Spreadsheet
Parameters
$filename : string
$spreadsheet : Spreadsheet
Return values
Spreadsheet

loadSpreadsheetFromString()

Loads Spreadsheet from string.

public loadSpreadsheetFromString(string $contents) : Spreadsheet
Parameters
$contents : string
Return values
Spreadsheet

setConstructorCallback()

Set a callback to change the defaults.

public static setConstructorCallback(callable|null $callback) : void

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

Parameters
$callback : callable|null
Return values
void

setContiguous()

public setContiguous(bool $contiguous) : self
Parameters
$contiguous : bool
Return values
self

setDelimiter()

public setDelimiter(string|null $delimiter) : self
Parameters
$delimiter : string|null
Return values
self

setEnclosure()

public setEnclosure(string $enclosure) : self
Parameters
$enclosure : string
Return values
self

setEscapeCharacter()

public setEscapeCharacter(string $escapeCharacter) : self
Parameters
$escapeCharacter : string
Return values
self

setFallbackEncoding()

public setFallbackEncoding(string $fallbackEncoding) : self
Parameters
$fallbackEncoding : string
Return values
self

setIncludeCharts()

Set read charts in workbook Set to true, to advise the Reader to include any charts that exist in the workbook.

public setIncludeCharts(mixed $includeCharts) : IReader

Note that a ReadDataOnly value of false overrides, and charts won't be read regardless of the IncludeCharts value. Set to false (the default) to discard charts.

Parameters
$includeCharts : mixed
Return values
IReader

setInputEncoding()

public setInputEncoding(string $encoding) : self
Parameters
$encoding : string
Return values
self

setLoadAllSheets()

Set all sheets to load Tells the Reader to load all worksheets from the workbook.

public setLoadAllSheets() : IReader
Return values
IReader

setLoadSheetsOnly()

Set which sheets to load.

public setLoadSheetsOnly(mixed $sheetList) : IReader
Parameters
$sheetList : mixed
Return values
IReader

setPreserveNullString()

public setPreserveNullString(bool $value) : self
Parameters
$value : bool
Return values
self

setReadDataOnly()

Set read data only Set to true, to advise the Reader only to read data values for cells, and to ignore any formatting information.

public setReadDataOnly(mixed $readCellValuesOnly) : IReader

Set to false (the default) to advise the Reader to read both data and formatting for cells.

Parameters
$readCellValuesOnly : mixed
Return values
IReader

setReadEmptyCells()

Set read empty cells Set to true (the default) to advise the Reader read data values for all cells, irrespective of value.

public setReadEmptyCells(mixed $readEmptyCells) : IReader

Set to false to advise the Reader to ignore cells containing a null value or an empty string.

Parameters
$readEmptyCells : mixed
Return values
IReader

setSheetIndex()

public setSheetIndex(int $indexValue) : self
Parameters
$indexValue : int
Return values
self

setTestAutoDetect()

public setTestAutoDetect(bool $value) : self
Parameters
$value : bool
Return values
self

checkSeparator()

Identify any separator that is explicitly set in the file.

protected checkSeparator() : void
Return values
void

inferSeparator()

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

protected inferSeparator() : void
Return values
void

loadSpreadsheetFromFile()

Loads Spreadsheet from file.

protected loadSpreadsheetFromFile(string $filename) : Spreadsheet
Parameters
$filename : string
Return values
Spreadsheet

openFile()

Open file for reading.

protected openFile(string $filename) : void
Parameters
$filename : string
Return values
void

processFlags()

protected processFlags(int $flags) : void
Parameters
$flags : int
Return values
void

skipBOM()

Move filepointer past any BOM marker.

protected skipBOM() : void
Return values
void

convertBoolean()

Convert string true/false to boolean, and null to null-string.

private convertBoolean(mixed &$rowDatum, bool $preserveBooleanString) : void
Parameters
$rowDatum : mixed
$preserveBooleanString : bool
Return values
void

convertFormattedNumber()

Convert numeric strings to int or float values.

private convertFormattedNumber(mixed &$rowDatum) : string
Parameters
$rowDatum : mixed
Return values
string

guessEncodingBom()

private static guessEncodingBom(string $filename) : string
Parameters
$filename : string
Return values
string

guessEncodingNoBom()

private static guessEncodingNoBom(string $filename) : string
Parameters
$filename : string
Return values
string

guessEncodingTestBom()

private static guessEncodingTestBom(string &$encoding, string $first4, string $compare, string $setEncoding) : void
Parameters
$encoding : string
$first4 : string
$compare : string
$setEncoding : string
Return values
void

guessEncodingTestNoBom()

private static guessEncodingTestNoBom(string &$encoding, string &$contents, string $compare, string $setEncoding) : void
Parameters
$encoding : string
$contents : string
$compare : string
$setEncoding : string
Return values
void

loadStringOrFile()

Loads PhpSpreadsheet from file into PhpSpreadsheet instance.

private loadStringOrFile(string $filename, Spreadsheet $spreadsheet, bool $dataUri) : Spreadsheet
Parameters
$filename : string
$spreadsheet : Spreadsheet
$dataUri : bool
Return values
Spreadsheet

openDataUri()

Open data uri for reading.

private openDataUri(string $filename) : void
Parameters
$filename : string
Return values
void

openFileOrMemory()

private openFileOrMemory(string $filename) : void
Parameters
$filename : string
Return values
void

setAutoDetect()

private setAutoDetect(string|null $value) : string|null
Parameters
$value : string|null
Return values
string|null

Search results