Moodle PHP Documentation 5.1
Moodle 5.1dev (Build: 20250711) (9addea9f0ac)
PhpOffice\PhpSpreadsheet\Reader\Csv Class Reference
Inheritance diagram for PhpOffice\PhpSpreadsheet\Reader\Csv:
PhpOffice\PhpSpreadsheet\Reader\BaseReader PhpOffice\PhpSpreadsheet\Reader\IReader

Public Member Functions

 __construct ()
 Create a new CSV Reader instance.
 
 canRead (string $filename)
 Can the current IReader read the file?
 
 castFormattedNumberToNumeric (bool $castFormattedNumberToNumeric, bool $preserveNumericFormatting=false)
 
 getContiguous ()
 
 getDelimiter ()
 
 getEnclosure ()
 
 getEscapeCharacter (int $version=PHP_VERSION_ID)
 
 getFallbackEncoding ()
 
 getIgnoreRowsWithNoCells ()
 
 getIncludeCharts ()
 Read charts in workbook?
 
 getInputEncoding ()
 
 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.
 
 getPreserveNullString ()
 
 getReadDataOnly ()
 Read data only?
 
 getReadEmptyCells ()
 Read empty cells?
 
 getReadFilter ()
 Read filter.
 
 getSecurityScanner ()
 
 getSecurityScannerOrThrow ()
 
 getSheetIndex ()
 
 getValueBinder ()
 
 listWorksheetInfo (string $filename)
 Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns).
 
 listWorksheetNames (string $filename)
 Returns names of the worksheets from a file, possibly without parsing the whole file to a Spreadsheet object.
 
 load (string $filename, int $flags=0)
 Loads Spreadsheet from file.
 
 loadIntoExisting (string $filename, Spreadsheet $spreadsheet)
 Loads PhpSpreadsheet from file into PhpSpreadsheet instance.
 
 loadSpreadsheetFromString (string $contents)
 Loads Spreadsheet from string.
 
 setContiguous (bool $contiguous)
 
 setDelimiter (?string $delimiter)
 
 setEnclosure (string $enclosure)
 
 setEscapeCharacter (string $escapeCharacter, int $version=PHP_VERSION_ID)
 Php9 intends to drop support for this parameter in fgetcsv.
 
 setFallbackEncoding (string $fallbackEncoding)
 
 setIgnoreRowsWithNoCells (bool $ignoreRowsWithNoCells)
 
 setIncludeCharts (bool $includeCharts)
 Set read charts in workbook Set to true, to advise the Reader to include any charts that exist in the workbook.
 
 setInputEncoding (string $encoding)
 
 setLoadAllSheets ()
 Set all sheets to load Tells the Reader to load all worksheets from the workbook.
 
 setLoadSheetsOnly (string|array|null $sheetList)
 Set which sheets to load.
 
 setPreserveNullString (bool $value)
 
 setReadDataOnly (bool $readCellValuesOnly)
 Set read data only Set to true, to advise the Reader only to read data values for cells, and to ignore any formatting or structural information (like merges).
 
 setReadEmptyCells (bool $readEmptyCells)
 Set read empty cells Set to true (the default) to advise the Reader read data values for all cells, irrespective of value.
 
 setReadFilter (IReadFilter $readFilter)
 Set read filter.
 
 setSheetIndex (int $indexValue)
 
 setSheetNameIsFileName (bool $sheetNameIsFileName)
 
 setTestAutoDetect (bool $value)
 
 setValueBinder (?IValueBinder $valueBinder)
 

Static Public Member Functions

static affectedByPhp9 (string $filename, string $inputEncoding='UTF-8', ?string $delimiter=null, string $enclosure='"', string $escapeCharacter = '\\', int $version = PHP_VERSION_ID )
 
static getConstructorCallback ()
 
static guessEncoding (string $filename, string $dflt=self::DEFAULT_FALLBACK_ENCODING)
 
static guessEncodingBom (string $filename, ?string $convertString=null)
 
static setConstructorCallback (?callable $callback)
 Set a callback to change the defaults.
 

Public Attributes

const DEFAULT_FALLBACK_ENCODING = 'CP1252'
 
const DEFAULT_TEST_AUTODETECT = false
 Changed from true to false in release 4.0.0.
 
const GUESS_ENCODING = 'guess'
 
const IGNORE_EMPTY_CELLS = 4
 Flag used to ignore empty cells when reading.
 
const IGNORE_ROWS_WITH_NO_CELLS = 8
 Flag used to ignore rows without cells.
 
const LOAD_WITH_CHARTS = 1
 
const READ_DATA_ONLY = 2
 Flag used to read data only, not style or structure information.
 
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"
 
const UTF8_BOM = "\xEF\xBB\xBF"
 
const UTF8_BOM_LEN = 3
 

Protected Member Functions

 checkSeparator ()
 Identify any separator that is explicitly set in the file.
 
 inferSeparator ()
 Infer the separator if it isn't explicitly set in the file or specified by the user.
 
 loadSpreadsheetFromFile (string $filename)
 Loads Spreadsheet from file.
 
 openFile (string $filename)
 Open file for reading.
 
 processFlags (int $flags)
 
 skipBOM ()
 Move filepointer past any BOM marker.
 

Protected Attributes

bool $castFormattedNumberToNumeric = false
 
resource $fileHandle
 
bool $ignoreRowsWithNoCells = false
 Ignore rows with no cells?
 
bool $includeCharts = false
 Read charts that are defined in the workbook?
 
null string[] array $loadSheetsOnly = null
 Restrict which sheets should be loaded?
 
bool $preserveNumericFormatting = false
 
bool $readDataOnly = false
 
bool $readEmptyCells = true
 Read empty cells?
 
IReadFilter $readFilter
 IReadFilter instance.
 
XmlScanner $securityScanner = null
 
IValueBinder $valueBinder = null
 

Constructor & Destructor Documentation

◆ __construct()

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

Create a new CSV Reader instance.

Reimplemented from PhpOffice\PhpSpreadsheet\Reader\BaseReader.

Member Function Documentation

◆ canRead()

PhpOffice\PhpSpreadsheet\Reader\Csv::canRead ( string $filename)

Can the current IReader read the file?

Implements PhpOffice\PhpSpreadsheet\Reader\IReader.

◆ getIncludeCharts()

PhpOffice\PhpSpreadsheet\Reader\BaseReader::getIncludeCharts ( )
inherited

Read charts in workbook?

If this is true, then the Reader will include any charts that exist in the workbook. 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.

Implements PhpOffice\PhpSpreadsheet\Reader\IReader.

◆ getLoadSheetsOnly()

PhpOffice\PhpSpreadsheet\Reader\BaseReader::getLoadSheetsOnly ( )
inherited

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.

Implements PhpOffice\PhpSpreadsheet\Reader\IReader.

◆ getReadDataOnly()

PhpOffice\PhpSpreadsheet\Reader\BaseReader::getReadDataOnly ( )
inherited

Read data only?

If this is true, then the Reader will only read data values for cells, it will not read any formatting or structural information (like merges). If false (the default) it will read data and formatting.

Implements PhpOffice\PhpSpreadsheet\Reader\IReader.

◆ getReadEmptyCells()

PhpOffice\PhpSpreadsheet\Reader\BaseReader::getReadEmptyCells ( )
inherited

Read empty cells?

If this is true (the default), then the Reader will read data values for all cells, irrespective of value. If false it will not read data for cells containing a null value or an empty string.

Implements PhpOffice\PhpSpreadsheet\Reader\IReader.

◆ getReadFilter()

PhpOffice\PhpSpreadsheet\Reader\BaseReader::getReadFilter ( )
inherited

Read filter.

Implements PhpOffice\PhpSpreadsheet\Reader\IReader.

◆ listWorksheetInfo()

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

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

Reimplemented from PhpOffice\PhpSpreadsheet\Reader\BaseReader.

◆ listWorksheetNames()

PhpOffice\PhpSpreadsheet\Reader\BaseReader::listWorksheetNames ( string $filename)
inherited

Returns names of the worksheets from a file, possibly without parsing the whole file to a Spreadsheet object.

Readers will often have a more efficient method with which they can override this method.

Reimplemented in PhpOffice\PhpSpreadsheet\Reader\Gnumeric, PhpOffice\PhpSpreadsheet\Reader\Ods, PhpOffice\PhpSpreadsheet\Reader\Xlsx, and PhpOffice\PhpSpreadsheet\Reader\Xml.

◆ load()

PhpOffice\PhpSpreadsheet\Reader\BaseReader::load ( string $filename,
int $flags = 0 )
inherited

Loads Spreadsheet from file.

Parameters
int$flagsthe 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

Implements PhpOffice\PhpSpreadsheet\Reader\IReader.

◆ loadSpreadsheetFromFile()

PhpOffice\PhpSpreadsheet\Reader\Csv::loadSpreadsheetFromFile ( string $filename)
protected

Loads Spreadsheet from file.

Reimplemented from PhpOffice\PhpSpreadsheet\Reader\BaseReader.

◆ 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.

◆ setEscapeCharacter()

PhpOffice\PhpSpreadsheet\Reader\Csv::setEscapeCharacter ( string $escapeCharacter,
int $version = PHP_VERSION_ID )

Php9 intends to drop support for this parameter in fgetcsv.

Not yet ready to mark deprecated in order to give users a migration path.

◆ setIncludeCharts()

PhpOffice\PhpSpreadsheet\Reader\BaseReader::setIncludeCharts ( bool $includeCharts)
inherited

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

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.

Return values
$this

Implements PhpOffice\PhpSpreadsheet\Reader\IReader.

◆ setLoadAllSheets()

PhpOffice\PhpSpreadsheet\Reader\BaseReader::setLoadAllSheets ( )
inherited

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

Return values
$this

Implements PhpOffice\PhpSpreadsheet\Reader\IReader.

◆ setLoadSheetsOnly()

PhpOffice\PhpSpreadsheet\Reader\BaseReader::setLoadSheetsOnly ( string|array|null $value)
inherited

Set which sheets to load.

Parameters
null | array | string$valueThis should be either an array of worksheet names to be loaded, or a string containing a single worksheet name. If NULL, then it tells the Reader to read all worksheets in the workbook
Return values
$this

Implements PhpOffice\PhpSpreadsheet\Reader\IReader.

◆ setReadDataOnly()

PhpOffice\PhpSpreadsheet\Reader\BaseReader::setReadDataOnly ( bool $readDataOnly)
inherited

Set read data only Set to true, to advise the Reader only to read data values for cells, and to ignore any formatting or structural information (like merges).

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

Return values
$this

Implements PhpOffice\PhpSpreadsheet\Reader\IReader.

◆ setReadEmptyCells()

PhpOffice\PhpSpreadsheet\Reader\BaseReader::setReadEmptyCells ( bool $readEmptyCells)
inherited

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

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

Return values
$this

Implements PhpOffice\PhpSpreadsheet\Reader\IReader.

◆ setReadFilter()

PhpOffice\PhpSpreadsheet\Reader\BaseReader::setReadFilter ( IReadFilter $readFilter)
inherited

Set read filter.

Return values
$this

Implements PhpOffice\PhpSpreadsheet\Reader\IReader.

Member Data Documentation

◆ $ignoreRowsWithNoCells

bool PhpOffice\PhpSpreadsheet\Reader\BaseReader::$ignoreRowsWithNoCells = false
protectedinherited

Ignore rows with no cells?

Identifies whether the Reader should ignore rows with no cells. Currently implemented only for Xlsx.

◆ $includeCharts

bool PhpOffice\PhpSpreadsheet\Reader\BaseReader::$includeCharts = false
protectedinherited

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 string [] array PhpOffice\PhpSpreadsheet\Reader\BaseReader::$loadSheetsOnly = null
protectedinherited

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. This property is ignored for Csv, Html, and Slk.

◆ $readEmptyCells

bool PhpOffice\PhpSpreadsheet\Reader\BaseReader::$readEmptyCells = true
protectedinherited

Read empty cells?

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

◆ IGNORE_EMPTY_CELLS

const PhpOffice\PhpSpreadsheet\Reader\IReader::IGNORE_EMPTY_CELLS = 4
inherited

Flag used to ignore empty cells when reading.

The ignored cells will not be instantiated.

◆ IGNORE_ROWS_WITH_NO_CELLS

const PhpOffice\PhpSpreadsheet\Reader\IReader::IGNORE_ROWS_WITH_NO_CELLS = 8
inherited

Flag used to ignore rows without cells.

This flag is supported only for some formats. This can heavily improve performance for some files.


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