IOFactory
in package
Factory to create readers and writers easily.
It is not required to use this class, but it should make it easier to read and write files. Especially for reading files with an unknown format.
Table of Contents
Constants
- READER_CSV = 'Csv'
- READER_GNUMERIC = 'Gnumeric'
- READER_HTML = 'Html'
- READER_ODS = 'Ods'
- READER_SLK = 'Slk'
- READER_SYLK = 'Slk'
- READER_XLS = 'Xls'
- READER_XLSX = 'Xlsx'
- READER_XML = 'Xml'
- WRITER_CSV = 'Csv'
- WRITER_HTML = 'Html'
- WRITER_ODS = 'Ods'
- WRITER_XLS = 'Xls'
- WRITER_XLSX = 'Xlsx'
Properties
Methods
- createReader() : IReader
- Create IReader.
- createReaderForFile() : IReader
- Create Reader\IReader for file using automatic IReader resolution.
- createWriter() : IWriter
- Create Writer\IWriter.
- identify() : string
- Identify file type using automatic IReader resolution.
- load() : Spreadsheet
- Loads Spreadsheet from file using automatic Reader\IReader resolution.
- registerReader() : void
- Register a reader with its type and class name.
- registerWriter() : void
- Register a writer with its type and class name.
- getReaderTypeFromExtension() : string|null
- Guess a reader type from the file extension, if any.
Constants
READER_CSV
public
mixed
READER_CSV
= 'Csv'
READER_GNUMERIC
public
mixed
READER_GNUMERIC
= 'Gnumeric'
READER_HTML
public
mixed
READER_HTML
= 'Html'
READER_ODS
public
mixed
READER_ODS
= 'Ods'
READER_SLK
public
mixed
READER_SLK
= 'Slk'
READER_SYLK
public
mixed
READER_SYLK
= 'Slk'
READER_XLS
public
mixed
READER_XLS
= 'Xls'
READER_XLSX
public
mixed
READER_XLSX
= 'Xlsx'
READER_XML
public
mixed
READER_XML
= 'Xml'
WRITER_CSV
public
mixed
WRITER_CSV
= 'Csv'
WRITER_HTML
public
mixed
WRITER_HTML
= 'Html'
WRITER_ODS
public
mixed
WRITER_ODS
= 'Ods'
WRITER_XLS
public
mixed
WRITER_XLS
= 'Xls'
WRITER_XLSX
public
mixed
WRITER_XLSX
= 'Xlsx'
Properties
$readers
private
static array<string, IReader>>
$readers
= [self::READER_XLSX => \PhpOffice\PhpSpreadsheet\Reader\Xlsx::class, self::READER_XLS => \PhpOffice\PhpSpreadsheet\Reader\Xls::class, self::READER_XML => \PhpOffice\PhpSpreadsheet\Reader\Xml::class, self::READER_ODS => \PhpOffice\PhpSpreadsheet\Reader\Ods::class, self::READER_SLK => \PhpOffice\PhpSpreadsheet\Reader\Slk::class, self::READER_GNUMERIC => \PhpOffice\PhpSpreadsheet\Reader\Gnumeric::class, self::READER_HTML => \PhpOffice\PhpSpreadsheet\Reader\Html::class, self::READER_CSV => \PhpOffice\PhpSpreadsheet\Reader\Csv::class]
$writers
private
static array<string, IWriter>>
$writers
= [self::WRITER_XLS => \PhpOffice\PhpSpreadsheet\Writer\Xls::class, self::WRITER_XLSX => \PhpOffice\PhpSpreadsheet\Writer\Xlsx::class, self::WRITER_ODS => \PhpOffice\PhpSpreadsheet\Writer\Ods::class, self::WRITER_CSV => \PhpOffice\PhpSpreadsheet\Writer\Csv::class, self::WRITER_HTML => \PhpOffice\PhpSpreadsheet\Writer\Html::class, 'Tcpdf' => \PhpOffice\PhpSpreadsheet\Writer\Pdf\Tcpdf::class, 'Dompdf' => \PhpOffice\PhpSpreadsheet\Writer\Pdf\Dompdf::class, 'Mpdf' => \PhpOffice\PhpSpreadsheet\Writer\Pdf\Mpdf::class]
Methods
createReader()
Create IReader.
public
static createReader(string $readerType) : IReader
Parameters
- $readerType : string
Return values
IReadercreateReaderForFile()
Create Reader\IReader for file using automatic IReader resolution.
public
static createReaderForFile(string $filename[, array<string|int, string> $readers = null ]) : IReader
Parameters
- $filename : string
- $readers : array<string|int, string> = null
-
An array of Readers to use to identify the file type. By default, load() will try all possible Readers until it finds a match; but this allows you to pass in a list of Readers so it will only try the subset that you specify here. Values in this list can be any of the constant values defined in the set IOFactory::READER_*.
Return values
IReadercreateWriter()
Create Writer\IWriter.
public
static createWriter(Spreadsheet $spreadsheet, string $writerType) : IWriter
Parameters
- $spreadsheet : Spreadsheet
- $writerType : string
Return values
IWriteridentify()
Identify file type using automatic IReader resolution.
public
static identify(string $filename[, array<string|int, mixed>|null $readers = null ]) : string
Parameters
- $filename : string
- $readers : array<string|int, mixed>|null = null
Return values
stringload()
Loads Spreadsheet from file using automatic Reader\IReader resolution.
public
static load(string $filename[, int $flags = 0 ][, array<string|int, string> $readers = null ]) : Spreadsheet
Parameters
- $filename : string
-
The name of the spreadsheet file
- $flags : int = 0
-
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. IReader::READ_DATA_ONLY - Read cell values only, not formatting or merge structure. IReader::IGNORE_EMPTY_CELLS - Don't load empty cells into the model.
- $readers : array<string|int, string> = null
-
An array of Readers to use to identify the file type. By default, load() will try all possible Readers until it finds a match; but this allows you to pass in a list of Readers so it will only try the subset that you specify here. Values in this list can be any of the constant values defined in the set IOFactory::READER_*.
Return values
SpreadsheetregisterReader()
Register a reader with its type and class name.
public
static registerReader(string $readerType, string $readerClass) : void
Parameters
- $readerType : string
- $readerClass : string
registerWriter()
Register a writer with its type and class name.
public
static registerWriter(string $writerType, IWriter> $writerClass) : void
Parameters
- $writerType : string
- $writerClass : IWriter>
getReaderTypeFromExtension()
Guess a reader type from the file extension, if any.
private
static getReaderTypeFromExtension(string $filename) : string|null
Parameters
- $filename : string