Skip to content

Class \avadim\FastExcelWriter\Sheet



__construct()


public function __construct(string $sheetName)
Sheet constructor

Parameters

  • string $sheetName

addCellStyle()


public function addCellStyle(string $cellAddr, $style): Sheet
Add additional styles to a cell

Parameters

  • string $cellAddr
  • array|Style $style

addChart()


public function addChart(string $range, 
                         avadim\FastExcelWriter\Charts\Chart $chart): Sheet
Add a chart object to the specified range of cells

Parameters

  • string $range – Set the position where the chart should appear in the worksheet
  • Chart $chart – Chart object

addConditionalFormatting()


public function addConditionalFormatting(string $range, $conditionals): Sheet
Add a conditional formatting object to the specified range of cells

Parameters

  • string $range
  • Conditional|Conditional[] $conditionals

addDataValidation()


public function addDataValidation(string $range, 
                                  avadim\FastExcelWriter\DataValidation\DataValidation $validation): Sheet
Add a data validation object to the specified range of cells

Parameters

  • string $range
  • DataValidation $validation

addImage()


public function addImage(string $cell, string $imageFile, 
                         ?array $imageStyle = []): Sheet
Add an image to the sheet from a local file, URL or image string in base64

Parameters

  • string $cell – Cell address
  • string $imageFile – URL, local path or image string in base64
  • array|null $imageStyle – ['width' => ..., 'height' => ..., 'hyperlink' => ...]

Examples

$sheet->addImage('A1', 'path/to/file');
$sheet->addImage('A1', 'path/to/file', ['width' => 100]);

addNamedRange()


public function addNamedRange(string $range, string $name): Sheet
Define named range

Parameters

  • string $range
  • string $name

Examples

$sheet->addNamedRange('B3:C5', 'Demo');

addNote()


public function addNote($cell, $comment, array $noteStyle = []): Sheet
Add a note to the sheet

Parameters

  • string|mixed $cell
  • string|array|null $comment
  • array $noteStyle

Examples

$sheet->addNote('A1', $noteText, $noteStyle);
$sheet->writeCell($cellValue)->addNote($noteText, $noteStyle);

addStyle()


public function addStyle(string $cellAddr, $style): Sheet
Alias for 'addCellStyle()'

Parameters

  • string $cellAddr
  • array|Style $style

allowAutoFilter()


public function allowAutoFilter(?bool $allow = true): Sheet
AutoFilters should be allowed to operate when the sheet is protected

Parameters

  • bool|null $allow

allowDeleteColumns()


public function allowDeleteColumns(?bool $allow = true): Sheet
Deleting columns should be allowed when the sheet is protected

Parameters

  • bool|null $allow

allowDeleteRows()


public function allowDeleteRows(?bool $allow = true): Sheet
Deleting rows should be allowed when the sheet is protected

Parameters

  • bool|null $allow

allowEditObjects()


public function allowEditObjects(?bool $allow = true): Sheet
Objects are allowed to be edited when the sheet is protected

Parameters

  • bool|null $allow

allowEditScenarios()


public function allowEditScenarios(?bool $allow = true): Sheet
Scenarios are allowed to be edited when the sheet is protected

Parameters

  • bool|null $allow

allowFormatCells()


public function allowFormatCells(?bool $allow = true): Sheet
Formatting cells should be allowed when the sheet is protected

Parameters

  • bool|null $allow

allowFormatColumns()


public function allowFormatColumns(?bool $allow = true): Sheet
Formatting columns should be allowed when the sheet is protected

Parameters

  • bool|null $allow

allowFormatRows()


public function allowFormatRows(?bool $allow = true): Sheet
Formatting rows should be allowed when the sheet is protected

Parameters

  • bool|null $allow

allowInsertColumns()


public function allowInsertColumns(?bool $allow = true): Sheet
Inserting columns should be allowed when the sheet is protected

Parameters

  • bool|null $allow


public function allowInsertHyperlinks(?bool $allow = true): Sheet
Inserting hyperlinks should be allowed when the sheet is protected

Parameters

  • bool|null $allow

allowInsertRows()


public function allowInsertRows(?bool $allow = true): Sheet
Inserting rows should be allowed when the sheet is protected

Parameters

  • bool|null $allow

allowPivotTables()


public function allowPivotTables(?bool $allow = true): Sheet
PivotTables should be allowed to operate when the sheet is protected

Parameters

  • bool|null $allow

allowSelectCells()


public function allowSelectCells(?bool $allow = true): Sheet
Selection of any cells should be allowed when the sheet is protected

Parameters

  • bool|null $allow

allowSelectLockedCells()


public function allowSelectLockedCells(?bool $allow = true): Sheet
Selection of locked cells should be allowed when the sheet is protected

Parameters

  • bool|null $allow

allowSelectUnlockedCells()


public function allowSelectUnlockedCells(?bool $allow = true): Sheet
Selection of unlocked cells should be allowed when the sheet is protected

Parameters

  • bool|null $allow

allowSort()


public function allowSort(?bool $allow = true): Sheet
Sorting should be allowed when the sheet is protected

Parameters

  • bool|null $allow

applyAlignLeft()


public function applyAlignLeft(): Sheet
Apply left alignment to content

Parameters

None


applyAlignRight()


public function applyAlignRight(): Sheet
Apply right alignment to content

Parameters

None


applyBgColor()


public function applyBgColor(string $color, ?string $pattern = null): Sheet
Alias of 'applyFillColor()'

Parameters

  • string $color
  • string|null $pattern

applyBorder()


public function applyBorder(string $style, ?string $color = '#000000'): Sheet
Sets all borders style

Parameters

  • string $style
  • string|null $color

applyBorderBottom()


public function applyBorderBottom(string $style, 
                                  ?string $color = '#000000'): Sheet
Apply bottom border style and color to the selected area

Parameters

  • string $style
  • string|null $color

applyBorderLeft()


public function applyBorderLeft(string $style, 
                                ?string $color = '#000000'): Sheet
Apply left border style and color to the selected area

Parameters

  • string $style
  • string|null $color

applyBorderRight()


public function applyBorderRight(string $style, 
                                 ?string $color = '#000000'): Sheet
Apply right border style and color to the selected area

Parameters

  • string $style
  • string|null $color

applyBorderTop()


public function applyBorderTop(string $style, 
                               ?string $color = '#000000'): Sheet
Apply top border style and color to the selected area

Parameters

  • string $style
  • string|null $color

applyColor()


public function applyColor(string $color): Sheet
Alias of 'setFontColor()'

Parameters

  • string $color

applyConditionalFormatting()


public function applyConditionalFormatting($conditionals): Sheet
Apply conditional formatting to the selected area

Parameters

  • Conditional|Conditional[] $conditionals

applyDataValidation()


public function applyDataValidation(avadim\FastExcelWriter\DataValidation\DataValidation $validation): Sheet
Apply data validation to the selected area

Parameters

  • DataValidation $validation

applyFillColor()


public function applyFillColor(string $color, ?string $pattern = null): Sheet
Fill background color

Parameters

  • string $color
  • string|null $pattern

applyFillGradient()


public function applyFillGradient(string $color1, string $color2, 
                                  ?int $degree = null): Sheet
Fill background by gradient

Parameters

  • string $color1
  • string $color2
  • int|null $degree

applyFont()


public function applyFont(string $fontName, ?int $fontSize = null, 
                          ?string $fontStyle = null, 
                          ?string $fontColor = null): Sheet
Apply font settings to the selected area

Parameters

  • string $fontName
  • int|null $fontSize
  • string|null $fontStyle
  • string|null $fontColor

applyFontColor()


public function applyFontColor(string $fontColor): Sheet
Apply font color to the selected area

Parameters

  • string $fontColor

applyFontName()


public function applyFontName(string $fontName): Sheet
Apply font name to the selected area

Parameters

  • string $fontName

applyFontSize()


public function applyFontSize(float $fontSize): Sheet
Apply font size to the selected area

Parameters

  • float $fontSize

applyFontStyle()


public function applyFontStyle(string $fontStyle): Sheet
Apply font style (bold, italic, etc.) to the selected area

Parameters

  • string $fontStyle

applyFontStyleBold()


public function applyFontStyleBold(): Sheet
Apply bold font style to the selected area

Parameters

None


applyFontStyleItalic()


public function applyFontStyleItalic(): Sheet
Apply italic font style to the selected area

Parameters

None


applyFontStyleStrikethrough()


public function applyFontStyleStrikethrough(): Sheet
Apply strikethrough font style to the selected area

Parameters

None


applyFontStyleUnderline()


public function applyFontStyleUnderline(?bool $double = false): Sheet
Apply underline font style to the selected area

Parameters

  • bool|null $double

applyFormat()


public function applyFormat($format): Sheet
Set value format for the selected area

Parameters

  • string|array $format

applyHide()


public function applyHide(?bool $hide = true): Sheet
Set hidden protection for the selected area

Parameters

  • bool|null $hide

applyIndentDistributed()


public function applyIndentDistributed(int $indent): Sheet
Set distributed indent for the selected area

Parameters

  • int $indent

applyIndentLeft()


public function applyIndentLeft(int $indent): Sheet
Set left indent for the selected area

Parameters

  • int $indent

applyIndentRight()


public function applyIndentRight(int $indent): Sheet
Set right indent for the selected area

Parameters

  • int $indent

applyInnerBorder()


public function applyInnerBorder(string $style, 
                                 ?string $color = '#000000'): Sheet
Apply inner border style and color to the selected area

Parameters

  • string $style
  • string|null $color

applyNamedRange()


public function applyNamedRange(string $name): Sheet
Apply named range to the selected area

Parameters

  • string $name

applyOuterBorder()


public function applyOuterBorder(string $style, 
                                 ?string $color = '#000000'): Sheet
Apply outer border style and color to the selected area

Parameters

  • string $style
  • string|null $color

applyRowHeight()


public function applyRowHeight(float $height): Sheet
Sets height to the current row

Parameters

  • float $height

applyRowOutlineLevel()


public function applyRowOutlineLevel(int $outlineLevel): Sheet
Set outline level for the current row

Parameters

  • int $outlineLevel

applyStyle()


public function applyStyle($style): Sheet
Apply the style

Parameters

  • array|Style $style

applyTextAlign()


public function applyTextAlign(string $textAlign, 
                               ?string $verticalAlign = null): Sheet
Apply horizontal alignment to the selected area

Parameters

  • string $textAlign
  • string|null $verticalAlign

applyTextCenter()


public function applyTextCenter(): Sheet
Apply horizontal and vertical center alignment to the selected area

Parameters

None


applyTextColor()


public function applyTextColor(string $color): Sheet
Set text color for the selected area

Parameters

  • string $color

applyTextRotation()


public function applyTextRotation(int $degrees): Sheet
Set text rotation for the selected area

Parameters

  • int $degrees

applyTextWrap()


public function applyTextWrap(?bool $textWrap = true): Sheet
Set text wrap for the selected area

Parameters

  • bool|null $textWrap

applyUnlock()


public function applyUnlock(?bool $unlock = true): Sheet
Set unlock protection for the selected area

Parameters

  • bool $unlock

applyVerticalAlign()


public function applyVerticalAlign(string $verticalAlign): Sheet
Apply vertical alignment to the selected area

Parameters

  • string $verticalAlign

beginArea()


public function beginArea(?string $cellAddress = null): Area
Begin a new area

Parameters

  • string|null $cellAddress – Upper left cell of area

beginOutlineLevel()


public function beginOutlineLevel(?bool $collapsed = false): Sheet
Start a new outline level for rows

Parameters

  • bool|null $collapsed

cell()


public function cell($cellAddress): Sheet
Select a single cell or cell range in the current row

Parameters

  • string|array $cellAddress

Examples

$sheet->cell('B5')->writeCell($value);
$sheet->cell('B5:C7')->applyBorder('thin');
$sheet->cell(['col' => 2, 'row' => 5])->applyUnlock();
$sheet->cell([2, 5])->applyColor($color);

clearAreas()


public function clearAreas(): Sheet
Clear all defined areas

Parameters

None


endAreas()


public function endAreas(): Sheet

Parameters

None


endOutlineLevel()


public function endOutlineLevel(): Sheet
End the current outline level for rows

Parameters

None


getCharts()


public function getCharts(): array
Get all charts in the sheet

Parameters

None


getColAttributes()


public function getColAttributes(): array
Get columns attributes

Parameters

None


getConditionalFormatting()


public function getConditionalFormatting(): array
Get all conditional formatting in the sheet

Parameters

None


getCurrentCell()


public function getCurrentCell(): string
Returns address of the current cell

Parameters

None


getCurrentCol()


public function getCurrentCol(): string
Returns current column letter

Parameters

None


getCurrentColId()


public function getCurrentColId(): int
Get current column index (0-based)

Parameters

None


getCurrentRow()


public function getCurrentRow(): int
Returns current row number

Parameters

None


getCurrentRowId()


public function getCurrentRowId(): int
Get current row index (0-based)

Parameters

None


getDataValidations()


public function getDataValidations(): array
Get all data validations in the sheet

Parameters

None


getDefaultStyle()


public function getDefaultStyle(): array
Returns default style

Parameters

None


getHeaderFooterOptions()


public function getHeaderFooterOptions(): array
Get header and footer options

Parameters

None



public function getHyperlinks(): array
Returns added hyperlinks

Parameters

None


getImages()


public function getImages(): array
Get all images in the sheet

Parameters

None


getLastCell()


public function getLastCell(?bool $absolute = false): string
Get address of the last touched cell

Parameters

  • bool|null $absolute

getLastRange()


public function getLastRange(?bool $absolute = false): string
Get address of the last touched range

Parameters

  • bool|null $absolute

getMergedCells()


public function getMergedCells(): array
Returns merged cells

Parameters

None


getName()


public function getName(): string
Get sheet name

Parameters

None


getNamedRanges()


public function getNamedRanges(): array
Returns named ranges with full addresses

Parameters

None


getNotes()


public function getNotes(): array
Get all notes in the sheet

Parameters

None


getOutlineLevel()


public function getOutlineLevel(): int
Get the current outline level for rows

Parameters

None


isName()


public function isName(string $name): bool
Case-insensitive name checking

Parameters

  • string $name

isRightToLeft()


public function isRightToLeft(): bool
Check if the sheet is right-to-left

Parameters

None


makeArea()


public function makeArea(string $range): Area
Make area for writing

Parameters

  • string $range – A1:Z9 or R1C1:R9C28

mergeCells()


public function mergeCells($rangeSet, ?int $mergeFlag = 0): Sheet
Merge cells

Parameters

  • array|string|int $rangeSet
  • int|null $mergeFlag – Action in case of intersection: 0 - exception; 1 - replace; 2 - keep; -1 - skip intersection check

Examples

$sheet->mergeCells('A1:C3');
$sheet->mergeCells(['A1:B2', 'C1:D2']);
$sheet->mergeCells('B5:C7', $value, Sheet:MERGE_NO_CHECK); // don't check for intersection of merged cells

mergeRelCells()


public function mergeRelCells($rangeSet): Sheet
Merge relative cells

Parameters

  • array|string|int $rangeSet

Examples

$sheet->mergeCells('C3:E8');
$sheet->mergeCells(3); // 3 columns of current row, equivalent of mergeCells('A5:C5') if current row is 5
$sheet->mergeCells(['RC3:RC5', 'RC6:RC7']); // equivalent of mergeCells(['C7:E7', 'F7:G7']) if current row is 7

nextCell()


public function nextCell(): Sheet
Move pointer to the next cell

Parameters

None


nextRow()


public function nextRow($style, ?bool $forceRow = false): Sheet
Move to the next row

Parameters

  • array|Style|null $style
  • bool|null $forceRow

pageFitToHeight()


public function pageFitToHeight($numPage): Sheet
Set page to fit to height

Parameters

  • int|string|null $numPage

pageFitToWidth()


public function pageFitToWidth($numPage): Sheet
Set page to fit to width

Parameters

  • int|string|null $numPage


public function pageFooter($footer): Sheet
Set the footer for all pages

Parameters

  • string|array $footer

pageFooterEven()


public function pageFooterEven($footer): Sheet
Set footer for even pages

Parameters

  • string|array $footer

pageFooterFirst()


public function pageFooterFirst($footer): Sheet
Set the footer for the first page

Parameters

  • string|array $footer

pageFooterOdd()


public function pageFooterOdd(string $footer): Sheet
Set footer for odd pages

Parameters

  • string $footer


public function pageHeader($header): Sheet
Set page header for all pages

Parameters

  • string|array $header

pageHeaderEven()


public function pageHeaderEven($header): Sheet
Set header for even pages

Parameters

  • string|array $header

pageHeaderFirst()


public function pageHeaderFirst($header): Sheet
Set the header for the first page

Parameters

  • string|array $header

pageHeaderFooter()


public function pageHeaderFooter(?string $header, ?string $footer): Sheet
Set the center header and footer for all pages

Parameters

  • string|null $header
  • string|null $footer

pageHeaderOdd()


public function pageHeaderOdd($header): Sheet
Set header for odd pages

Parameters

  • string|array $header

pageLandscape()


public function pageLandscape(): Sheet
Set page orientation as Landscape

Parameters

None


pageMarginBottom()


public function pageMarginBottom($value): Sheet
Bottom Page Margin in mm|cm|in

Parameters

  • string|float $value

pageMarginFooter()


public function pageMarginFooter($value): Sheet
Footer Page Margin in mm|cm|in

Parameters

  • string|float $value

pageMarginHeader()


public function pageMarginHeader($value): Sheet
Header Page Margin in mm|cm|in

Parameters

  • string|float $value

pageMarginLeft()


public function pageMarginLeft($value): Sheet
Left Page Margin in mm|cm|in

Parameters

  • string|float $value

pageMarginRight()


public function pageMarginRight($value): Sheet
Right page margin in mm|cm|in

Parameters

  • string|float $value

pageMargins()


public function pageMargins(array $margins): Sheet
Page margins for a sheet or a custom sheet view in mm|cm|in

Parameters

  • array $margins

pageMarginTop()


public function pageMarginTop($value): Sheet
Top Page Margin in mm|cm|in

Parameters

  • string|float $value

pageOrientationLandscape()


public function pageOrientationLandscape(): Sheet
Set page orientation as Landscape, alias of pageLandscape()

Parameters

None


pageOrientationPortrait()


public function pageOrientationPortrait(): Sheet
Set page orientation as Portrait, alias of pagePortrait()

Parameters

None


pagePaperHeight()


public function pagePaperHeight($paperHeight): Sheet
Height of custom paper as a number followed by a unit identifier mm|cm|in (ex: 297mm, 11in)

Parameters

  • string|float|int $paperHeight

pagePaperSize()


public function pagePaperSize(int $paperSize): Sheet
Set Paper size (when paperHeight and paperWidth are specified, paperSize should be ignored)

Parameters

  • int $paperSize

pagePaperSizeA3()


public function pagePaperSizeA3(): Sheet
Set Paper Size to A3 (when paperHeight and paperWidth are specified, paperSize should be ignored)

Parameters

None


pagePaperSizeA4()


public function pagePaperSizeA4(): Sheet
Set Paper Size to A4 (when paperHeight and paperWidth are specified, paperSize should be ignored)

Parameters

None


pagePaperSizeLegal()


public function pagePaperSizeLegal(): Sheet
Set Paper Size to Legal (when paperHeight and paperWidth are specified, paperSize should be ignored)

Parameters

None


pagePaperSizeLetter()


public function pagePaperSizeLetter(): Sheet
Set Paper Size to Letter (when paperHeight and paperWidth are specified, paperSize should be ignored)

Parameters

None


pagePaperWidth()


public function pagePaperWidth($paperWidth): Sheet
Width of custom paper as a number followed by a unit identifier mm|cm|in (ex: 21cm, 8.5in)

Parameters

  • string|float|int $paperWidth

pagePortrait()


public function pagePortrait(): Sheet
Set page orientation as Portrait

Parameters

None


pageScale()


public function pageScale(int $scale): Sheet
Set page scale

Parameters

  • int $scale

protect()


public function protect(?string $password = null): Sheet
Protect sheet

Parameters

  • string|null $password

setActiveCell()


public function setActiveCell($cellAddress): Sheet
Set active cell

Parameters

  • $cellAddress

setAutoFilter()


public function setAutoFilter($rowOrCell, ?int $col = 1): Sheet
Set auto filter

Parameters

  • mixed|null $rowOrCell
  • int|null $col

Examples

$sheet->setAutoFilter(2);
$sheet->setAutoFilter('B2');
$sheet->setAutoFilter('B2:C4');

setBgColor()


public function setBgColor(string $cellAddr, string $color): Sheet
Set background color for the specific cell or range

Parameters

  • string $cellAddr
  • string $color

setBottomNodesOptions()


public function setBottomNodesOptions(string $node, array $options): Sheet
Set multiple options for a bottom node

Parameters

  • string $node
  • array $options

setCellStyle()


public function setCellStyle(string $cellAddress, $style, 
                             ?bool $mergeStyles = false): Sheet
Set style for the specific cell

Parameters

  • string $cellAddress – Cell address
  • array|Style $style – Style array or object
  • bool|null $mergeStyles – True - merge style with previous style for this cell (if exists)

setColAutoWidth()


public function setColAutoWidth($col): Sheet
Alias of setColWidthAuto($col)

Parameters

  • int|string|array $col – Column number or column letter (or array of these)

setColDataStyle()


public function setColDataStyle($colRange, $colStyle): Sheet
Set styles of column cells (colors, formats, etc.)

Styles are applied only to non-empty cells in a column and only take effect starting with the current row

Parameters

  • int|string|array $colRange
  • array|Style $colStyle

Examples

$sheet->setColDataStyle('B', ['width' = 20]); // style for cells of column 'B'
$sheet->setColDataStyle(2, ['width' = 20]); // 'B' is number 2 column
$sheet->setColDataStyle('B:D', ['width' = 'auto']); // options for range of columns
$sheet->setColDataStyle(['A', 'B', 'C'], $style); // options for several columns 'A', 'B' and 'C'

setColDataStyleArray()


public function setColDataStyleArray(array $colStyles): Sheet
Set style of column cells (colors, formats, etc.)

Styles are applied only to non-empty cells in a column and only take effect starting with the current row

Parameters

  • array $colStyles

Examples

$sheet->setColDataStyleArray(['B' => $style1, 'C' => $style2]); // options for columns 'B' and 'C'

setColFormat()


public function setColFormat($col, $format): Sheet
Set a format of single or multiple column(s)

Parameters

  • int|string|array $col – Column number or column letter (or array of these)
  • mixed $format

setColFormats()


public function setColFormats(array $formats): Sheet
Set formats of columns

Parameters

  • array $formats

setColFormula()


public function setColFormula($col, string $formula): Sheet
Set formula for single or multiple column(s)

Parameters

  • int|string|array $col – Column number or column letter (or array of these)
  • string $formula

setColHidden()


public function setColHidden($col): Sheet
Set a column as hidden

Parameters

  • int|string|array $col – Column number or column letter (or array of these)

setColMinWidth()


public function setColMinWidth($col, $width): Sheet
Setting a minimal column's width

Parameters

  • int|string|array $col – Column number or column letter (or array of these)
  • int|float|string $width

setColMinWidths()


public function setColMinWidths(array $widths): Sheet
Setting a multiple column's minimal width

Parameters

  • array $widths

Examples

$sheet->setColWidths(['B' => 10, 'C' => 'auto', 'E' => 30, 'F' => 40]);

setColOutlineLevel()


public function setColOutlineLevel($col, int $outlineLevel): Sheet
Set a column outline level

Parameters

  • int|string|array $col – Column number or column letter (or array of these)
  • int $outlineLevel

setColStyle()


public function setColStyle($colRange, $style): Sheet
Set style of single or multiple column(s)

Styles are applied to the entire sheet column(s) (even if it is empty)

Parameters

  • int|string|array $colRange – Column number or column letter or column range (or array of these)
  • array|Style $style

Examples

$sheet->setColStyle('B', $style);
$sheet->setColStyle(2, $style); // 'B' is number 2 column
$sheet->setColStyle('C:F', $style);
$sheet->setColStyle(['A', 'B', 'C'], $style);

setColStyleArray()


public function setColStyleArray($colStyles): Sheet
Set styles of single or multiple column(s)

Styles are applied to the entire sheet column(s) (even if it is empty)

Parameters

  • array|Style $colStyles

Examples

$style1 = ['width' = 20];
$style2 = (new Style())->setColor('red');
$sheet->setColStyleArray(['B' => $style1, 'C' => $style2]);

setColVisible()


public function setColVisible($col, bool $val): Sheet
Show/hide a column

Parameters

  • int|string|array $col – Column number or column letter (or array of these)
  • bool $val

setColWidth()


public function setColWidth($col, $width, ?bool $min = false): Sheet
Set a width of single or multiple column(s)

Parameters

  • int|string|array $col – Column number or column letter (or array of these)
  • int|float|string $width
  • bool|null $min

setColWidthAuto()


public function setColWidthAuto($col): Sheet
Set auto width of single or multiple column(s)

Parameters

  • int|string|array $col – Column number or column letter (or array of these)

Examples

$sheet->setColWidthAuto(2);
$sheet->setColWidthAuto('B');
$sheet->setColWidthAuto(['B', 'C']);
$sheet->setColWidthAuto(['B:D']);

setColWidths()


public function setColWidths(array $widths, ?bool $min = false): Sheet
Setting a multiple column's width

Parameters

  • array $widths
  • bool|null $min

Examples

$sheet->setColWidths(['B' => 10, 'C' => 'auto', 'E' => 30, 'F' => 40]);

setDefaultFont()


public function setDefaultFont($font): Sheet
Set default font settings for the sheet

Parameters

  • string|array $font

setDefaultFontColor()


public function setDefaultFontColor(string $fontColor): Sheet
Set default font color

Parameters

  • string $fontColor

setDefaultFontName()


public function setDefaultFontName(string $fontName): Sheet
Set default font name for the sheet

Parameters

  • string $fontName

setDefaultFontSize()


public function setDefaultFontSize(int $fontSize): Sheet
Set default font size for the sheet

Parameters

  • int $fontSize

setDefaultFontStyle()


public function setDefaultFontStyle(string $fontStyle): Sheet
Set default font style (bold, italic, etc.) for the sheet

Parameters

  • string $fontStyle

setDefaultFontStyleBold()


public function setDefaultFontStyleBold(): Sheet
Set default font style as bold for the sheet

Parameters

None


setDefaultFontStyleItalic()


public function setDefaultFontStyleItalic(): Sheet
Set default font style as italic

Parameters

None


setDefaultFontStyleStrikethrough()


public function setDefaultFontStyleStrikethrough(): Sheet
Set default font style as strikethrough

Parameters

None


setDefaultFontStyleUnderline()


public function setDefaultFontStyleUnderline(?bool $double = false): Sheet
Set default font style as underline

Parameters

  • bool|null $double

setDefaultStyle()


public function setDefaultStyle($style): Sheet
Sets default style

Parameters

  • array|Style $style

setFormat()


public function setFormat(string $cellAddr, string $format): Sheet
Set value format for the specific cell or range

Parameters

  • string $cellAddr
  • string $format

setFormula()


public function setFormula($cellAddress, $value, $style): Sheet
Set a formula to the single cell or to the cell range

Parameters

  • string|array $cellAddress
  • mixed $value
  • array|Style|null $style

Examples

$sheet->setFormula('B5', '=F23');
$sheet->setFormula('B5:C7', $formula, $style);
$sheet->setFormula(['col' => 2, 'row' => 5], '=R2C3+R3C4');
$sheet->setFormula([2, 5], '=SUM(A4:A18)');

setFreeze()


public function setFreeze($freezeRows, $freezeColumns): Sheet
Freeze rows/columns

Parameters

  • mixed $freezeRows
  • mixed $freezeColumns

Examples

$sheet->setFreeze(3, 3); // number rows and columns to freeze
$sheet->setFreeze('C3'); // left top cell of the free area

setFreezeColumns()


public function setFreezeColumns(int $freezeColumns): Sheet
Freeze columns

Parameters

  • int $freezeColumns – Number columns to freeze

setFreezeRows()


public function setFreezeRows(int $freezeRows): Sheet
Freeze rows

Parameters

  • int $freezeRows – Number rows to freeze

setName()


public function setName(string $sheetName): Sheet
Set sheet name

Parameters

  • string $sheetName

setOuterBorder()


public function setOuterBorder(string $range, $style): Sheet
Set outer border for the specific range

Parameters

  • string $range
  • string|array|Style $style

setPrintArea()


public function setPrintArea(string $range): Sheet
Set print area for the sheet

Parameters

  • string $range

setPrintCentered()


public function setPrintCentered(?bool $value = true): Sheet
Center the print area horizontally and vertically

Parameters

  • bool|null $value

setPrintGridlines()


public function setPrintGridlines(?bool $bool = true): Sheet
Show grid lines in the print area

Parameters

  • bool|null $bool

setPrintHorizontalCentered()


public function setPrintHorizontalCentered(?bool $value = true): Sheet
Center the print area horizontally

Parameters

  • bool|null $value

setPrintLeftColumns()


public function setPrintLeftColumns(string $range): Sheet
Set left columns to repeat on every printed page

Parameters

  • string $range

setPrintRowAndColumnHeading()


public function setPrintRowAndColumnHeading(?bool $bool = true): Sheet
Print row and column headings in the printout

Parameters

  • bool|null $bool

setPrintTitles()


public function setPrintTitles(?string $rowsAtTop, 
                               ?string $colsAtLeft = null): Sheet
Set rows to repeat at top and columns to repeat at left when printing

Parameters

  • string|null $rowsAtTop
  • string|null $colsAtLeft

setPrintTopRows()


public function setPrintTopRows(string $range): Sheet
Set top rows to repeat on every printed page

Parameters

  • string $range

setPrintVerticalCentered()


public function setPrintVerticalCentered(?bool $value = true): Sheet
Center the print area vertically

Parameters

  • bool|null $value

setRowDataStyle()


public function setRowDataStyle($rowRange, $style): Sheet
Style are applied only to non-empty cells in a row (or row range)

Parameters

  • int|string|array $rowRange
  • array|Style $style

Examples

$sheet->setRowDataStyle(3, ['height' = 20]); // options for row number 3
$sheet->setRowDataStyle('2:5', ['font-color' = '#f00']); // options for range of rows

setRowDataStyleArray()


public function setRowDataStyleArray(array $rowStyles): Sheet
Styles are applied only to non-empty cells in a rows

Parameters

  • array $rowStyles

Examples

$sheet->setRowDataStyleArray([3 => $style1, 5 => $style2]); // styles for rows 3 and 5

setRowHeight()


public function setRowHeight($rowNum, $height): Sheet
Height of a specific row

Parameters

  • $rowNum
  • $height

setRowHeights()


public function setRowHeights(array $heights): Sheet
Multiple rows height

Parameters

  • array $heights

setRowHidden()


public function setRowHidden($rowNum): Sheet
Hide a specific row

Parameters

  • int|array $rowNum

setRowOutlineLevel()


public function setRowOutlineLevel($rowNum, int $outlineLevel, 
                                   ?bool $collapsed = null): Sheet
Set an outline level for a specific row or range of rows

Parameters

  • int|array|string $rowNum
  • int $outlineLevel
  • bool|null $collapsed

Examples

setRowOutlineLevel(5, 1)
setRowOutlineLevel([5, 6, 7], 1)
setRowOutlineLevel('5:7', 1)

setRowStyle()


public function setRowStyle($rowRange, $style): Sheet
The style is applied to the entire sheet row (even if it is empty)

Parameters

  • int|string|array $rowRange
  • array|Style $style

Examples

$sheet->setRowStyle(3, ['height' = 20]); // options for row number 3
$sheet->setRowStyle('2:5', ['font-color' = '#f00']); // options for range of rows

setRowStyleArray()


public function setRowStyleArray(array $rowStyles): Sheet
Styles are applied to the entire sheet row (even if it is empty)

Parameters

  • array $rowStyles

Examples

$sheet->setRowStyleArray([3 => $style1, 5 => $style2]); // styles for rows 3 and 5

setRowVisible()


public function setRowVisible($rowNum, bool $visible): Sheet
Hide/show a specific row

Parameters

  • int|array $rowNum
  • bool $visible

setShowGridLines()


public function setShowGridLines(bool $flag): void
Turn on/off grid lines

Parameters

  • bool $flag

setStateHidden()


public function setStateHidden(): Sheet
Make the sheet hidden

Parameters

None


setStateVeryHidden()


public function setStateVeryHidden(): Sheet
Make the sheet very hidden

Parameters

None


setStateVisible()


public function setStateVisible(): Sheet
Make the sheet visible

Parameters

None


setStyle()


public function setStyle(string $cellAddress, $style, 
                         ?bool $mergeStyles = false): Sheet
Alias for 'setCellStyle()'

Parameters

  • string $cellAddress
  • array|Style $style
  • bool|null $mergeStyles

setTabColor()


public function setTabColor(?string $color): Sheet
Set color for the sheet tab

Parameters

  • string|null $color

setTopLeftCell()


public function setTopLeftCell($cellAddress): Sheet
Set the top left cell for writing

Parameters

  • string|array $cellAddress

Examples

$sheet->setTopLeftCell('C3');
$sheet->writeRow([11, 22, 33]); // Will be written in cells C3, D3, E3
$sheet->setTopLeftCell('G7');
$sheet->writeRow([44, 55]); // Will be written in cells G7, H7

setValue()


public function setValue($cellAddress, $value, $style): Sheet
Set a value to the single cell or to the cell range

Parameters

  • string|array $cellAddress
  • mixed $value
  • array|Style|null $style

Examples

$sheet->setValue('B5', $value);
$sheet->setValue('B5:C7', $value, $style);
$sheet->setValue(['col' => 2, 'row' => 5], $value, $style);
$sheet->setValue([2, 5], $value);

skipRow()


public function skipRow(?int $rowCount = 1): Sheet
Skip rows

Parameters

  • int|null $rowCount

unprotect()


public function unprotect(): Sheet
Unprotect sheet

Parameters

None


withLastCell()


public function withLastCell(): Sheet
Select the last written cell for applying

Parameters

None


withLastRow()


public function withLastRow(): Sheet
Select the last written row for applying

Parameters

None


withRange()


public function withRange($range): Sheet
Select a custom range for applying

Parameters

  • array|string $range

writeArray()


public function writeArray(array $rowArray = [], $rowStyle): Sheet
Write values from a two-dimensional array (alias of writeRows)

Parameters

  • array $rowArray – Array of rows
  • array|Style|null $rowStyle – Style applied to each row

writeArrayTo()


public function writeArrayTo($topLeftCell, array $data): Sheet
Write 2d array from the specified cell

Parameters

  • $topLeftCell
  • array $data

writeCell()


public function writeCell($value, ?array $styles = null): Sheet
Write value to the current cell and move a pointer to the next cell in the row

Parameters

  • mixed $value
  • array|null $styles

writeCells()


public function writeCells(array $values, ?array $cellStyles = null): Sheet
Write several values into cells of one row

Parameters

  • array $values
  • array|null $cellStyles

writeHeader()


public function writeHeader(array $header, ?array $rowStyle = null, 
                            ?array $colStyles = []): Sheet
Write a header row with optional styles and formats for columns

Parameters

  • array $header
  • array|null $rowStyle
  • array|null $colStyles

Examples

$sheet->writeHeader(['title1', 'title2', 'title3']); // texts for cells of header
$sheet->writeHeader(['title1' => '@text', 'title2' => 'YYYY-MM-DD', 'title3' => ['format' => ..., 'font' => ...]]); // texts and formats of columns
$sheet->writeHeader($cellValues, $rowStyle, $colStyles); // texts and formats of columns and options of row

writeRow()


public function writeRow(array $rowValues = [], $rowStyle, 
                         ?array $cellStyles = null): Sheet
Write values to the current row

Parameters

  • array $rowValues – Values of cells
  • array|Style|null $rowStyle – Style applied to the entire row
  • array|null $cellStyles – Styles of specified cells in the row

writeRows()


public function writeRows(array $rowArray = [], 
                          ?array $rowStyle = null): Sheet
Write several rows from a two-dimensional array

Parameters

  • array $rowArray – Array of rows
  • array|null $rowStyle – Style applied to each row

writeTo()


public function writeTo($cellAddress, $value, $style, 
                        ?int $mergeFlag = 0): Sheet
Write value to the specified cell and move a pointer to the next cell in the row

Parameters

  • string|array $cellAddress
  • mixed $value
  • array|Style|null $style
  • int|null $mergeFlag

Examples

$sheet->writeTo('B5', $value); // write to single cell
$sheet->writeTo(['col' => 2, 'row' => 5], $value); // address as an array
$sheet->writeTo([2, 5], $value); // address as an array
$sheet->writeTo('B5:C7', $value); // write a value to merged cells
$sheet->writeTo('B5:C7', $value, $styles, Sheet:MERGE_NO_CHECK); // don't check for intersection of merged cells