Styles, Number Formats, and Layout
Apply reusable styles, column formats, widths, row heights, merged cells, filters, and frozen panes.
Updated
namedStyle()styleHeader()rangeStyle()currencyColumns()autoWidth()freezePanes()autoFilterRange()What you will learn
- Create reusable named styles.
- Format values without turning them into text.
- Make large reports easier to scan and navigate.
Define and reuse named styles#
$workbook
->namedStyle('title', [
'font' => ['bold' => true, 'size' => 18, 'color' => '#FFFFFF'],
'fill' => ['color' => '#146C5B'],
'alignment' => ['horizontal' => 'center'],
])
->title('Quarterly Sales', ['style' => 'title']);Style scopes intentionally#
$workbook
->styleHeader([
'font' => ['bold' => true, 'color' => '#FFFFFF'],
'fill' => ['color' => '#0E5144'],
])
->columnStyle('A', ['font' => ['bold' => true]])
->rowStyle(5, ['fill' => ['color' => '#FFF4E8']])
->cellStyle('D12', ['font' => ['color' => '#B42318']])
->rangeStyle('A2:F100', ['borders' => ['all' => ['style' => 'thin']]]);Apply number formats by semantic column#
$workbook
->currencyColumns(['Amount'], '$')
->percentageColumns(['Margin'])
->integerColumns(['Quantity'])
->decimalColumns(['Weight'], 3)
->dateStyleColumns(['Order Date'], 'yyyy-mm-dd')
->datetimeStyleColumns(['Created At'], 'yyyy-mm-dd hh:mm:ss');Improve navigation and scanning#
$workbook
->freezePanes(rows: 1, columns: 2)
->autoFilterRange('A1:H5000')
->columnWidths(['A' => 16, 'B' => 28])
->rowHeight(1, 30)
->autoWidth(true, ['min' => 10, 'max' => 42]);Was this guide useful?Use GitHub issues for corrections, missing examples, or unclear behavior.
Open an issue