Documentation

IOFactory

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

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'
$readers  : mixed
$writers  : mixed
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_GNUMERIC

public mixed READER_GNUMERIC = 'Gnumeric'

READER_HTML

public mixed READER_HTML = 'Html'

READER_SYLK

public mixed READER_SYLK = 'Slk'

READER_XLSX

public mixed READER_XLSX = 'Xlsx'

WRITER_HTML

public mixed WRITER_HTML = 'Html'

WRITER_XLSX

public mixed WRITER_XLSX = 'Xlsx'

Properties

$readers

private static mixed $readers = [self::READER_XLSX => PhpOfficePhpSpreadsheetReaderXlsx::class, self::READER_XLS => PhpOfficePhpSpreadsheetReaderXls::class, self::READER_XML => PhpOfficePhpSpreadsheetReaderXml::class, self::READER_ODS => PhpOfficePhpSpreadsheetReaderOds::class, self::READER_SLK => PhpOfficePhpSpreadsheetReaderSlk::class, self::READER_GNUMERIC => PhpOfficePhpSpreadsheetReaderGnumeric::class, self::READER_HTML => PhpOfficePhpSpreadsheetReaderHtml::class, self::READER_CSV => PhpOfficePhpSpreadsheetReaderCsv::class]

$writers

private static mixed $writers = [self::WRITER_XLS => PhpOfficePhpSpreadsheetWriterXls::class, self::WRITER_XLSX => PhpOfficePhpSpreadsheetWriterXlsx::class, self::WRITER_ODS => PhpOfficePhpSpreadsheetWriterOds::class, self::WRITER_CSV => PhpOfficePhpSpreadsheetWriterCsv::class, self::WRITER_HTML => PhpOfficePhpSpreadsheetWriterHtml::class, 'Tcpdf' => PhpOfficePhpSpreadsheetWriterPdfTcpdf::class, 'Dompdf' => PhpOfficePhpSpreadsheetWriterPdfDompdf::class, 'Mpdf' => PhpOfficePhpSpreadsheetWriterPdfMpdf::class]

Methods

createReader()

Create IReader.

public static createReader(string $readerType) : IReader
Parameters
$readerType : string
Return values
IReader

createReaderForFile()

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
IReader

identify()

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
string

load()

Loads Spreadsheet from file using automatic Reader\IReader resolution.

public static load(string $filename, int $flags[, array<string|int, string> $readers = null ]) : Spreadsheet
Parameters
$filename : string

The name of the spreadsheet file

$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

$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
Spreadsheet

registerReader()

Register a reader with its type and class name.

public static registerReader(string $readerType, string $readerClass) : void
Parameters
$readerType : string
$readerClass : string
Return values
void

registerWriter()

Register a writer with its type and class name.

public static registerWriter(string $writerType, string $writerClass) : void
Parameters
$writerType : string
$writerClass : string
Return values
void

getReaderTypeFromExtension()

Guess a reader type from the file extension, if any.

private static getReaderTypeFromExtension(string $filename) : string|null
Parameters
$filename : string
Return values
string|null

Search results