Skip to content

Commit

Permalink
Stream callback sample
Browse files Browse the repository at this point in the history
Stream callback function example
  • Loading branch information
rakibhoossain authored Apr 24, 2024
1 parent 609d60b commit 7984407
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,41 @@ foreach (range(1, 10_000) as $i) {
$writer->toBrowser();
```

Stream download using callback function

```php
use Spatie\SimpleExcel\SimpleExcelWriter;
use OpenSpout\Common\Entity\Row;

$writer = SimpleExcelWriter::streamDownload(downloadName: 'user-list.xlsx', writerCallback: function ($writerCallback, $downloadName) {

$writerCallback->openToBrowser($downloadName);

$writerCallback->addRow(Row::fromValues([
'first_name' => 'First Name',
'last_name' => 'Last Name',
]));

$writerCallback->addRow(Row::fromValues([
'first_name' => 'Rakib',
'last_name' => 'Hossain',
]));

foreach (range(1, 10_000) as $i) {
$writerCallback->addRow(Row::fromValues([
'first_name' => 'Rakib',
'last_name' => 'Hossain',
]));

if ($i % 1000 === 0) {
flush();
}
}
});

$writer->toBrowser();
```


### Writing multiple rows at once

Expand Down

0 comments on commit 7984407

Please sign in to comment.