Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php laravel excel仅获取当前数据_Php_Excel_Laravel - Fatal编程技术网

Php laravel excel仅获取当前数据

Php laravel excel仅获取当前数据,php,excel,laravel,Php,Excel,Laravel,我刚开始使用这个excel包maatwebsite/excel,我设法将excel下载出来。但在创建excel时,我遇到了一些困难 如何更改excel中打印的日期格式?我见过有人用这样的东西,但为什么我的不行呢 $sheet->setColumnFormat(数组('E'=>'d/m/y') 如何获取来自今天的数据?例如,我输入了一些数据并保存到数据库中,当我下载excel时,它将只显示该数据,而不是过去的数据。我该怎么做 是否可以更改excel的标题?例如,更改日期时创建的 目前我的代码如下:

我刚开始使用这个excel包maatwebsite/excel,我设法将excel下载出来。但在创建excel时,我遇到了一些困难

  • 如何更改excel中打印的日期格式?我见过有人用这样的东西,但为什么我的不行呢
  • $sheet->setColumnFormat(数组('E'=>'d/m/y')

  • 如何获取来自今天的数据?例如,我输入了一些数据并保存到数据库中,当我下载excel时,它将只显示该数据,而不是过去的数据。我该怎么做

  • 是否可以更改excel的标题?例如,更改日期时创建的

  • 目前我的代码如下:

     public function downloadExcel($type)
        {
    
            $data = personal_info::join('qualifications', 'qualifications.user_id', '=', 'personal_infos.id')
            ->select(
              'personal_infos.id',  
              'personal_infos.name', 
              'personal_infos.email', 
              'qualifications.qualification',
              'personal_infos.created_at')
            ->get()
            ->sortByDesc('created_at');
            return Excel::create('test', function($excel) use ($data) {
                $excel->sheet('mySheet', function($sheet) use ($data)
                {
                    $sheet->fromArray($data);
                    $sheet->setColumnFormat(array('E' => 'd/m/y'));
                });
            })->download($type);
        }
    

    如果需要今日数据,请在查询中添加where条件,如下所示:-

    $todaydate = date('Y-m-d');
    $data = personal_info::join('qualifications', 'qualifications.user_id', '=', 'personal_infos.id')
        ->select(
          'personal_infos.id',  
          'personal_infos.name', 
          'personal_infos.email', 
          'qualifications.qualification',
          'personal_infos.created_at')
        ->where('personal_infos.created_at',$todaydate) // or you can use whereDate() of laravel like :- whereDate('personal_infos.created_at', '=', date('Y-m-d'));
        ->get();
    
    enter code here
    $data = personal_info::join('qualifications', 'qualifications.user_id', '=', 'personal_infos.id')
        ->select(
          'personal_infos.id',  
          'personal_infos.name', 
          'personal_infos.email', 
          'qualifications.qualification',
          'personal_infos.created_at as Date') //here you can change the name
         ->where('Date',$todaydate) // then you need to change in where condition also 
         ->get();
    
    是的,可以将在创建的更改为日期您需要这样的别名:-

    $todaydate = date('Y-m-d');
    $data = personal_info::join('qualifications', 'qualifications.user_id', '=', 'personal_infos.id')
        ->select(
          'personal_infos.id',  
          'personal_infos.name', 
          'personal_infos.email', 
          'qualifications.qualification',
          'personal_infos.created_at')
        ->where('personal_infos.created_at',$todaydate) // or you can use whereDate() of laravel like :- whereDate('personal_infos.created_at', '=', date('Y-m-d'));
        ->get();
    
    enter code here
    $data = personal_info::join('qualifications', 'qualifications.user_id', '=', 'personal_infos.id')
        ->select(
          'personal_infos.id',  
          'personal_infos.name', 
          'personal_infos.email', 
          'qualifications.qualification',
          'personal_infos.created_at as Date') //here you can change the name
         ->where('Date',$todaydate) // then you need to change in where condition also 
         ->get();
    

    希望它能帮助你

    对于你所有的问题,你可以在一个视图中这样做,对吗?然后将该视图导出到excel,@Blade to excel()对不起,我可以在视图中执行该操作是什么意思?你的意思是我能在我的视图中下载excel或其他东西,还是我能看到excel中的数据?还有你给我的链接,我已经读过了,我真的不太明白。如果可能的话,你能给我举个例子,让我能更清楚地理解它吗@Arunkumarth创作的最新作品的变化,非常感谢!!但是当我使用->where('Date',$todaydate)时,我得到了这个错误,在'where子句'中的未知列'Date'。我尝试将日期替换为个人信息。创建于,没有错误,但不会显示任何数据。因此,当我试图删除where子句时,这里有数据,那么这里可能有什么问题?检查数据是否存在@DknaYup日期存在,我尝试进行dd,结果是,#attributes:array:5[▼ “id”=>5“名称”=>“测试”“电子邮件”=>”hello@gmail.com“资格”=>“adw”日期“=>“2017-11-08 05:19:43”]不带whereclause@Dkna今天日期2017-12-04。。。我想你没有这个日期的数据哦,是的,我忘了添加数据了哈哈哈,非常感谢现在就去添加数据