**i want to export 100data from database but every sheet must have just 12 data **
我在laravel应用程序中使用maatwebsite软件包
$data = array();
$data['usertotal'] = DB::table('users')
->join('employees', 'users.id', '=', 'employees.user_id')
->select('users.first_name','users.last_name', 'employees.function', 'employees.salary')
->skip($j)
->take(12)
->get();
///这是我的maatwebsite软件包代码 / *开始导出数据* /
Excel::load($sourceFilePath, function ($excel) use ($data) {
$excel->sheet('CNSS 2T19', function($sheet) use($data) {
$datasheet = array();
$i=0;
foreach($data['total-user'] as $datanew){
$datasheet[$i] = array( $datanew['first_name'].' '.$datanew['last_name'],
$datanew['chez_emp'],
$datanew['cat_prof'],
$datanew['brut_1'],
$datanew['brut_2'],
$datanew['brut_3'],
$datanew['total'],
);
$i++;
}
答案 0 :(得分:0)
您应该使用(offset,limit),每个循环都将12加到offset上,如下所示:
$data = array();
$data['usertotal'] = DB::table('users')
->join('employees', 'users.id', '=', 'employees.user_id')
->select('users.first_name','users.last_name', 'employees.function', 'employees.salary')
->offset($j+12)
->limit(12)
->get();