[英]Export data to excel file
**i want to export 100data from database but every sheet must have just 12 data **
i'm using maatwebsite package for my laravel application 我为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();
//this is my code with maatwebsite package /* Start Exporting Data */ //这是我与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++;
}
you should use (offset , limit) and each loop add 12 to offset like this: 您应该使用(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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.