lundi 20 juin 2016

Laravel 5.2 - How to print data id wise in excel file?

I want, when i click on button then print and display particular id's data into excel file.

In my code i can't display this(above) type.

And my code are:

public function downloadExcel($type) { $data = DateEstimate::get()->toArray();

    return Excel::create('Task_Manager_File', function($excel) use ($data) {
                $excel->sheet('mySheet', function($sheet) use ($data) {
                    $sheet->fromArray($data);
                });
            })->download($type);
}

// Export Data Into Excel File And Print In. public function exportExcel($id) { echo 'export Data!!
'; $calculate_estimated_date = DB::table('calculate_estimated_date')->where('id', $id)->select()->first(); $dates = DB::select('SELECT start_date,end_date FROM calculate_estimated_date WHERE id' . '=' . $id);

    foreach ($dates as $sdate) {
        $startDate = $sdate->start_date;
        $endDate = $sdate->end_date;
    }

    //calculate start date and end date between two dates
    $start_date = new \DateTime($startDate);
    $end_date = new \DateTime($endDate);

    $betweenDate = new DatePeriod($start_date, new \DateInterval('P1D'), $end_date);

    foreach ($betweenDate as $data) {
        $between_to_dates = $data->format("Y-m-d");
    }

    if (Input::hasFile('import_file')) {
        $path = Input::file('import_file')->getRealPath();
        $data = Excel::load($path, function($reader) {

                })->get();

        if (!empty($data) && $data->count()) {
            foreach ($data as $key => $value) {
                $insert[] = ['project_name' => $value->project_name];
            }
            if (!empty($insert)) {
                DB::table('calculate_estimated_date')->insert($insert);

                dd('insert successfully');
            }
        }
    }
    return back();
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire