Laravel导出excel教程

基础

首先,在Controller中使用Excel::create('Filename'); ,该语句的意思大致是建立一个名字为Filename的excel表的对象。
创建的过程中可以使用回调函数,如:

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

    // Call writer methods here

});

改变属性

可以在闭包函数里面使用一些属性,这些属性可以在配置文件app/config/packages/maatwebsite/excel/config.php中进行定义(我用的是Laravel5,把vendor\maatwebsite\excel\src\config\excel.php复制到了config下面,所以我认为应该是config/excel.php这个文件。此处我不是很明了,希望有懂的朋友告诉一下)。

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

});

现在就能导出excel文件了,只不过没有内容,有错误,打不开。

导出

下载创建的excel文件使用:->export($ext) 或者 >download($ext)

导出 Excel5 (xls):

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

})->export('xls');

// or
->download('xls');

导出 Excel2007 (xlsx):

->export('xlsx');

// or
->download('xlsx');

导出CSV:

->export('csv');

// or
->download('csv');

导出PDF:
如果要导出PDF格式的文件,则必须要把:"dompdf/dompdf": "~0.6.1""mpdf/mpdf": "~5.7.3" 或者 "tecnick.com/tcpdf": "~6.0.0" 这些放到composer.json文件中,并且要根据这些改变export.pdf.driver中的配置。

->export('pdf');
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值