浏览文章

文章信息

PHP简单的Excel表格下载 2289

$result = $this->model->query($sql)->rows;
   # 下载产品Excel
   $search = "";
   foreach ($result as $key => $val) {
       $search .= "<tr>
  <td>{$val['product_id']}</td>
  <td>{$val['sku']}</td>
  <td>{$val['keyword']}</td>
  <td>{$val['language_id']}</td>
</tr>";
   }

   $table = "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
  <table border='1' width='100%'>
     <tr>
        <td>产品ID</td>
        <td>SKU</td>
        <td>SEO-URL</td>
        <td>语言ID</td>
     </tr>".$search."
  </table>";

   $file_name = 'SEO URL 映射表'.date("Y-m-d H:i:s");
   header("Pragma: public");
   header("Content-type:application/vnd.ms-excel");
   header("Content-Disposition: inline;filename=$file_name.xls");

   echo $table;
   exit;


原创