Skip to content
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

Merged
merged 4 commits into from
Apr 24, 2024
Merged

CSV stream callback fixed #170

merged 4 commits into from
Apr 24, 2024

Conversation

rakibhoossain
Copy link
Contributor

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.

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.
@rakibhoossain
Copy link
Contributor Author

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);
        });

@@ -68,11 +68,11 @@ public static function streamDownload(
$writer = $simpleExcelWriter->getWriter();

if ($writerCallback) {
$writerCallback($writer);
$writerCallback($writer, $downloadName);
} else {
Copy link
Member

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?

Copy link
Contributor Author

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.

@freekmurze
Copy link
Member

Could you also update the readme with an example on how to use this?

@rakibhoossain
Copy link
Contributor Author

Could you also update the readme with an example on how to use this?

I've added example on readme file.

@freekmurze freekmurze merged commit e2482b2 into spatie:main Apr 24, 2024
10 checks passed
@freekmurze
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants