我必须将数据从数据库mysql导出到excel

时间:2019-08-12 04:02:06

标签: laravel-5.8

when i am trying to export it says that the Export::create is not found class:

use DB;  
use Excel;  
class ExportExcelController extends Controller    
{  
  function index()  
  {                                 
    $customer_data=DB::table('book_details')->get();    
    return view('export_excel')->with('customer_data',$customer_data);  
  }

  function excel()
  {
    $customer_data=DB::table('book_details')->get()->toArray();
    $customer_array[]=array('ID','Book Name','Author Name','Publisher 
Name','Supplier Name','Department of book','Book status','Book Stock',

“图片”);           foreach($ customer_data作为$ customer)           {             $ customer_array [] = array('ID'=> $ customer-> id,                 'Book Name'=> $ customer-> book_name,                 '作者姓名'=> $ customer-> book_author,                 '发布者名称'=> $ customer-> book_publisher,                 '供应商名称'=> $ customer-> book_supplier,                 '图书部门'=> $ customer-> book_dept,                 '图书状态'=> $ customer-> book_status,                 'Book Stock'=> $ customer-> book_stock,                 '图像'=> $ customer-> book_image              );
          }

    Excel::create('Book Data', function($excel) use($customer_array)
    {
        $excel->setTitle('Book Data');
        $excel->sheet('Book Data',function($sheet)
        use($customer_array)
        {
            $sheet->fromArray(
            $customer_array,null,'A1',false,false);
         });
     })->download('xlsx');
  }

0 个答案:

没有答案