2016-08-20 12 views
0

私のコードは、ウェブサイトからコピーされたものです。Laravel Excelはダウンロードおよびエクスポートできません

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

正常にダウンロードされました。

他の試行は間違いです。

エラーメッセージです。

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 

答えて

-1
• 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','[email protected]'); 
Route::post('/postImport','[email protected]'); 
• 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'); 
    } 
+0

エクスポート用には、その公共関数getExport()を使用できます。 { \t $ export = Customer :: all(); \tエクセル::($エクスポートを使用します( 'データのエクスポート'、関数($エクセル)を使用する($エクスポート){ \t \t $ excel->シート( 'シート1'、関数($シート)を作成){ \t \t \t $ sheet-> fromArray($ export); \t \t}); \t}) - > export( 'xlsx'); } – Borna

+0

まだ動作していません。 –

+0

はあなたのモデルのLaravelExcelWriter.phpですか? – Borna

0

私は理由を知っています。

私の場合はシートがありません。

しかし、シートが必要です。

ありがとうございます。

関連する問題