From b0169dd669ee22a1a18322011b9ec49abc9a5a65 Mon Sep 17 00:00:00 2001 From: Kevin Bui Date: Fri, 27 Jun 2025 14:47:22 +1000 Subject: [PATCH 1/2] Create the headings page. --- 3.1/exports/headings.md | 46 +++++++++++++++++++++++++++++++++++++++++ 3.1/exports/mapping.md | 43 -------------------------------------- 2 files changed, 46 insertions(+), 43 deletions(-) create mode 100644 3.1/exports/headings.md diff --git a/3.1/exports/headings.md b/3.1/exports/headings.md new file mode 100644 index 0000000..9c7e283 --- /dev/null +++ b/3.1/exports/headings.md @@ -0,0 +1,46 @@ +# Headings + +[[toc]] + +## Adding a heading row + +A heading row can easily be added by adding the `WithHeadings` concern. The heading row will be added +as very first row of the sheet. + +```php + +use Maatwebsite\Excel\Concerns\FromQuery; +use Maatwebsite\Excel\Concerns\WithHeadings; + +class InvoicesExport implements FromQuery, WithHeadings +{ + public function headings(): array + { + return [ + '#', + 'User', + 'Date', + ]; + } +} +``` + +If you need to have multiple heading rows, you can return multiple rows from the `headings()` method: + + +```php + +use Maatwebsite\Excel\Concerns\FromQuery; +use Maatwebsite\Excel\Concerns\WithHeadings; + +class InvoicesExport implements FromQuery, WithHeadings +{ + public function headings(): array + { + return [ + ['First row', 'First row'], + ['Second row', 'Second row'], + ]; + } +} +``` \ No newline at end of file diff --git a/3.1/exports/mapping.md b/3.1/exports/mapping.md index 295035c..39706a5 100644 --- a/3.1/exports/mapping.md +++ b/3.1/exports/mapping.md @@ -65,49 +65,6 @@ class InvoicesExport implements FromQuery, WithMapping } ``` -## Adding a heading row - -A heading row can easily be added by adding the `WithHeadings` concern. The heading row will be added -as very first row of the sheet. - -```php - -use Maatwebsite\Excel\Concerns\FromQuery; -use Maatwebsite\Excel\Concerns\WithHeadings; - -class InvoicesExport implements FromQuery, WithHeadings -{ - public function headings(): array - { - return [ - '#', - 'User', - 'Date', - ]; - } -} -``` - -If you need to have multiple heading rows, you can return multiple rows from the `headings()` method: - - -```php - -use Maatwebsite\Excel\Concerns\FromQuery; -use Maatwebsite\Excel\Concerns\WithHeadings; - -class InvoicesExport implements FromQuery, WithHeadings -{ - public function headings(): array - { - return [ - ['First row', 'First row'], - ['Second row', 'Second row'], - ]; - } -} -``` - ## Prepare rows If you need to prepare rows before appending these rows to sheet, you can add method `prepareRows` to your export class. This method will be called before flattening the query output and calling `map()`. From 53444dabe0ff658e574ca9b532e15c1e4dd3b3eb Mon Sep 17 00:00:00 2001 From: Kevin Bui Date: Sun, 29 Jun 2025 14:05:10 +1000 Subject: [PATCH 2/2] Add a nav item named headings to the side bar. --- .vuepress/3.1.js | 1 + 1 file changed, 1 insertion(+) diff --git a/.vuepress/3.1.js b/.vuepress/3.1.js index 9e41f2a..049d48a 100644 --- a/.vuepress/3.1.js +++ b/.vuepress/3.1.js @@ -35,6 +35,7 @@ module.exports = [ 'queued', 'multiple-sheets', 'mapping', + 'headings', 'column-formatting', 'settings', 'drawings',