phpoffice/phpspreadsheet 下载文件

会有一股神秘感。 提交于 2020-04-06 14:52:28
use   PhpOffice\PhpSpreadsheet\IOFactory ;
 
use   PhpOffice\PhpSpreadsheet\Cell\Coordinate ;
 
use   PhpOffice\PhpSpreadsheet\Spreadsheet ;
 
use   PhpOffice\PhpSpreadsheet\Writer\Xlsx ;
 
 
 
 
  
         $spreadsheet   =   new   Spreadsheet ();
         $objSheet   =   $spreadsheet -> getActiveSheet ();   //获取当前操作sheet的对象
 
         $objSheet -> setCellValue ( 'A1' '团长' )
                    -> setCellValue ( 'B1' '申请时间' )
                    -> setCellValue ( 'C1' '提现方式' )
                    -> setCellValue ( 'D1' '帐号' )
                    -> setCellValue ( 'E1' '姓名' )
                    -> setCellValue ( 'F1' '电话' )
                    -> setCellValue ( 'G1' '提现金额' );
         $i = 2 ;
 
         if ( $list ){
             foreach  ( $list   as   $key  =>  $val ) {
 
                 switch ( $val -> wd_type ){
                     case   '1' :
                     $wd_type = '微信' ;
                     break ;
                     case   '2' :
                     $wd_type = '支付宝' ;
                     break ;
                     case   '3' :
                     $wd_type = '银行卡' ;
                     break ;
                }
                 $objSheet -> setCellValue ( "A" . $i , $val -> leader_name )
                    
                    -> setCellValue ( "B" . $i , $val -> update_time )
                    -> setCellValue ( "C" . $i , $wd_type )
                    -> setCellValue ( "D" . $i , $val -> wd_account )
                    -> setCellValue ( "E" . $i , $val -> leader_name )
                    -> setCellValue ( "F" . $i , $val -> wd_phone )
                    -> setCellValue ( "G" . $i , $val -> money );
 
                 $i ++;
 
            }
 
        } else {
 
             $objSheet -> setCellValue ( "A2" , '没有内容' );
        }


 
         $title = "提现列表" ;
 
         header ( 'Content-Type: application/vnd.ms-excel' );
 
         header ( 'Content-Disposition: attachment;filename="' . $title . '.xls"' );
 
         header ( 'Cache-Control: max-age=0' );
   
         $writer   =   new   Xlsx ( $spreadsheet );
    
         $writer -> save ( 'php://output' );
    
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!