将数据从控制器导出到excel

时间:2017-02-14 03:50:21

标签: php

请帮我按此格式插入值

Roll No 1   Student Name:   Subject Name:
Date:        Session        Attendance Status


Roll No 2   Student Name:   Subject Name:
Date:        Session        Attendance Status

我的代码:

Excel::create('Consolidated List', function($excel) use ($data,$subject,$students,$studattendance) {
    $excel->sheet('Sheet 1', function($sheet) use ($data,$subject,$students,$studattendance){

        // $sheet->fromArray($data); 
        $sheet->row(1, array('Subject:'. $subject->subname));

        // $sheet->fromArray($data,null, 'A3', false, false);
        foreach($students as $student){
            foreach($studattendance as $studattend){
                $headings = array('Roll No:'.$student->studrollno,'Student:'.$student->studname);
                $sheet->prependRow(2, $headings);
                $headings=array('Date:','Session','Attendance Status');  
                $sheet->prependRow(1,$headings);
                $data[] = array( 
                    $studattend->adate= date('d-m-Y', strtotime($studattend->adate)),
                    $studattend->session_id,
                    $studattend->attendence,
                );
                $sheet->fromArray($data,null, 'F2', false, false);
            }   
        }
    });
})->export('xls');

0 个答案:

没有答案