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
By default, every element of the Collection becomes a row and every unprotected field of the Model becomes a cell.
72
74
No headers row is printed.
73
75
74
-
To change this behaviour, create a class which extends *Cyberduck\LaravelExcel\Contract\SerialiserInterface* and implements the methods *getHeaderRow()* and *getData(Model $data)*.
76
+
To change this behaviour, create a class extending *Cyberduck\LaravelExcel\Contract\SerialiserInterface*, implement the methods *getHeaderRow()* and *getData(Model $data)* and set this class on the excel object usint *setSerialiser()*.
77
+
```
78
+
$serialiser = new CustomSerialiser();
79
+
$excel = Exporter::make('Excel');
80
+
$excel->load($collection);
81
+
$excel->setSerialiser($serialiser);
82
+
return $excel->stream($yourFileName);
83
+
```
84
+
75
85
*getHeaderRow()* must return an array of string where every element is a cell of the first row. To not print the header row, simply return a void array *[]*.
76
86
*getData(Model $data)* must return an array of string, and every elements is a cell.
77
87
@@ -105,21 +115,21 @@ class ExampleSerialiser implements SerialiserInterface
105
115
```
106
116
107
117
## Import Excel
108
-
Add
118
+
Add
109
119
```
110
120
use Importer;
111
-
```
121
+
```
112
122
to your controller.
113
123
114
124
In your controler function, import an excel file.
115
125
```
116
126
$excel = Importer::make('Excel');
117
-
$excel->load($filepath);
118
-
$collection = $excel->getCollection();
127
+
$excel->load($filepath);
128
+
$collection = $excel->getCollection();
119
129
//dd($collection)
120
-
```
130
+
```
121
131
122
-
The importer class is fluent, then you can also write
132
+
The importer class is fluent, then you can also write
@@ -130,13 +140,13 @@ By default, every row of the first sheet of the excel file becomes an array and
130
140
To import a different sheet, use *setSheet($sheet)*
131
141
```
132
142
$excel = Importer::make('Excel');
133
-
$excel->load($filepath);
134
-
$excel->setSheet($sheetNumber);
135
-
$collection = $excel->getCollection();
143
+
$excel->load($filepath);
144
+
$excel->setSheet($sheetNumber);
145
+
$collection = $excel->getCollection();
136
146
//dd($collection)
137
-
```
147
+
```
138
148
139
-
To import each row in an Eloquent model, create a class which extends *Cyberduck\LaravelExcel\Contract\ParserInterface* and implements the methods *transform($row)*.
149
+
To import each row in an Eloquent model, create a class extending *Cyberduck\LaravelExcel\Contract\ParserInterface* and implement the methods *transform($row)*.
0 commit comments