laravel-excel 实现导入导出

public function import(){

    $filePath = '/'.iconv('UTF-8', 'GBK', 'lq').'.xls';

    Excel::load($filePath, function ($reader) {

      /* $reader->noHeading();*/

        $data = $reader->toArray();

      /* array_pull($data, 0);//去除0号元素  =>Excel表格的头*/

        for ($m=0;$m

            $item = new enroll();

            $item->save();

}

});

}


public function export()

{

        $arr = ['排名', '微信昵称', '姓名', '手机号'];

        $list = [];

        $enrolls = Member::query()->where('zongnum',6)->get()->toArray();

/*dd($enrolls);*/

        foreach ($enrolls as $k=>$item)

{

            $nickname =  iconv("UTF-8","GB2312//IGNORE",$item['nickname']);

            $nickname =  iconv("GB2312","UTF-8//IGNORE",$nickname);

            $list[$k][] = $k;

            $list[$k][] =$nickname;

            $list[$k][] = $item['realname'];

            $list[$k][] = $item['tel'];

            //类型 1.正常 2.处长 3.联络员

        }

        /*array_unshift($list, $arr);*/

        Excel::create('中奖名单',function ($excel) use ($list) {

              $excel->sheet('score', function ($sheet) use ($list) {

                  $sheet->rows($list);

});

          })->export('xls');

}

}

你可能感兴趣的:(laravel-excel 实现导入导出)