Laravel Excel can't download and export

laravel download export phpexcel laravel-excel

3460 просмотра

2 ответа

My code is copyed from the website.

Excel::create('Filename', function($excel) {

// Set the title
$excel->setTitle('Our new awesome title');

// Chain the setters
$excel->setCreator('Maatwebsite')
      ->setCompany('Maatwebsite');

  // Call them separately
  $excel->setDescription('A demonstration to change the file properties');
})->download('xls');

I successfully download once.

However the other try is error.

The error Message is that.

Whoops, looks like something went wrong.

FatalErrorException in LaravelExcelWriter.php line 263:


Call to a member function getMergeCells() on a non-object
in LaravelExcelWriter.php line 263
Автор: 偉年熊 Источник Размещён: 08.11.2019 11:12

Ответы (2)


0 плюса

•   Write following in cmd
composer require Maatwebsite/excel
•   after install /run upper composer........Maalwebsite/excel successfully check in composer.json that 

"require": {
        "php": ">=5.5.9",
        "laravel/framework": "5.2.*",
        "laravelcollective/html": "5.2.*",
        "Maatwebsite/excel": "^2.1"
    },

•   config/app.php/ in provides
Maatwebsite\Excel\ExcelServiceProvider::class,
•   config/app.php/ in alias
'Excel' => Maatwebsite\Excel\Facades\Excel::class,
•   php artisan vendor:publish
•   php artisan make:controller ExcelController
•   open excel then create first_name,last_name,sex,email,phone then store datas and save as .csv
•   in controlller for import

use App\Customer;
use Input;
use DB;
use Excel;

class ExcelController extends Controller
{
    //
   public function getImport()
   {
        return view('excel.importCustomer');
   }

    public function postImport()
    {
        Excel::load(Input::file('customer'),function($reader){

     $reader->each(function($sheet){
        Customer::firstOrCreate($sheet->toArray());
        });
     });
    }
}
•   in routes for import

Route::get('/getImport','ExcelController@getImport');
Route::post('/postImport','ExcelController@postImport');
•   In controller for export

    public function getExport()
    {
        $export=Customer::all();
        Excel::create('Export Data',function($excel) use ($export){
            $excel->sheet('Sheet 1',function($sheet) use ($export){
                $sheet->fromArray($export);
            });
        })->export('xlsx');
  }
Автор: Borna Размещён: 20.08.2016 11:27

0 плюса

Решение

I know why the reason.

Because there is not any sheet in my case.

However the sheet is necessary.

Thank you.

Автор: 偉年熊 Размещён: 20.08.2016 05:11
Вопросы из категории :
32x32