Class \avadim\FastExcelTemplator\Excel
On this page
- __construct()
- Parameters
- colLetter()
- Parameters
- colNum()
- Parameters
- createReader()
- Parameters
- createSheet()
- Parameters
- isXls()
- Parameters
- isXlsx()
- Parameters
- open()
- Parameters
- openCsv()
- Parameters
- openStream()
- Parameters
- openString()
- Parameters
- openXls()
- Parameters
- setTempDir()
- Parameters
- template()
- Parameters
- validate()
- Parameters
- countExtraImages()
- Parameters
- countImages()
- Parameters
- countSheets()
- Parameters
- dateFormatter()
- Parameters
- download()
- Parameters
- fill()
- 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
- metadataDiagnostics()
- Parameters
- metadataImage()
- Parameters
- output()
- Parameters
- outputFile()
- Parameters
- readCallback()
- Parameters
- readCells()
- Parameters
- readCellStyles()
- Parameters
- readCellsWithStyles()
- Parameters
- readColumns()
- Parameters
- readColumnsWithStyles()
- Parameters
- readRows()
- Parameters
- readRowsWithStyles()
- Parameters
- readStyles()
- Parameters
- replace()
- Parameters
- save()
- Parameters
- selectFirstSheet()
- Parameters
- selectSheet()
- Parameters
- selectSheetById()
- Parameters
- setDateFormat()
- Parameters
- setReadArea()
- Parameters
- sharedString()
- Parameters
- sheet()
- Parameters
- sheetExists()
- Parameters
- sheets()
- Parameters
- stat()
- Parameters
- styleByIdx()
- Parameters
- templateFile()
- 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 internal reader
- createSheet() – Create sheet template instance
- 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 file
- 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
- setTempDir() – Set dir for temporary files
- template() – Open an XLSX template and create its output writer.
- validate() – Validate XLSX file
- 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
- download() – Download generated file to client (send to browser)
- fill() – Set replacements of entire cell values for the sheet
- 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() – Returns a sheet by name
- 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
- metadataDiagnostics() – Return sheet/code/message diagnostics from the latest archive generation, including strict rejections; preliminary path errors do not refresh the report.
- metadataImage() – Get image file name from metadata by index
- output() – Alias of download()
- outputFile() – Name of the output file, or an empty string if it was not specified yet
- 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
- replace() – Set replacements of any occurring substrings
- save() – Save XLSX after metadata checks; publish only the completed workbook, preserving the template and an existing destination on failure.
- 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()
- 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
- templateFile()
- 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 $templateFile, ?string $outputFile = null,
?array $options = [])
Excel constructor
Parameters
string $templateFilestring|null $outputFilearray|null $options
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 = []): Reader
Create internal reader
Parameters
string $filearray|null $parserProperties
createSheet()
public static function createSheet(string $sheetName, $sheetId, $file, $path,
$excel): SheetTemplate
Create sheet template instance
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 signatureAn 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): avadim\FastExcelReader\AbstractBook
Open a spreadsheet, choosing the reader by the file signatureThe OLE2 magic number is a legacy XLS workbook, a ZIP container is XLSX,and anything else is treated as delimited text (CSV). The file extensionis not consulted, because it is often wrong on files arriving from othersystems. Pass $options['format'] = 'csv' to force the CSV reader, and anyCsvOptions keys (delimiter, enclosure, encoding, ...) to configure it.
Parameters
string $fileCsvOptions|array|null $options
openCsv()
public static function openCsv(string $file,
$options): avadim\FastExcelReader\Csv\CsvReader
Open CSV file
Parameters
string $fileCsvOptions|array|null $options
openStream()
public static function openStream($stream,
$options): avadim\FastExcelReader\AbstractBook
Open a spreadsheet from an open stream resourceThe stream is copied (from its current position, without seeking, sonon-rewindable streams such as HTTP wrappers work) into a temporary fileand then opened like open(). This is the entry point for URLs(fopen('https://...')), php://memory and Flysystem/S3 read streams. Thecaller keeps ownership of the stream; it is not closed here. The temporaryfile 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): avadim\FastExcelReader\AbstractBook
Open a spreadsheet held in a string, choosing the reader by its signatureThe content is written to a temporary file and then opened exactly likeopen() - format is detected from the bytes, not from any file name, so anXLSX/XLS/CSV payload each read back the same as its on-disk counterpart.The temporary file is removed on script shutdown. Handy for content comingfrom 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): avadim\FastExcelReader\Xls\XlsBook
Open an XLS (Excel 97-2003, BIFF8) file
Parameters
string $file
setTempDir()
public static function setTempDir($tempDir)
Set dir for temporary files
Parameters
$tempDir
template()
public static function template(string $templateFile,
?string $outputFile = null,
?array $options = []): Excel
Open an XLSX template and create its output writer.
Parameters
string $templateFile– Existing XLSX templatestring|null $outputFile– Output path; may also be supplied to save()array|null $options– Writer options; strict_metadata (bool, default false) rejects detected unsupported metadata transformations at save time
validate()
public static function validate(string $file, ?array &$errors = []): bool
Validate XLSX file
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): avadim\FastExcelReader\AbstractBook
Set custom date formatter
Parameters
\Closure|callable|string|bool|null $formatter
download()
public function download(?string $name = null)
Download generated file to client (send to browser)
Parameters
string|null $name
fill()
public function fill(array $params): Excel
Set replacements of entire cell values for the sheet
Parameters
array $params
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): avadim\FastExcelReader\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): avadim\FastExcelReader\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 workbookReads the core properties (docProps/core.xml) and the extended,application properties (docProps/app.xml) into a single associative arraywith normalised keys - 'creator', 'lastModifiedBy', 'created', 'modified','title', 'subject', 'description', 'keywords', 'category', 'revision','application', 'company', 'manager', ... Only the properties present in thefile are returned; a workbook without a docProps part returns an emptyarray. The result is read on demand and cached.
Parameters
None
getSheet()
public function getSheet(?string $name = null, ?string $areaRange = null,
?bool $firstRowKeys = false): SheetTemplate
Returns a sheet by name
Parameters
string|null $namestring|null $areaRangebool|null $firstRowKeys
getSheetById()
public function getSheetById(int $sheetId, ?string $areaRange = null,
?bool $firstRowKeys = false): avadim\FastExcelReader\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
metadataDiagnostics()
public function metadataDiagnostics(): array
Return sheet/code/message diagnostics from the latest archive generation, including strict rejections; preliminary path errors do not refresh the report.
Parameters
None
metadataImage()
public function metadataImage(int $vmIndex): ?string
Get image file name from metadata by index
Parameters
int $vmIndex
output()
public function output(?string $name = null): void
Alias of download()
Parameters
string|null $name
outputFile()
public function outputFile(): string
Name of the output file, or an empty string if it was not specified yet
Parameters
None
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
replace()
public function replace(array $params): Excel
Set replacements of any occurring substrings
Parameters
array $params
save()
public function save(?string $fileName = null, ?bool $overWrite = true): bool
Save XLSX after metadata checks; publish only the completed workbook, preserving the template and an existing destination on failure.
Parameters
string|null $fileName– Output path; null uses the configured writer filenamebool|null $overWrite– False refuses existing destinations, including files created during generation
selectFirstSheet()
public function selectFirstSheet(?string $areaRange = null,
?bool $firstRowKeys = false): avadim\FastExcelReader\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): avadim\FastExcelReader\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): avadim\FastExcelReader\AbstractSheet
Selects default sheet by ID
Parameters
int $sheetIdstring|null $areaRangebool|null $firstRowKeys
setDateFormat()
public function setDateFormat(string $dateFormat): avadim\FastExcelReader\AbstractBook
Set date format for reading
Parameters
string $dateFormat
setReadArea()
public function setReadArea(string $areaRange,
?bool $firstRowKeys = false): avadim\FastExcelReader\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): ?SheetTemplate
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
templateFile()
public function templateFile(): string
Parameters
None
timestamp()
public function timestamp($excelDateTime): int
Convert date to timestamp
Parameters
$excelDateTime
useLocaleFormats()
public function useLocaleFormats(?string $locale = null): avadim\FastExcelReader\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