Class \avadim\FastExcelReader\Excel
On this page
- __construct()
- Parameters
- colLetter()
- Parameters
- colNum()
- Parameters
- createReader()
- Parameters
- createSheet()
- Parameters
- isXls()
- Parameters
- isXlsx()
- Parameters
- open()
- Parameters
- openCsv()
- Parameters
- openCsvBook()
- Parameters
- openCsvReader()
- Parameters
- openStream()
- Parameters
- openString()
- Parameters
- openXls()
- Parameters
- openXlsx()
- Parameters
- setTempDir()
- Parameters
- validate()
- Parameters
- countExtraImages()
- Parameters
- countImages()
- Parameters
- countSheets()
- Parameters
- dateFormatter()
- Parameters
- formatDate()
- Parameters
- from()
- Parameters
- getCompleteStyleByIdx()
- Parameters
- getDateFormat()
- Parameters
- getDateFormatPattern()
- Parameters
- getDateFormatter()
- Parameters
- getDefinedNames()
- Parameters
- getFirstSheet()
- Parameters
- getFormatPattern()
- Parameters
- getImageList()
- Parameters
- getProperties()
- Parameters
- getSheet()
- Parameters
- getSheetById()
- Parameters
- getSheetNames()
- Parameters
- hasDrawings()
- Parameters
- hasExtraImages()
- Parameters
- hasImages()
- Parameters
- hiddenSheets()
- Parameters
- innerFileList()
- Parameters
- mediaImageFiles()
- Parameters
- metadataImage()
- Parameters
- readCallback()
- Parameters
- readCells()
- Parameters
- readCellStyles()
- Parameters
- readCellsWithStyles()
- Parameters
- readColumns()
- Parameters
- readColumnsWithStyles()
- Parameters
- readRows()
- Parameters
- readRowsWithStyles()
- Parameters
- readStyles()
- Parameters
- selectFirstSheet()
- Parameters
- selectSheet()
- Parameters
- selectSheetById()
- Parameters
- setDateFormat()
- Parameters
- setReadArea()
- Parameters
- sharedString()
- Parameters
- sheet()
- Parameters
- sheetExists()
- Parameters
- sheets()
- Parameters
- stat()
- Parameters
- styleByIdx()
- Parameters
- timestamp()
- Parameters
- useLocaleFormats()
- Parameters
- visibleSheets()
- Parameters
- __construct() – Excel constructor
- colLetter() – Convert column number to letter
- colNum() – Converts an alphabetic column index to a numeric
- createReader() – Create XML reader object
- createSheet() – Create sheet object
- isXls() – TRUE if the file starts with the OLE2 compound file signature
- isXlsx() – TRUE if the file starts with the ZIP local file header signature
- open() – Open a spreadsheet, choosing the reader by the file signature
- openCsv() – Open CSV as the low-level CsvReader (4.x contract)
- openCsvBook() – Open CSV as a single-sheet workbook without format detection
- openCsvReader() – Open the low-level CSV reader without a workbook wrapper
- openStream() – Open a spreadsheet from an open stream resource
- openString() – Open a spreadsheet held in a string, choosing the reader by its signature
- openXls() – Open an XLS (Excel 97-2003, BIFF8) file
- openXlsx() – Open an XLSX workbook without format detection
- setTempDir() – Set directory for temporary files
- validate() – Check required XLSX package parts and XML well-formedness
- countExtraImages() – Count "extra" images (images that are in the media folder but not in the drawings)
- countImages() – Returns the total count of images in the workbook
- countSheets() – Returns the number of sheets in the workbook
- dateFormatter() – Set custom date formatter
- formatDate() – Format date value
- from() – Set top left of read area
- getCompleteStyleByIdx() – Get complete style by style index
- getDateFormat() – Get current date format
- getDateFormatPattern() – Get PHP date format pattern by style index
- getDateFormatter() – Get date formatter
- getDefinedNames() – Get defined names of workbook
- getFirstSheet() – Returns the first sheet as default
- getFormatPattern() – Get format pattern by style index
- getImageList() – Get the list of images from the workbook
- getProperties() – Get the document properties of the workbook
- getSheet() – Get sheet object by name and optionally set read area and options
- getSheetById() – Returns a sheet by ID
- getSheetNames() – Get names array of all sheets
- hasDrawings() – Returns TRUE if the workbook contains an any draw objects (not images only)
- hasExtraImages() – Returns TRUE if there are any "extra" images
- hasImages() – Returns TRUE if any sheet contains an image object
- hiddenSheets() – Array of hidden sheets only
- innerFileList() – Get list of inner files in XLSX
- mediaImageFiles() – Get list of media image files in the workbook
- metadataImage() – Get image file name from metadata by index
- readCallback() – Reads cell values and passes them to a callback function
- readCells() – Returns the values of all cells as array
- readCellStyles() – Returns the styles of all cells as array
- readCellsWithStyles() – Returns the values and styles of all cells as array
- readColumns() – Returns cell values as a two-dimensional array from default sheet [col][row]
- readColumnsWithStyles() – Returns cell values and styles as a two-dimensional array from default sheet [col][row]
- readRows() – Returns cell values as a two-dimensional array from default sheet [row][col]
- readRowsWithStyles() – Returns cell values and styles as a two-dimensional array from default sheet [row][col]
- readStyles() – Read all workbook styles
- selectFirstSheet() – Selects the first sheet as default
- selectSheet() – Selects default sheet by name
- selectSheetById() – Selects default sheet by ID
- setDateFormat() – Set date format for reading
- setReadArea() – Set top left and right bottom of read area
- sharedString() – Get string by index
- sheet() – Get current or specified sheet
- sheetExists() – Returns TRUE if a sheet with the given name exists
- sheets() – Array of all sheets
- stat() – Returns statistics of the workbook: per-sheet breakdown and totals
- styleByIdx() – Get style array by style index
- timestamp() – Convert date to timestamp
- useLocaleFormats() – Opt in to locale-dependent patterns for the built-in date codes (numFmtId 14-22).
- visibleSheets() – Array of visible sheets only
__construct()
public function __construct(?string $file = null, ?string $tempDir = '')
Excel constructor
Parameters
string|null $filestring|null $tempDir
colLetter()
public static function colLetter(int $colNumber): string
Convert column number to letter
Parameters
int $colNumber– ONE based
colNum()
public static function colNum(string $colLetter): int
Converts an alphabetic column index to a numeric
Parameters
string $colLetter
createReader()
public static function createReader(string $file,
?array $parserProperties = []): Interfaces\InterfaceXmlReader
Create XML reader object
Parameters
string $filearray|null $parserProperties
createSheet()
public static function createSheet(string $sheetName, $sheetId, $file, $path,
$excel): Interfaces\InterfaceSheetReader
Create sheet object
Parameters
string $sheetNameint|string $sheetIdstring $filestring $pathExcel $excel
isXls()
public static function isXls(string $file): bool
TRUE if the file starts with the OLE2 compound file signature
Parameters
string $file
isXlsx()
public static function isXlsx(string $file): bool
TRUE if the file starts with the ZIP local file header signature
An XLSX package is a ZIP archive, so it begins with "PK\x03\x04". This iswhat lets open() tell a real XLSX apart from plain text, which is thenread as CSV.
Parameters
string $file
open()
public static function open(string $file, $options): AbstractBook
Open a spreadsheet, choosing the reader by the file signature
The OLE2 magic number is a legacy XLS workbook, a ZIP container is XLSX, and anything else is treated as delimited text (CSV). The file extension is not consulted, because it is often wrong on files arriving from other systems. Pass $options['format'] = 'csv' to force the CSV reader, and any CsvOptions keys (delimiter, enclosure, encoding, ...) to configure it.
Parameters
string $fileCsvOptions|array|null $options
openCsv()
public static function openCsv(string $file, $options): Csv\CsvReader
Open CSV as the low-level CsvReader (4.x contract)
In 5.0, openCsv() is planned to return CsvBook. Use openCsvReader() for stable low-level access, or openCsvBook() for the common book/sheet API.
Parameters
string $fileCsvOptions|array|null $options
openCsvBook()
public static function openCsvBook(string $file, $options): Csv\CsvBook
Open CSV as a single-sheet workbook without format detection
Unlike open(), this factory also accepts an empty CSV file.
Parameters
string $fileCsvOptions|array|null $options
openCsvReader()
public static function openCsvReader(string $file, $options): Csv\CsvReader
Open the low-level CSV reader without a workbook wrapper
Use this name to keep the CsvReader contract across the planned 5.0 change to openCsv(). For the common book/sheet API, use openCsvBook() instead.
Parameters
string $fileCsvOptions|array|null $options
openStream()
public static function openStream($stream, $options): AbstractBook
Open a spreadsheet from an open stream resource
The stream is copied (from its current position, without seeking, so non-rewindable streams such as HTTP wrappers work) into a temporary file and then opened like open(). This is the entry point for URLs (fopen('https://...')), php://memory and Flysystem/S3 read streams. The caller keeps ownership of the stream; it is not closed here. The temporary file is removed on script shutdown.
Parameters
resource $stream– An open, readable stream resourceCsvOptions|array|null $options– Same options as open()
openString()
public static function openString(string $content, $options): AbstractBook
Open a spreadsheet held in a string, choosing the reader by its signature
The content is written to a temporary file and then opened exactly like open() - format is detected from the bytes, not from any file name, so an XLSX/XLS/CSV payload each read back the same as its on-disk counterpart. The temporary file is removed on script shutdown. Handy for content coming from a database blob, an HTTP response body or an S3/Flysystem read.
Parameters
string $content– Raw bytes of the workbookCsvOptions|array|null $options– Same options as open()
openXls()
public static function openXls(string $file): Xls\XlsBook
Open an XLS (Excel 97-2003, BIFF8) file
Parameters
string $file
openXlsx()
public static function openXlsx(string $file): self
Open an XLSX workbook without format detection
Parameters
string $file
setTempDir()
public static function setTempDir($tempDir)
Set directory for temporary files
Parameters
string $tempDir
validate()
public static function validate(string $file, ?array &$errors = []): bool
Check required XLSX package parts and XML well-formedness
This is not OOXML schema validation. The libxml error mode is restored; its diagnostic buffer is cleared before and after validation. XML errors are returned in $errors; missing package parts return false without XML errors.
Parameters
string $filearray|null $errors
countExtraImages()
public function countExtraImages(): int
Count "extra" images (images that are in the media folder but not in the drawings)
Parameters
None
countImages()
public function countImages(): int
Returns the total count of images in the workbook
Parameters
None
countSheets()
public function countSheets(): int
Returns the number of sheets in the workbook
Parameters
None
dateFormatter()
public function dateFormatter($formatter): AbstractBook
Set custom date formatter
Parameters
\Closure|callable|string|bool|null $formatter
formatDate()
public function formatDate($value, $format, $styleIdx): false|mixed|string
Format date value
Parameters
mixed $valuestring|null $formatint|null $styleIdx
from()
public function from(string $topLeftCell,
?bool $firstRowKeys = false): AbstractSheet
Set top left of read area
Parameters
string $topLeftCellbool|null $firstRowKeys
getCompleteStyleByIdx()
public function getCompleteStyleByIdx(int $styleIdx,
?bool $flat = false): array
Get complete style by style index
Parameters
int $styleIdxbool|null $flat
getDateFormat()
public function getDateFormat(): ?string
Get current date format
Parameters
None
getDateFormatPattern()
public function getDateFormatPattern(int $styleIdx): ?string
Get PHP date format pattern by style index
Parameters
int $styleIdx
getDateFormatter()
public function getDateFormatter(): callable|\Closure|bool|null
Get date formatter
Parameters
None
getDefinedNames()
public function getDefinedNames(): array
Get defined names of workbook
Parameters
None
getFirstSheet()
public function getFirstSheet(?string $areaRange = null,
?bool $firstRowKeys = false): AbstractSheet
Returns the first sheet as default
Parameters
string|null $areaRangebool|null $firstRowKeys
getFormatPattern()
public function getFormatPattern(int $styleIdx): mixed|string
Get format pattern by style index
Parameters
int $styleIdx
getImageList()
public function getImageList(): array
Get the list of images from the workbook
Parameters
None
getProperties()
public function getProperties(): array
Get the document properties of the workbook
Reads the core properties (docProps/core.xml) and the extended, application properties (docProps/app.xml) into a single associative array with normalised keys - 'creator', 'lastModifiedBy', 'created', 'modified', 'title', 'subject', 'description', 'keywords', 'category', 'revision', 'application', 'company', 'manager', ... Only the properties present in the file are returned; a workbook without a docProps part returns an empty array. The result is read on demand and cached.
Parameters
None
getSheet()
public function getSheet(?string $name = null, ?string $areaRange = null,
?bool $firstRowKeys = false): AbstractSheet
Get sheet object by name and optionally set read area and options
Parameters
string|null $namestring|null $areaRangebool|null $firstRowKeys
getSheetById()
public function getSheetById(int $sheetId, ?string $areaRange = null,
?bool $firstRowKeys = false): AbstractSheet
Returns a sheet by ID
Parameters
int $sheetIdstring|null $areaRangebool|null $firstRowKeys
getSheetNames()
public function getSheetNames(): array
Get names array of all sheets
Parameters
None
hasDrawings()
public function hasDrawings(): bool
Returns TRUE if the workbook contains an any draw objects (not images only)
Parameters
None
hasExtraImages()
public function hasExtraImages(): bool
Returns TRUE if there are any "extra" images
Parameters
None
hasImages()
public function hasImages(): bool
Returns TRUE if any sheet contains an image object
Parameters
None
hiddenSheets()
public function hiddenSheets(): array
Array of hidden sheets only
Parameters
None
innerFileList()
public function innerFileList(): array
Get list of inner files in XLSX
Parameters
None
mediaImageFiles()
public function mediaImageFiles(): array
Get list of media image files in the workbook
Parameters
None
metadataImage()
public function metadataImage(int $vmIndex): ?string
Get image file name from metadata by index
Parameters
int $vmIndex
readCallback()
public function readCallback(callable $callback, ?int $resultMode = null,
?bool $styleIdxInclude = null)
Reads cell values and passes them to a callback function
Parameters
callback $callbackint|null $resultModebool|null $styleIdxInclude
readCells()
public function readCells(): array
Returns the values of all cells as array
Parameters
None
readCellStyles()
public function readCellStyles(?bool $flat = false): array
Returns the styles of all cells as array
Parameters
bool|null $flat
readCellsWithStyles()
public function readCellsWithStyles(): array
Returns the values and styles of all cells as array
Parameters
None
readColumns()
public function readColumns($columnKeys, ?int $resultMode = null): array
Returns cell values as a two-dimensional array from default sheet [col][row]
Parameters
array|bool|int|null $columnKeysint|null $resultMode
readColumnsWithStyles()
public function readColumnsWithStyles($columnKeys,
?int $resultMode = null): array
Returns cell values and styles as a two-dimensional array from default sheet [col][row]
Parameters
array|bool|int|null $columnKeysint|null $resultMode
readRows()
public function readRows($columnKeys, ?int $resultMode = null,
?bool $styleIdxInclude = null): array
Returns cell values as a two-dimensional array from default sheet [row][col]
readRows()readRows(true)readRows(false, Excel::KEYS_ZERO_BASED)readRows(Excel::KEYS_ZERO_BASED | Excel::KEYS_RELATIVE)
Parameters
array|bool|int|null $columnKeysint|null $resultModebool|null $styleIdxInclude
readRowsWithStyles()
public function readRowsWithStyles($columnKeys,
?int $resultMode = null): array
Returns cell values and styles as a two-dimensional array from default sheet [row][col]
Parameters
array|bool|int|null $columnKeysint|null $resultMode
readStyles()
public function readStyles(): array
Read all workbook styles
Parameters
None
selectFirstSheet()
public function selectFirstSheet(?string $areaRange = null,
?bool $firstRowKeys = false): AbstractSheet
Selects the first sheet as default
Parameters
string|null $areaRangebool|null $firstRowKeys
selectSheet()
public function selectSheet(string $name, ?string $areaRange = null,
?bool $firstRowKeys = false): AbstractSheet
Selects default sheet by name
Parameters
string $namestring|null $areaRangebool|null $firstRowKeys
selectSheetById()
public function selectSheetById(int $sheetId, ?string $areaRange = null,
?bool $firstRowKeys = false): AbstractSheet
Selects default sheet by ID
Parameters
int $sheetIdstring|null $areaRangebool|null $firstRowKeys
setDateFormat()
public function setDateFormat(string $dateFormat): AbstractBook
Set date format for reading
Parameters
string $dateFormat
setReadArea()
public function setReadArea(string $areaRange,
?bool $firstRowKeys = false): AbstractSheet
Set top left and right bottom of read area
Parameters
string $areaRangebool|null $firstRowKeys
sharedString()
public function sharedString($stringId): ?string
Get string by index
Parameters
int $stringId
sheet()
public function sheet(?string $name = null): ?AbstractSheet
Get current or specified sheet
Parameters
string|null $name
sheetExists()
public function sheetExists(string $name): bool
Returns TRUE if a sheet with the given name exists
Parameters
string $name
sheets()
public function sheets(): array
Array of all sheets
Parameters
None
stat()
public function stat(): array
Returns statistics of the workbook: per-sheet breakdown and totals
['sheets' => ['<sheetName>' => ['rows' => [...], 'cols' => [...], 'cells' => ['total' => int, 'filled' => int]],...],'total' => ['sheets' => int, // number of sheets'visible' => int, // number of visible sheets'hidden' => int, // number of hidden sheets'rows' => int, // sum of actual rows over all sheets'cells' => ['total' => int, 'filled' => int],],]
Note: scans every sheet fully (see Sheet::stat()); expensive on large workbooks.
Parameters
None
styleByIdx()
public function styleByIdx($styleIdx): array
Get style array by style index
Parameters
int $styleIdx
timestamp()
public function timestamp($excelDateTime): int
Convert date to timestamp
Parameters
$excelDateTime
useLocaleFormats()
public function useLocaleFormats(?string $locale = null): AbstractBook
Opt in to locale-dependent patterns for the built-in date codes (numFmtId 14-22).
By default these codes resolve to fixed, deterministic patterns, so the same file yields the same output on any server. Call this to render them with ICU locale patterns instead (the pre-4.x behaviour, but now explicit and with a chosen locale). Requires ext-intl.
Parameters
string|null $locale– ICU locale name (e.g. 'ru_RU'); NULL uses the process default locale
visibleSheets()
public function visibleSheets(): array
Array of visible sheets only
Parameters
None