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

[Bug]: Error open file after download #3657

Closed
1 task done
anhtuan2810 opened this issue Jun 15, 2022 · 8 comments
Closed
1 task done

[Bug]: Error open file after download #3657

anhtuan2810 opened this issue Jun 15, 2022 · 8 comments

Comments

@anhtuan2810
Copy link

Is the bug applicable and reproducable to the latest version of the package and hasn't it been reported before?

  • Yes, it's still reproducable

What version of Laravel Excel are you using?

3.1.36

What version of Laravel are you using?

8.74.0

What version of PHP are you using?

8.0

Describe your issue

I fill data in exist template excel, everything is okay until open file, i have following error:
Screen Shot 2022-06-15 at 11 04 52

How can the issue be reproduced?

This is my controller:
`
$fieldPath = config('files.excel_templates.order_pop.path') . DIRECTORY_SEPARATOR . config('files.excel_templates.order_pop.file_path');
$fileDownload = $fieldPath . DIRECTORY_SEPARATOR . config('files.excel_templates.order_pop.file_name');
$exists = Storage::disk('s3')->exists($fileDownload);
if (! $exists) {
abort(404);
}
Storage::disk('local')->put($fileDownload, Storage::disk('s3')->get($fileDownload));

    return Excel::download(new LineStartkitExport($applicationId), config('files.excel_templates.order_pop.file_name'));`

And this is my Export Class:

`
$shops = TmpMstShop::where('application_id', $this->applicationId)->with('lineAccountOrderById')
->whereHas('lineAccountOrderById', function ($getLineAccountStatus) {
$getLineAccountStatus->where('line_startkit_apply', TmpLineAccountOrder::APPLY);
})->get();

    return [
        BeforeWriting::class => function (BeforeWriting $event) use ($shops) {
            $templateFile = new LocalTemporaryFile(storage_path('app/template/excel/' . config('files.excel_templates.order_pop.file_name')));
            $event->getWriter()->reopen($templateFile, Excel::XLSX);
            $event->getWriter()->getSheetByIndex(0);
            foreach ($shops as $index => $shop) {
                $event->getWriter()->getSheetByIndex(0)->setCellValue('B' . (self::START_ROW + $index), $shop->name_kanji ?? '');
            }
            $event->getWriter()->getSheetByIndex(0)->export($event->getConcernable());
            return $event->getWriter()->getSheetByIndex(0);
        },

`

What should be the expected behaviour?

So what is this problem and how to solve it?

@anhtuan2810
Copy link
Author

I haven't have anyway right now. Who can help me? Thanks

@leecrosdale
Copy link

Hello, do you by any chance have some whitespace in a file somewhere? like your web.php file? I've had this issue and it turned out to be that. Took me ages to find!

@anhtuan2810
Copy link
Author

Hello, do you by any chance have some whitespace in a file somewhere? like your web.php file? I've had this issue and it turned out to be that. Took me ages to find!

Thank for your answer. I only fill data to file, is it make effects?

@gagres
Copy link

gagres commented Jul 13, 2022

I'm facing the same issue here, for some reason when we try to export the file as a XLS it gets the same error, but on CSV it works well. We're exporting the XLS file using blade template. Could someone find a solution for this problem? In the past it was working normally for us too, what changed is that we're allowing special characters while exporting now, maybe this is what is breaking the export

@gagres
Copy link

gagres commented Jul 15, 2022

@anhtuan2810 , @leecrosdale , after some tests here, I've discovered the XLS export was breaking due the usage of emojis inside the text. Here is an example of file exported in both formats: csv and xls, you can see on the csv one that it uses emoji, and when you try to open the xls it's broken
8b829c4b3de587951273cf7f25eacc01.xls
a7adf5416438d0cd771d25ba61dfa847.csv

@stale stale bot added the stale label Sep 14, 2022
@stale
Copy link

stale bot commented Sep 15, 2022

This bug report has been automatically closed because it has not had recent activity. If this is still an active bug, please comment to reopen. Thank you for your contributions.

@stale stale bot closed this as completed Sep 15, 2022
@sluxzer
Copy link

sluxzer commented Jan 24, 2023

Hi there,

I also had the same issue right now #3857

Sorry I open a new ticket cause no answer here

@itamaradin15
Copy link

itamaradin15 commented Feb 25, 2023

Hello, do you by any chance have some whitespace in a file somewhere? like your web.php file? I've had this issue and it turned out to be that. Took me ages to find!

This happened to my. Check white space at the top of your files:
image

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

No branches or pull requests

5 participants