Skip to content

Commit bcd3271

Browse files
authored
Update multiple-sheets.md (SpartnerNL#134)
* Update multiple-sheets.md * add forgotten interface
1 parent b670657 commit bcd3271

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

3.1/imports/multiple-sheets.md

+52
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,55 @@ $import->onlySheets('Worksheet 1', 'Worksheet 3');
171171

172172
Excel::import($import, 'users.xlsx');
173173
```
174+
175+
## Making calculations work when referencing between sheets
176+
177+
When importing you have to implement the `Maatwebsite\Excel\Concerns\WithCalculatedFormulas` concern for Laravel Excel to calculate values from formulas. However, if one sheet creates a calculation by referencing another sheet, e.g. `=Sheet1!A1`, then you also have to implement the concern `Maatwebsite\Excel\Concerns\HasReferencesToOtherSheets`. An example is given below
178+
179+
```php
180+
namespace App\Imports;
181+
182+
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
183+
184+
class UsersImport implements WithMultipleSheets
185+
{
186+
public function sheets(): array
187+
{
188+
return [
189+
new FirstSheetImport(),
190+
new SecondSheetImport()
191+
];
192+
}
193+
}
194+
```
195+
196+
Then if `SecondSheetImport` contains formulas that reference `FirstSheetImport` then `FirstSheetImport` has to be defined using the `HasReferencesToOtherSheets` concern
197+
198+
```php
199+
namespace App\Imports;
200+
201+
use Maatwebsite\Excel\Concerns\ToArray;
202+
use Maatwebsite\Excel\Concerns\HasReferencesToOtherSheets;
203+
204+
class FirstSheetImport implements ToArray, HasReferencesToOtherSheets
205+
{
206+
public function array(array: $row)
207+
{
208+
209+
}
210+
}
211+
```
212+
213+
```php
214+
namespace App\Imports;
215+
216+
use Maatwebsite\Excel\Concerns\WithCalculatedFormulas;
217+
218+
class SecondSheetImport implements ToArray, WithCalculatedFormulas
219+
{
220+
public function array(array: $row)
221+
{
222+
223+
}
224+
}
225+
```

0 commit comments

Comments
 (0)