tp5 data output

tp5 data export
directly call the method in the controller, just download

<?php
namespace app\index\controller;
use think\Controller;
use think\Model;
use think\Db;
header("Content-type:text/html;charset=UTF-8");
class Index extends Controller
{
    
    
	 public function index()
	{
    
    
	 $result = db('work')->select();
            $strTable ='<table border="1">';
            $strTable .='<tr>';
            $strTable .='<td>学号</td>';
            $strTable .='<td>姓名</td>';
            $strTable .='<td>性别</td>';
            $strTable .='<td>电话</td>';
			$strTable .='<td>职位</td>';
            $strTable .='</tr>';
            foreach($result as $k=>$val){
    
    
                $strTable .='<tr>';
                $strTable .='<td>'.$val['num'].'</td>';
                $strTable .='<td>'.$val['name'].'</td>';
                $strTable .='<td>'.$val['sex'].'</td>';
                $strTable .='<td>'.$val['phone'].'</td>';
                $strTable .='<td>'.$val['que'].'</td>';
                $strTable .='</tr>';
            }
            $strTable .='</table>';
            
        header("Content-type: application/vnd.ms-excel");
		header("Content-Type: application/force-download");
		header("Content-Disposition: attachment; filename=".'员工表'."_".date('Y-m-d').".xls");
		header('Expires:0');
		header('Pragma:public');
		echo '<html><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'.$strTable.'</html>';
	}
}

If you don’t understand, please contact the editor!

Guess you like

Origin blog.csdn.net/Kenneth_JC/article/details/114921052