【发布时间】:2019-05-20 02:37:59
【问题描述】:
我阻止从 laravel 上的表中导出 excel 文件,这是我的控制器:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DB;
use Excel;
class ExportExcelController extends Controller
{
function Export()
{
$customer_data = DB::table('qualys')->get();
return view('export_excel')->with('customer_data', $customer_data);
}
function excel()
{
$customer_data = DB::table('qualys')->get();
$customer_array[] = array('ip','qid');
// dd($customer_data);
foreach($customer_data as $customer)
{
// dd($customer);
$customer_array[] = array(
'ip' => $customer->qid,
'qid' => $customer->ip
);
}
Excel::download('customer data', function($excel) use ($customer_array) {
$excel->setTitle('customer Data');
$excel->sheet('Customer Data', function($sheet) use ($customer_array)
{
$sheet->fromArray($customer_array, null, 'A1', false, false);
});
})->download('xls', 'test');
}
}
我在第 29 行被阻止,我无法取回文件,这是以下错误:
Argument 2 passed to Maatwebsite\Excel\Excel::download() must be of the type string, object given, called in /var/www/html/qualys/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php on line 223
我已经测试了几个“代码”但没有任何效果:(你能帮我吗? 诚挚的。
【问题讨论】:
-
下载函数的第一个参数需要是一个对象“download(object $export, string $fileName, string $writerType = null)”,你传递2个字符串
-
没有注释,复制粘贴过程中的小错误,就是这样: Excel::download('customer data', function($excel) use ($customer_array) { $excel ->setTitle('客户数据'); $excel->sheet('客户数据', function($sheet) 使用 ($customer_array) { $sheet->fromArray($customer_array, null, 'A1', false, false ); }); })->下载('xls', 'test');
标签: php laravel laravel-5 frameworks