Class \avadim\FastExcelTemplator\Excel

Source: 3.4.0 · 4de0b13

On this page


__construct()


php
public function __construct(string $templateFile, ?string $outputFile = null, 
                            ?array $options = [])

Excel constructor

Parameters

  • string $templateFile
  • string|null $outputFile
  • array|null $options

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 = []): Reader

Create internal reader

Parameters

  • string $file
  • array|null $parserProperties

createSheet()


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

Create sheet template instance

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


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

openCsv()


php
public static function openCsv(string $file, 
                               $options): avadim\FastExcelReader\Csv\CsvReader

Open CSV file

Parameters

  • string $file
  • CsvOptions|array|null $options

openStream()


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

openString()


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

openXls()


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

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

Parameters

  • string $file

setTempDir()


php
public static function setTempDir($tempDir)

Set dir for temporary files

Parameters

  • $tempDir

template()


php
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 template
  • string|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()


php
public static function validate(string $file, ?array &$errors = []): bool

Validate XLSX file

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): avadim\FastExcelReader\AbstractBook

Set custom date formatter

Parameters

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

download()


php
public function download(?string $name = null)

Download generated file to client (send to browser)

Parameters

  • string|null $name

fill()


php
public function fill(array $params): Excel

Set replacements of entire cell values for the sheet

Parameters

  • array $params

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): avadim\FastExcelReader\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): avadim\FastExcelReader\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 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()


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

Returns a sheet by name

Parameters

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

getSheetById()


php
public function getSheetById(int $sheetId, ?string $areaRange = null, 
                             ?bool $firstRowKeys = false): avadim\FastExcelReader\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


metadataDiagnostics()


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


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

Get image file name from metadata by index

Parameters

  • int $vmIndex

output()


php
public function output(?string $name = null): void

Alias of download()

Parameters

  • string|null $name

outputFile()


php
public function outputFile(): string

Name of the output file, or an empty string if it was not specified yet

Parameters

None


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


replace()


php
public function replace(array $params): Excel

Set replacements of any occurring substrings

Parameters

  • array $params

save()


php
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 filename
  • bool|null $overWrite – False refuses existing destinations, including files created during generation

selectFirstSheet()


php
public function selectFirstSheet(?string $areaRange = null, 
                                 ?bool $firstRowKeys = false): avadim\FastExcelReader\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): avadim\FastExcelReader\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): avadim\FastExcelReader\AbstractSheet

Selects default sheet by ID

Parameters

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

setDateFormat()


php
public function setDateFormat(string $dateFormat): avadim\FastExcelReader\AbstractBook

Set date format for reading

Parameters

  • string $dateFormat

setReadArea()


php
public function setReadArea(string $areaRange, 
                            ?bool $firstRowKeys = false): avadim\FastExcelReader\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): ?SheetTemplate

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

templateFile()


php
public function templateFile(): string

Parameters

None


timestamp()


php
public function timestamp($excelDateTime): int

Convert date to timestamp

Parameters

  • $excelDateTime

useLocaleFormats()


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


php
public function visibleSheets(): array

Array of visible sheets only

Parameters

None


FastExcelTemplator 3.4.0 · Search this library and version.

Loading search…

Could not load search. Please try again.

No results. Try another word or method name.