-
-
Notifications
You must be signed in to change notification settings - Fork 132
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
CSV stream callback fixed #170
Conversation
If we use callback to write content, we must open the OpenSpout writer. So it basically calls twice, which makes problem on CSV. openToBrowser function also need the file name inside closure. So I've added the $downloadName as an argument.
Sample usages of the function: SimpleExcel::streamDownload(downloadName: $name, writerCallback: function ($writerCallback, $downloadName) {
$writerCallback->openToBrowser($downloadName);
$row = Row::fromValues([
'first_name' => 'Rakib',
'last_name' => 'Hossain',
]);
$writerCallback->addRow($row);
}); |
src/SimpleExcelWriter.php
Outdated
@@ -68,11 +68,11 @@ public static function streamDownload( | |||
$writer = $simpleExcelWriter->getWriter(); | |||
|
|||
if ($writerCallback) { | |||
$writerCallback($writer); | |||
$writerCallback($writer, $downloadName); | |||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use a ternary instead of else
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I've updated it.
Could you also update the readme with an example on how to use this? |
Stream callback function example
I've added example on readme file. |
Thanks! |
If we use callback to write content, we must open the OpenSpout writer. So it basically calls twice, which makes problem on CSV.
openToBrowser
function also need the file name inside closure. So I've added the$downloadName
as an argument.