PHP输出Excel

2016年3月23日 16:43:51 星期三

 1 public function echoExcel($list)
 2 {
 3     $body = '';
 4     $tr = '<tr style="border-right: 1px solid lightgrey;border-bottom: 1px solid lightgrey;">';
 5     $tds = '<td>';
 6     $tde = '</td>';
 7 
 8     $title = $tr.'<td>aaa</td>
 9         <td>bbb</td>
10         </tr>';
11     $userModel = new UserModel();
12     foreach ($list as $v) {
13         $aaa   = $tds.$v['aaa'].$tde;
14         $bbb   = $tds.$v['bbb'].$tde;
15         $body .= $tr.$aaa.$bbb.'</tr>';
16     }
17 
18     header('Content-Type: application/vnd.ms-excel');
19     header('Content-Disposition: attachment;filename="'.date('Y_m_d_H_i_s').'.xls"');
20     
21 $table = '<table style="border: 1px solid lightgrey; border-collapse: collapse;">'; 22 echo $table.$title.$body.'</table>'; 23 exit; 24 }

 

你可能感兴趣的:(PHP输出Excel)