Class \avadim\FastExcelLaravel\ExcelWriter
On this page
- __construct()
- Parameters
- cellAddress()
- Parameters
- Examples
- colIndex()
- Parameters
- colIndexRange()
- Parameters
- colLetter()
- Parameters
- colLetterRange()
- Parameters
- Examples
- colNumber()
- Parameters
- colNumberRange()
- Parameters
- create()
- Parameters
- createSheet()
- Parameters
- fullAddress()
- Parameters
- generateUuid()
- Parameters
- newStyle()
- Parameters
- pixelsToEMU()
- Parameters
- rangeRelOffsets()
- Parameters
- setTempDir()
- Parameters
- toTimestamp()
- Parameters
- addDefinedName()
- Parameters
- addNamedRange()
- Parameters
- addSharedString()
- Parameters
- download()
- Parameters
- exportModel()
- Parameters
- getDefaultFormatStyles()
- Parameters
- getDefaultSheetName()
- Parameters
- getDefaultStyle()
- Parameters
- getDefinedNames()
- Parameters
- getFileName()
- Parameters
- getImageFiles()
- Parameters
- getMetadata()
- Parameters
- getSharedStrings()
- Parameters
- getSharedStringsRefCount()
- Parameters
- getSheet()
- Parameters
- getSheets()
- Parameters
- getWriter()
- Parameters
- isR1C1()
- Parameters
- isRightToLeft()
- Parameters
- makeSheet()
- Parameters
- output()
- Parameters
- protect()
- Parameters
- removeSheet()
- Parameters
- save()
- Parameters
- saveTo()
- Parameters
- setActiveSheet()
- Parameters
- setAuthor()
- Parameters
- setCompany()
- Parameters
- setDefaultDateFormat()
- Parameters
- setDefaultDateTimeFormat()
- Parameters
- setDefaultFont()
- Parameters
- setDefaultFontName()
- Parameters
- setDefaultFormat()
- Parameters
- setDefaultLocale()
- Parameters
- setDefaultStyle()
- Parameters
- setDefaultTimeFormat()
- Parameters
- setDescription()
- Parameters
- setFileName()
- Parameters
- setKeywords()
- Parameters
- setLocale()
- Parameters
- setMetaAuthor()
- Parameters
- setMetaCompany()
- Parameters
- setMetadata()
- Parameters
- setMetaDescription()
- Parameters
- setMetaKeywords()
- Parameters
- setMetaSubject()
- Parameters
- setMetaTitle()
- Parameters
- setR1C1()
- Parameters
- setRightToLeft()
- Parameters
- setSharedString()
- Parameters
- setSubject()
- Parameters
- setTitle()
- Parameters
- sheet()
- Parameters
- store()
- Parameters
- unprotect()
- Parameters
- writeData()
- Parameters
- __construct() -- Excel constructor
- cellAddress() -- Create cell address by row and col numbers
- colIndex() -- Convert letter to index (ZERO based)
- colIndexRange() -- Convert letter range to array of numbers (ZERO based)
- colLetter() -- Convert column number to letter
- colLetterRange() -- Convert values to letters array
- colNumber() -- Convert letter to number (ONE based)
- colNumberRange() -- Convert letter range to array of numbers (ONE based)
- create() -- Create XLSX for export
- createSheet() -- Create SheetWriter instance
- fullAddress() -- Get full address with sheet name
- generateUuid() -- Generate UUID v4
- newStyle() -- Create a new instance of Style class
- pixelsToEMU() -- Convert pixels to EMU (English Metric Units)
- rangeRelOffsets() -- Return offsets by relative address (zero based)
- setTempDir() -- Set dir for temporary files
- toTimestamp() -- Convert value (int or string) to Excel timestamp
- addDefinedName() -- Add a defined name
- addNamedRange() -- Add a named range
- addSharedString() -- Add a string to the shared strings table
- download() -- Download generated file to client (send to browser)
- exportModel() -- Export a model to the current sheet
- getDefaultFormatStyles() -- Get default format styles
- getDefaultSheetName() -- Get the default sheet name
- getDefaultStyle() -- Get default style
- getDefinedNames() -- Get all defined names
- getFileName() -- Returns default filename
- getImageFiles() -- Get list of all loaded image files
- getMetadata() -- Get metadata
- getSharedStrings() -- Get the shared strings table
- getSharedStringsRefCount() -- Total number of shared string references
- getSheet() -- Alias of sheet()
- getSheets() -- Returns all sheets
- getWriter() -- Get the writer instance
- isR1C1() -- Is R1C1 notation mode enabled?
- isRightToLeft() -- Get right-to-left orientation
- makeSheet() -- Creates and returns a new sheet
- output() -- Alias of download()
- protect() -- Protect workbook
- removeSheet() -- Removes sheet by index or name of sheet.
- save() -- Save generated XLSX-file
- saveTo() -- Save file to the storage directory (relative to storage_path())
- setActiveSheet() -- Set active (default) sheet by case-insensitive name
- setAuthor() -- Set the author of the document
- setCompany() -- Set the company of the document
- setDefaultDateFormat() -- Set the default date format of the workbook
- setDefaultDateTimeFormat() -- Set the default date and time format of the workbook
- setDefaultFont() -- Set default font options
- setDefaultFontName() -- Set default font name
- setDefaultFormat() -- Set the format of the workbook which overrides the format of the locale
- setDefaultLocale() -- Set default locale from the current environment
- setDefaultStyle() -- Set default style
- setDefaultTimeFormat() -- Set the default time format of the workbook
- setDescription() -- Set the description of the document
- setFileName() -- Sets default filename for saving
- setKeywords() -- Set the keywords of the document
- setLocale() -- Set locale information
- setMetaAuthor() -- Set metadata 'author'
- setMetaCompany() -- Set metadata 'company'
- setMetadata() -- Set metadata
- setMetaDescription() -- Set metadata 'description'
- setMetaKeywords() -- Set metadata 'keywords'
- setMetaSubject() -- Set metadata 'subject'
- setMetaTitle() -- Set metadata 'title'
- setR1C1() -- Set R1C1 notation mode
- setRightToLeft() -- Set right-to-left orientation
- setSharedString() -- Set the usage of shared strings
- setSubject() -- Set the subject of the document
- setTitle() -- Set the title of the document
- sheet() -- Returns sheet by number or name of sheet.
- store() -- Store file to specified disk
- unprotect() -- Unprotect workbook
- writeData() -- Write data to the current sheet
__construct()
public function __construct(?array $options = [])
Excel constructor
Parameters
array|null $options-- Optional parameters: ['temp_dir' => ..., 'temp_prefix' => ..., 'auto_convert_number' => ..., 'shared_string' => ...]
cellAddress()
public static function cellAddress(int $rowNumber, int $colNumber,
?bool $absolute = false,
?bool $absoluteRow = null): string
Create cell address by row and col numbers
Parameters
int $rowNumber-- ONE basedint $colNumber-- ONE basedbool|null $absolutebool|null $absoluteRow
Examples
cellAddress(3, 3) => 'C3'
cellAddress(43, 27) => 'AA43'
cellAddress(43, 27, true) => '$AA$43'
cellAddress(43, 27, false, true) => 'AA$43'
colIndex()
public static function colIndex(string $colLetter): int
Convert letter to index (ZERO based)
Parameters
string $colLetter
colIndexRange()
public static function colIndexRange($colLetter): array
Convert letter range to array of numbers (ZERO based)
Parameters
string|int|array $colLetter-- e.g.: 'B', 2, 'C:F', ['A', 'B', 'C']
colLetter()
public static function colLetter(int $colNumber): string
Convert column number to letter
Parameters
int $colNumber-- ONE based
colLetterRange()
public static function colLetterRange($colKeys, ?int $baseNum = 0): array
Convert values to letters array
Parameters
array|string $colKeysint|null $baseNum-- 0 or 1
Examples
$res = colLetterRange([0, 1, 2]); // returns ['A', 'B', 'C']
$res = colLetterRange([1, 2, 3], 1); // returns ['A', 'B', 'C']
$res = colLetterRange('B, E, F'); // returns ['B', 'E', 'F']
$res = colLetterRange('B-E, F'); // returns ['B', 'C', 'D', 'E', 'F']
$res = colLetterRange('B1-E8'); // returns ['B', 'C', 'D', 'E']
$res = colLetterRange('B1:E8'); // returns ['B:E']
colNumber()
public static function colNumber(string $colLetter): int
Convert letter to number (ONE based)
Parameters
string $colLetter
colNumberRange()
public static function colNumberRange($colLetter): array
Convert letter range to array of numbers (ONE based)
Parameters
string|int|array $colLetter-- e.g.: 'B', 2, 'C:F', ['A', 'B', 'C']
create()
public static function create($sheets, ?array $options = []): ExcelWriter
Create XLSX for export
Parameters
string|array $sheetsarray|null $options
createSheet()
public static function createSheet(string $sheetName): SheetWriter
Create SheetWriter instance
Parameters
string $sheetName
fullAddress()
public static function fullAddress(string $sheetName, string $address,
?bool $force = false): string
Get full address with sheet name
Parameters
string $sheetNamestring $addressbool|null $force
generateUuid()
public static function generateUuid(): string
Generate UUID v4
Parameters
None
newStyle()
public static function newStyle(): avadim\FastExcelWriter\Style\Style
Create a new instance of Style class
Parameters
None
pixelsToEMU()
public static function pixelsToEMU($pixels): float|int
Convert pixels to EMU (English Metric Units)
Parameters
int|float $pixels
rangeRelOffsets()
public static function rangeRelOffsets(string $relAddress): array
Return offsets by relative address (zero based)
Parameters
string $relAddress
setTempDir()
public static function setTempDir($tempDir)
Set dir for temporary files
Parameters
$tempDir
toTimestamp()
public static function toTimestamp($value): float|bool
Convert value (int or string) to Excel timestamp
Parameters
int|string $value
addDefinedName()
public function addDefinedName(string $name, string $range,
?array $attributes = []): avadim\FastExcelWriter\Excel
Add a defined name
Parameters
string $namestring $rangearray|null $attributes
addNamedRange()
public function addNamedRange(string $range,
string $name): avadim\FastExcelWriter\Excel
Add a named range
Parameters
string $rangestring $name
addSharedString()
public function addSharedString(string $string, ?bool $richText = false): int
Add a string to the shared strings table
Parameters
string $stringbool|null $richText
download()
public function download(?string $name = null)
Download generated file to client (send to browser)
Parameters
string|null $name
exportModel()
public function exportModel($model, ?array $rowStyle = null,
?array $cellStyles = null): ExcelWriter
Export a model to the current sheet. Accepts a model class name or instance, an Eloquent builder, a query builder or a relation, see SheetWriter::exportModel()
Parameters
string|Model|EloquentBuilder|QueryBuilder|Relation $modelarray|null $rowStylearray|null $cellStyles
getDefaultFormatStyles()
public function getDefaultFormatStyles(): array
Get default format styles
Parameters
None
getDefaultSheetName()
public function getDefaultSheetName(): string
Get the default sheet name
Parameters
None
getDefaultStyle()
public function getDefaultStyle(): array
Get default style
Parameters
None
getDefinedNames()
public function getDefinedNames(): array
Get all defined names
Parameters
None
getFileName()
public function getFileName(): string
Returns default filename
Parameters
None
getImageFiles()
public function getImageFiles(): array
Get list of all loaded image files
Parameters
None
getMetadata()
public function getMetadata($key): mixed
Get metadata
Parameters
null $key
getSharedStrings()
public function getSharedStrings(): array
Get the shared strings table
Parameters
None
getSharedStringsRefCount()
public function getSharedStringsRefCount(): int
Total number of shared string references (the count attribute of <sst>)
Parameters
None
getSheet()
public function getSheet($index): ?avadim\FastExcelWriter\Sheet
Alias of sheet()
Parameters
int|string|null $index-- - number or name of sheet
getSheets()
public function getSheets(): array
Returns all sheets
Parameters
None
getWriter()
public function getWriter(): Writer
Get the writer instance
Parameters
None
isR1C1()
public function isR1C1(): bool
Is R1C1 notation mode enabled?
Parameters
None
isRightToLeft()
public function isRightToLeft(): bool
Get right-to-left orientation
Parameters
None
makeSheet()
public function makeSheet(?string $sheetName = null): avadim\FastExcelWriter\Sheet
Creates and returns a new sheet
Parameters
string|null $sheetName
output()
public function output(?string $name = null): void
Alias of download()
Parameters
string|null $name
protect()
public function protect(?string $password = null): avadim\FastExcelWriter\Excel
Protect workbook
Parameters
string|null $password
removeSheet()
public function removeSheet($index): avadim\FastExcelWriter\Excel
Removes sheet by index or name of sheet.Removes the first sheet of index omitted
Parameters
int|string|null $index
save()
public function save(?string $fileName = null, ?bool $overWrite = true): bool
Save generated XLSX-file
Parameters
string|null $fileNamebool|null $overWrite
saveTo()
public function saveTo(string $filePath, ?bool $overWrite = true): bool
Save file to the storage directory. The path is always resolved relative to storage_path() (not to a Storage disk root), missing directories are created. Use save() to save to an arbitrary path or store() to save to a disk
Parameters
string $filePathbool|null $overWrite
setActiveSheet()
public function setActiveSheet(string $name): avadim\FastExcelWriter\Excel
Set active (default) sheet by case-insensitive name
Parameters
string $name
setAuthor()
public function setAuthor(?string $author = ''): avadim\FastExcelWriter\Excel
Set the author of the document
Parameters
string|null $author
setCompany()
public function setCompany(?string $company = ''): avadim\FastExcelWriter\Excel
Set the company of the document
Parameters
string|null $company
setDefaultDateFormat()
public function setDefaultDateFormat(string $format): avadim\FastExcelWriter\Excel
Set the default date format of the workbook (the '@date' style). It overrides the format of the locale.
Parameters
string $format-- e.g.'DD.MM.YYYY'
setDefaultDateTimeFormat()
public function setDefaultDateTimeFormat(string $format): avadim\FastExcelWriter\Excel
Set the default date and time format of the workbook (the '@datetime' style, used for DateTime values).
Parameters
string $format-- e.g.'DD.MM.YYYY HH:MM'
setDefaultFont()
public function setDefaultFont(array $fontOptions): avadim\FastExcelWriter\Excel
Set default font options
Parameters
array $fontOptions
setDefaultFontName()
public function setDefaultFontName(string $fontName): avadim\FastExcelWriter\Excel
Set default font name
Parameters
string $fontName
setDefaultFormat()
public function setDefaultFormat(string $formatName, string $format): avadim\FastExcelWriter\Excel
Set a format of the workbook which overrides the format of the locale.
Parameters
string $formatName-- format name, e.g.'date','@date','DATETIME'string $format-- format pattern, e.g.'DD.MM.YYYY'
setDefaultLocale()
public function setDefaultLocale()
Set default locale from the current environment
Parameters
None
setDefaultStyle()
public function setDefaultStyle(array $style): avadim\FastExcelWriter\Excel
Set default style
Parameters
array $style
setDefaultTimeFormat()
public function setDefaultTimeFormat(string $format): avadim\FastExcelWriter\Excel
Set the default time format of the workbook (the '@time' style).
Parameters
string $format-- e.g.'HH:MM'
setDescription()
public function setDescription(?string $description = ''): avadim\FastExcelWriter\Excel
Set the description of the document
Parameters
string|null $description
setFileName()
public function setFileName(string $fileName): avadim\FastExcelWriter\Excel
Sets default filename for saving
Parameters
string $fileName
setKeywords()
public function setKeywords($keywords): avadim\FastExcelWriter\Excel
Set the keywords of the document
Parameters
string|array $keywords
setLocale()
public function setLocale(string $locale,
?string $dir = null): avadim\FastExcelWriter\Excel
Set locale information
Parameters
string $localestring|null $dir
setMetaAuthor()
public function setMetaAuthor(?string $author = ''): avadim\FastExcelWriter\Excel
Set metadata 'author'
Parameters
string|null $author
setMetaCompany()
public function setMetaCompany(?string $company = ''): avadim\FastExcelWriter\Excel
Set metadata 'company'
Parameters
string|null $company
setMetadata()
public function setMetadata($key, $value): avadim\FastExcelWriter\Excel
Set metadata
Parameters
$key$value
setMetaDescription()
public function setMetaDescription(?string $description = ''): avadim\FastExcelWriter\Excel
Set metadata 'description'
Parameters
string|null $description
setMetaKeywords()
public function setMetaKeywords($keywords): avadim\FastExcelWriter\Excel
Set metadata 'keywords'
Parameters
mixed $keywords
setMetaSubject()
public function setMetaSubject(?string $subject = ''): avadim\FastExcelWriter\Excel
Set metadata 'subject'
Parameters
string|null $subject
setMetaTitle()
public function setMetaTitle(?string $title = ''): avadim\FastExcelWriter\Excel
Set metadata 'title'
Parameters
string|null $title
setR1C1()
public function setR1C1(bool $option = true): avadim\FastExcelWriter\Excel
Set R1C1 notation mode
Parameters
bool $option
setRightToLeft()
public function setRightToLeft(bool $isRightToLeft)
Set right-to-left orientation
Parameters
bool $isRightToLeft
setSharedString()
public function setSharedString(bool $option = true): avadim\FastExcelWriter\Excel
Set the usage of shared strings
Parameters
bool $option
setSubject()
public function setSubject(?string $subject = ''): avadim\FastExcelWriter\Excel
Set the subject of the document
Parameters
string|null $subject
setTitle()
public function setTitle(?string $title = ''): avadim\FastExcelWriter\Excel
Set the title of the document
Parameters
string|null $title
sheet()
public function sheet($index): SheetWriter
Returns sheet by number or name of sheet.Return the first sheet if number or name omitted
Parameters
int|string|null $index-- - number or name of sheet
store()
public function store($disk, $path): bool
Store file to specified disk
Parameters
$disk$path
unprotect()
public function unprotect(): avadim\FastExcelWriter\Excel
Unprotect workbook
Parameters
None
writeData()
public function writeData($data): ExcelWriter
Write data to the current sheet. Accepts any iterable (array, Collection, LazyCollection, Model::cursor(), a generator, ...) or a callable that returns an iterable
Parameters
iterable|callable $data