LaravelExcel匯出,事先將需要匯出的內容封裝到數組裡面,然後一次性匯出,示例程式碼如下:
function DataList(Excel $excel) {
$info = $this->test->select("id","name","sex","mobile","hobby")->get();
foreach ($info as $key => $value) {
$export[] = array(
"ID" => $value["id"],
"姓名" => $value["name"],
"性別" => $value["mobile"],
"電話" => $value["mobile"],
"愛好" => $value["hobby"],
);
}
$tab_name = "users";
$excel->create($name, function($excel) use ($export) {
$excel->sheet("export", function($sheet) use ($export) {
$sheet->fromArray($export);
});
})->export("xls");
我也是因為使用Laravel後項目需要,就引入了LaravelExcel,當時還寫了一篇博文心得,有興趣的話可以看看,希望對閣下有用:狂奔的螞蟻的部落格_Laravel5.1框架中Laravel Excel 的引入及其配置使用方法
LaravelExcel匯出,事先將需要匯出的內容封裝到數組裡面,然後一次性匯出,示例程式碼如下:
function DataList(Excel $excel) {
$info = $this->test->select("id","name","sex","mobile","hobby")->get();
foreach ($info as $key => $value) {
$export[] = array(
"ID" => $value["id"],
"姓名" => $value["name"],
"性別" => $value["mobile"],
"電話" => $value["mobile"],
"愛好" => $value["hobby"],
);
}
$tab_name = "users";
$excel->create($name, function($excel) use ($export) {
$excel->sheet("export", function($sheet) use ($export) {
$sheet->fromArray($export);
});
})->export("xls");
}
我也是因為使用Laravel後項目需要,就引入了LaravelExcel,當時還寫了一篇博文心得,有興趣的話可以看看,希望對閣下有用:狂奔的螞蟻的部落格_Laravel5.1框架中Laravel Excel 的引入及其配置使用方法