You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can also do a more complex query with select, joins, where conditions etc. Just like with any Export object, you can pass any data via the constructor (or setters).
In the controller you can pass any required data to the export.
71
+
72
+
```php
73
+
return Excel::download(new UsersExport('NL'));
74
+
```
75
+
41
76
### Custom collections
42
77
43
-
If you are not using Eloquent or having another datasource (e.g. an API, MongoDB, Cache, ...) you can also return a custom collection:
78
+
If you are not using Eloquent or having another datasource (e.g. an API, MongoDB, Cache, ...) you can also return a
79
+
custom collection:
44
80
45
81
```php
46
82
class InvoicesExport implements FromCollection
@@ -96,9 +132,11 @@ class InvoicesExport implements FromArray
96
132
97
133
## Query
98
134
99
-
In the previous examples, we did the query inside the export class. While this is a good solution for small exports, for bigger exports this will come at a hefty performance price.
135
+
In the previous examples, we did the query inside the export class. While this is a good solution for small exports, for
136
+
bigger exports this will come at a hefty performance price.
100
137
101
-
By using the `FromQuery` concern, we can prepare a query for an export. Behind the scenes this query is executed in chunks.
138
+
By using the `FromQuery` concern, we can prepare a query for an export. Behind the scenes this query is executed in
139
+
chunks to limit the amount of models held in memory.
102
140
103
141
In the `InvoicesExport` class, add the `FromQuery` concern and return a query. Be sure to not `->get()` the results!
104
142
@@ -154,10 +192,10 @@ It will convert an HTML table into an Excel spreadsheet. For example; `exports/u
154
192
</thead>
155
193
<tbody>
156
194
@foreach($users as $user)
157
-
<tr>
158
-
<td>{{ $user->name }}</td>
159
-
<td>{{ $user->email }}</td>
160
-
</tr>
195
+
<tr>
196
+
<td>{{ $user->name }}</td>
197
+
<td>{{ $user->email }}</td>
198
+
</tr>
161
199
@endforeach
162
200
</tbody>
163
201
</table>
@@ -167,7 +205,8 @@ It will convert an HTML table into an Excel spreadsheet. For example; `exports/u
167
205
168
206
Exports can be created from a PHP generator class, by using the `FromGenerator` concern.
169
207
170
-
A generator allows you to write code that uses foreach to iterate over a set of data without needing to build an array in memory.
208
+
A generator allows you to write code that uses foreach to iterate over a set of data without needing to build an array
209
+
in memory.
171
210
172
211
```php
173
212
namespace App\Exports;
@@ -186,3 +225,35 @@ class DataExport implements FromGenerator
186
225
}
187
226
}
188
227
```
228
+
229
+
## Generic data manipulations
230
+
231
+
### Strict null comparison
232
+
233
+
If you want your `0` values to be actual `0` values in your Excel sheet instead of `null` (empty cells), you can use `WithStrictNullComparison`.
234
+
235
+
```php
236
+
use Maatwebsite\Excel\Concerns\WithStrictNullComparison;
237
+
238
+
class UsersExport implements FromCollection, WithStrictNullComparison
239
+
```
240
+
241
+
### Custom start cell
242
+
243
+
The default start cell is A1. Implementing the `WithCustomStartCell` concern in your export class allows you to specify a custom start cell.
244
+
245
+
```php
246
+
use Maatwebsite\Excel\Concerns\WithCustomStartCell;
247
+
248
+
class UsersExport implements FromCollection, WithCustomStartCell
249
+
{
250
+
public function startCell(): string
251
+
{
252
+
return 'B2';
253
+
}
254
+
}
255
+
```
256
+
257
+
:::warning
258
+
WithCustomStartCell is only supported for FromCollection exports.
0 commit comments