I've read through the older issues about the blank space prior to the
I'm using the latest Laravel, & Laravel-Excel Package.
My Link code;
$.post(export_url, export_data, function(data){
var uri = 'data:application/vnd.ms-excel;charset=UTF-8,' + escape(data);
var link = document.createElement('a');
link.href = uri;
link.style = "visibility:hidden";
link.download = table_config.toolbar.tools.export.name+'.'+file_type;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
});
My export code;
return Excel::create($name, function($excel) use($records) {
$excel->sheet('Sheet 1', function($sheet) use($records) {
$sheet->fromArray($records);
});
})->export($type);
When I try to open the file. It is corrupt. This same code works fine with CSV
Hi, I've encountered the same bug.
I've read all the issues about removing the blank spaces before "
That does not change the fact that xls/xlsx export doesnt not work as it should.
Here is my code:
routes.php
Route::get('{id_me}/export/{table}', 'FileController@exportCsv')->where('table', 'shops|societies|axes|programs|scenarios|users|surveys');
FileController.php
public function exportCsv(Request $request)
{
$table = $request->route('table');
$model = $this->loadModel($table);
$society_id = $request->route('id_me');
$rows = $model
->where('society_id', $society_id)
->get();
$rows = $rows->toArray();
Excel::create($table, function($excel) use ($rows, $table)
{
$excel->setTitle("Exportation des " . $table);
$excel->sheet('shops', function($sheet) use ($rows)
{
$sheet->fromArray($rows);
});
})->download('xls');
}
This code works like a charm with csv extension not xls or xlsx.
By not working i mean that it render unreadable data.
Here is my setup:
Laravel 5.1
"maatwebsite/excel": "~2.1.0"
I'm pretty sure i've removed all trailling spaces before
No offense, but this should be highly considered as a bug to fixe.
Even if removing what's have to be removed to solve the problem is an "ok" solution for some, it is too much of a project maintainability issue for what can be a minor usage of this library (in my case).
Thanks for your work and attention, I really like to use Laravel-excel even if I'm still struggling to get some of the implemented feature to work as planned
I am facing a similar issue, with Laravel 5.2. Storing the file (XLS/XLSX) works fine, however the download('xlsx') function returns a corrupted file.
Trust me on this one, it's a problem with spaces as they get prepended/appended to the stream. Everybody who had this issue in the end found a space somewhere. You have to check all files, not only the once which get called.
It's not a bug, if you remove the incorrect spaces (which shouldn't be there in the first place) it will work fine. As well it's not a problem with this package, but with the parent package PHPExcel, if you do it with that package you will get the exact same error. Nothing we can do on this side.
Indeed that was a wrong space from my end.
Please once i upgraded to php7, i keep having this site cannot be reached in chrome with an ERR_INVALID_RESPONSE. Please is there anything am supposed to add or remove??
it works on windows but not after i uploaded it to my linux server. please check out this url. http://jabu-portal.com.ng/test/excel it downloaded once and then it starts giving file not found error.
Thanks
This is the code for the test page
` Excel::create('Laravel Excel', function($excel) {
$excel->sheet('Excel sheet', function($sheet) {
$sheet->setOrientation('landscape');
});
})->export('xlsx');`
i am facing same problem in my current application. But the problem is i wrote the same code in two different methods, but its working in one method and not in the other one.
Not working method:
public function exportReport($reportName,$reportData,$reportType){
$data=json_encode($reportData);
$data=json_decode($data,true);
Log::info('Download generated file into local disk');
return (Excel::create($reportName, function($excel) use ($data,$reportName){
$excel->sheet($reportName, function($sheet) use ($data){
//Inserting the data in the excel sheet
$sheet->fromArray($data);
// Freeze first row
$sheet->freezeFirstRow();
});
})->download($reportType));
}
have the same issue---basically download csv works fine on my local development enviroment[ LAMP on windows+php5.6+Laravel 5.3 ]but got ERR_INVALID_RESPONSE on my remote production server. ubuntu, nginx+php7,0+laravel5.3... any ideas?
@topegret download php7.0-zip to download the zip archive or change 'xslx' to 'xls' that's what I did an it worked.
@LordRahl90 I had the same issue in exporting xlsx only, but installing php7.0-zip solved my problem. Well done brother
I checked mine, it was php 7.0 zip and I only need csv file...
do we have a solution for this?
I am also experiencing the issue, i have php7 in my nginx server and i want to download xls file.
@topegret where you able to solve your issue?
Thank you for any help!
@edanao, try cleanin the buffer before calling download function. There must be some space symbol in the code which triggers the error.
if (ob_get_level() > 0) {
ob_end_clean();
}
Yeah. I have a walk around on this. basically I wrote my own stuff. I once
read an article after i have my own solution. it seems the nginx folder(s)
have permission set wrong. but I did not test it.
On Wed, Apr 5, 2017 at 11:43 AM, vitaliyb notifications@github.com wrote:
@edanao https://github.com/edanao, try cleanin the buffer before
calling download function. There must be some space symbol in the code
which triggers the error.if (ob_get_level() > 0) { ob_end_clean(); }
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/Maatwebsite/Laravel-Excel/issues/762#issuecomment-291922033,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AJqw_Xy1YDT-MAFLz8t6eDJNUD8-jn8Yks5rs8SVgaJpZM4IGjGg
.
@topegret What is the way you solved?
I have same issue on centos + nginx
Thank you @vitaliyb and @topegret !
It turns out that whenever I use composer update in Laravel, the PHPExcel module doesn't get updated so I am not getting the version correct version. I removed the extra break as suggested here https://github.com/PHPOffice/PHPExcel/issues/642 and clear the config cache just to be sure and it worked.
Hope this helps.
Finally, I have found the issue by config to /tmp folder of project.
It's working for me now.
Thanks.
Hi, i had the similar error, in the following code :
return Excel::create($name, function($excel) use($records) {
$excel->sheet('Sheet 1', function($sheet) use($records) {
$sheet->fromArray($records);
});
})->export($type);
The File name($name) and sheet name(Sheet 1) should Not contain any space. After removing space, everything worked like a charm. Cheers.
Thank you @vitaliyb
@edanao, try cleanin the buffer before calling download function. There must be some space symbol in the code which triggers the error.
if (ob_get_level() > 0) { ob_end_clean(); }
Thanks it worked For Me
if (ob_get_level() > 0) { ob_end_clean(); }
Great tip, thanks a lot!
if (ob_get_level() > 0) { ob_end_clean(); }
Great tip, thanks a lot!
Most helpful comment
@edanao, try cleanin the buffer before calling download function. There must be some space symbol in the code which triggers the error.
if (ob_get_level() > 0) { ob_end_clean(); }