Skip to content

Create the headings page #244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vuepress/3.1.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module.exports = [
'queued',
'multiple-sheets',
'mapping',
'headings',
'column-formatting',
'settings',
'drawings',
Expand Down
46 changes: 46 additions & 0 deletions 3.1/exports/headings.md
Original file line number Diff line number Diff line change
@@ -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'],
];
}
}
```
43 changes: 0 additions & 43 deletions 3.1/exports/mapping.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()`.
Expand Down