Class \avadim\FastExcelReader\Excel

Source: 4.5.0 · dd0d48d

On this page


__construct()


php
public function __construct(?string $file = null, ?string $tempDir = '')

Excel constructor

Parameters

  • string|null $file
  • string|null $tempDir

colLetter()


php
public static function colLetter(int $colNumber): string

Convert column number to letter

Parameters

  • int $colNumber – ONE based

colNum()


php
public static function colNum(string $colLetter): int

Converts an alphabetic column index to a numeric

Parameters

  • string $colLetter

createReader()


php
public static function createReader(string $file, 
                                    ?array $parserProperties = []): Interfaces\InterfaceXmlReader

Create XML reader object

Parameters

  • string $file
  • array|null $parserProperties

createSheet()


php
public static function createSheet(string $sheetName, $sheetId, $file, $path, 
                                   $excel): Interfaces\InterfaceSheetReader

Create sheet object

Parameters

  • string $sheetName
  • int|string $sheetId
  • string $file
  • string $path
  • Excel $excel

isXls()


php
public static function isXls(string $file): bool

TRUE if the file starts with the OLE2 compound file signature

Parameters

  • string $file

isXlsx()


php
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()


php
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 $file
  • CsvOptions|array|null $options

openCsv()


php
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 $file
  • CsvOptions|array|null $options

openCsvBook()


php
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 $file
  • CsvOptions|array|null $options

openCsvReader()


php
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 $file
  • CsvOptions|array|null $options

openStream()


php
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 resource
  • CsvOptions|array|null $options – Same options as open()

openString()


php
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 workbook
  • CsvOptions|array|null $options – Same options as open()

openXls()


php
public static function openXls(string $file): Xls\XlsBook

Open an XLS (Excel 97-2003, BIFF8) file

Parameters

  • string $file

openXlsx()


php
public static function openXlsx(string $file): self

Open an XLSX workbook without format detection

Parameters

  • string $file

setTempDir()


php
public static function setTempDir($tempDir)

Set directory for temporary files

Parameters

  • string $tempDir

validate()


php
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 $file
  • array|null $errors

countExtraImages()


php
public function countExtraImages(): int

Count "extra" images (images that are in the media folder but not in the drawings)

Parameters

None


countImages()


php
public function countImages(): int

Returns the total count of images in the workbook

Parameters

None


countSheets()


php
public function countSheets(): int

Returns the number of sheets in the workbook

Parameters

None


dateFormatter()


php
public function dateFormatter($formatter): AbstractBook

Set custom date formatter

Parameters

  • \Closure|callable|string|bool|null $formatter

formatDate()


php
public function formatDate($value, $format, $styleIdx): false|mixed|string

Format date value

Parameters

  • mixed $value
  • string|null $format
  • int|null $styleIdx

from()


php
public function from(string $topLeftCell, 
                     ?bool $firstRowKeys = false): AbstractSheet

Set top left of read area

Parameters

  • string $topLeftCell
  • bool|null $firstRowKeys

getCompleteStyleByIdx()


php
public function getCompleteStyleByIdx(int $styleIdx, 
                                      ?bool $flat = false): array

Get complete style by style index

Parameters

  • int $styleIdx
  • bool|null $flat

getDateFormat()


php
public function getDateFormat(): ?string

Get current date format

Parameters

None


getDateFormatPattern()


php
public function getDateFormatPattern(int $styleIdx): ?string

Get PHP date format pattern by style index

Parameters

  • int $styleIdx

getDateFormatter()


php
public function getDateFormatter(): callable|\Closure|bool|null

Get date formatter

Parameters

None


getDefinedNames()


php
public function getDefinedNames(): array

Get defined names of workbook

Parameters

None


getFirstSheet()


php
public function getFirstSheet(?string $areaRange = null, 
                              ?bool $firstRowKeys = false): AbstractSheet

Returns the first sheet as default

Parameters

  • string|null $areaRange
  • bool|null $firstRowKeys

getFormatPattern()


php
public function getFormatPattern(int $styleIdx): mixed|string

Get format pattern by style index

Parameters

  • int $styleIdx

getImageList()


php
public function getImageList(): array

Get the list of images from the workbook

Parameters

None


getProperties()


php
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()


php
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 $name
  • string|null $areaRange
  • bool|null $firstRowKeys

getSheetById()


php
public function getSheetById(int $sheetId, ?string $areaRange = null, 
                             ?bool $firstRowKeys = false): AbstractSheet

Returns a sheet by ID

Parameters

  • int $sheetId
  • string|null $areaRange
  • bool|null $firstRowKeys

getSheetNames()


php
public function getSheetNames(): array

Get names array of all sheets

Parameters

None


hasDrawings()


php
public function hasDrawings(): bool

Returns TRUE if the workbook contains an any draw objects (not images only)

Parameters

None


hasExtraImages()


php
public function hasExtraImages(): bool

Returns TRUE if there are any "extra" images

Parameters

None


hasImages()


php
public function hasImages(): bool

Returns TRUE if any sheet contains an image object

Parameters

None


hiddenSheets()


php
public function hiddenSheets(): array

Array of hidden sheets only

Parameters

None


innerFileList()


php
public function innerFileList(): array

Get list of inner files in XLSX

Parameters

None


mediaImageFiles()


php
public function mediaImageFiles(): array

Get list of media image files in the workbook

Parameters

None


metadataImage()


php
public function metadataImage(int $vmIndex): ?string

Get image file name from metadata by index

Parameters

  • int $vmIndex

readCallback()


php
public function readCallback(callable $callback, ?int $resultMode = null, 
                             ?bool $styleIdxInclude = null)

Reads cell values and passes them to a callback function

Parameters

  • callback $callback
  • int|null $resultMode
  • bool|null $styleIdxInclude

readCells()


php
public function readCells(): array

Returns the values of all cells as array

Parameters

None


readCellStyles()


php
public function readCellStyles(?bool $flat = false): array

Returns the styles of all cells as array

Parameters

  • bool|null $flat

readCellsWithStyles()


php
public function readCellsWithStyles(): array

Returns the values and styles of all cells as array

Parameters

None


readColumns()


php
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 $columnKeys
  • int|null $resultMode

readColumnsWithStyles()


php
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 $columnKeys
  • int|null $resultMode

readRows()


php
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 $columnKeys
  • int|null $resultMode
  • bool|null $styleIdxInclude

readRowsWithStyles()


php
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 $columnKeys
  • int|null $resultMode

readStyles()


php
public function readStyles(): array

Read all workbook styles

Parameters

None


selectFirstSheet()


php
public function selectFirstSheet(?string $areaRange = null, 
                                 ?bool $firstRowKeys = false): AbstractSheet

Selects the first sheet as default

Parameters

  • string|null $areaRange
  • bool|null $firstRowKeys

selectSheet()


php
public function selectSheet(string $name, ?string $areaRange = null, 
                            ?bool $firstRowKeys = false): AbstractSheet

Selects default sheet by name

Parameters

  • string $name
  • string|null $areaRange
  • bool|null $firstRowKeys

selectSheetById()


php
public function selectSheetById(int $sheetId, ?string $areaRange = null, 
                                ?bool $firstRowKeys = false): AbstractSheet

Selects default sheet by ID

Parameters

  • int $sheetId
  • string|null $areaRange
  • bool|null $firstRowKeys

setDateFormat()


php
public function setDateFormat(string $dateFormat): AbstractBook

Set date format for reading

Parameters

  • string $dateFormat

setReadArea()


php
public function setReadArea(string $areaRange, 
                            ?bool $firstRowKeys = false): AbstractSheet

Set top left and right bottom of read area

Parameters

  • string $areaRange
  • bool|null $firstRowKeys

sharedString()


php
public function sharedString($stringId): ?string

Get string by index

Parameters

  • int $stringId

sheet()


php
public function sheet(?string $name = null): ?AbstractSheet

Get current or specified sheet

Parameters

  • string|null $name

sheetExists()


php
public function sheetExists(string $name): bool

Returns TRUE if a sheet with the given name exists

Parameters

  • string $name

sheets()


php
public function sheets(): array

Array of all sheets

Parameters

None


stat()


php
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()


php
public function styleByIdx($styleIdx): array

Get style array by style index

Parameters

  • int $styleIdx

timestamp()


php
public function timestamp($excelDateTime): int

Convert date to timestamp

Parameters

  • $excelDateTime

useLocaleFormats()


php
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()


php
public function visibleSheets(): array

Array of visible sheets only

Parameters

None


FastExcelReader 4.5.0 · Search this library and version.

Loading search…

Could not load search. Please try again.

No results. Try another word or method name.