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
Error Opening file with Excel. Possible data corrupted or bad file extension. #1673
Comments
Also thank you in advance :) Especially for taking the time to write this wrapper to begin with |
I'm not sure if it's still the same problem with PhpSpreadsheet, but PHPExcel had problems with having spaces ( |
Hey all, thanks for the lead. I think you are correct that there is an extra line break or something at the start of the file. I haven't traced it yet but when I switch to CSV, I can open the file and the data is there but the first row is blank.... Going to look some more, ill report back. I grepped for a file starting with a line break and then <?php but it didn't yield anything. |
I am going to close this out and open a new one with a better description of the problem. I can't find the source of the blank row |
i met same issue. i fixed by
|
Hi everyone, I spend my day to understand this unworkable download function. PHPSpreadSheet seems to use PHP buffer. And depending on your PHP configuration some warnings or errors could interfer with the output. Using : // in controller
ob_end_clean(); // this
ob_start(); // and this
return Excel::download(new MyExport, 'file.xls'); solves for me. Thank you for this awesome library. |
THanks alot its perfect answer |
Love You man.. You saved my head... |
Hello @patrickbrouwers |
If you are using ajax to download, My example code:
Without |
Thank!! save my life, i keep looking at which line of php code that corrupted my exported file.. turn out is axios |
Thanks @Leenzuur , you saved my day! It worked! I wonder is there any any to fix this but @Leenzuur way, you know what's I mean, if I have 10 Export class for 10 Model, when download, I have to add in 10 places. |
This problem started to happen to me today with no change to any export. Using @Leenzuur code sample fixed it after hours of research. |
This worked for me .. thanks <3 |
You should create a symbolic link at
This should fix it without the need of changing your code |
This solves all my problems. Also, if you cant install PHP spreadsheet and composer because it needs all the things u don't know, try adding --ignore-platform-reqs in your composer require/update |
Clearing the buffer was throwing a different error. No empty spaces before Instead of I now have however my frontend is still giving it as a .xlsx file back (blob with an extension). I don't know why and how, really, but the problem is solved now.
was getting a pretty uncorrupted PDF, every time. So it's either the added format or masking an .xls file as a .xlsx and making Excel work it out on its own. |
function index(Request $req){ |
If you are working with jquery: // In controller: // Ajax: |
Not sure why but I solved, storing the file Excel::store(new PaymentsExport($date), 'payments.xlsx', 'public'); and then redirecting to the file. return redirect('storage/payments.xlsx'); |
@SwithFr did you ever find the solution for this one? |
@Ribbon-Brooke Sorry don't remember and I don't have project sources anymore :/ |
Prerequisites
Versions
Description
Downloading file from a FromQuery method.... file downloads, upon opening XLSX file, receive an error message from Office:
"Excel cannot open the file <filename.xlxs> because the file format or the file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file"
Steps to Reproduce
Here is my method
I call it like this from a controller
Expected behavior:
The file to be downloaded with data
Actual behavior:
The file downloads but Excel gives error opening it
Additional Information
I have tested the query in eloquent and it returns a collection with data.
(https://user-images.githubusercontent.com/18451450/40511758-f61e6570-5f5d-11e8-9f37-0b594f60be59.png)
The text was updated successfully, but these errors were encountered: