php导出excel最简单的办法,无需phpexcel


代码示例

  1. public function  exportDayInner(){

  2.         $start_date = input('start');

  3.         $end_date = input('end');

  4.         $innerdata = Db::table('inner')

  5.             ->whereTime('add_date', 'between', [$start_date,$end_date])

  6.             ->where('inner.depart_id',session('depart_id'))

  7.             ->join('goods','inner.goods_id = goods.id')

  8.             ->join('storage','storage.id = inner.storage_id')

  9.             ->join('supplier','supplier.id = inner.supplier_id')

  10.             ->join('user','user.id = inner.user_id')

  11.             //->limit(5)

  12.             ->order('inner.id desc')

  13.             ->field('goods_name,add_date,storage_name,supplier_name,real_name,num,inner.price')

  14.             ->select();

  15.         $table = '';

  16.         $table .= "<table>

  17.             <thead>

  18.                 <tr>

  19.                     <th class='name'>名称</th>

  20.                     <th class='name'>入库日期</th>

  21.                     <th class='name'>入库库位</th>

  22.                     <th class='name'>供货商</th>

  23.                     <th class='name'>入库人</th>

  24.                     <th class='name'>数量</th>

  25.                     <th class='name'>单价</th>

  26.                 </tr>

  27.             </thead>

  28.             <tbody>";

  29.         foreach ($innerdata as $v) {

  30.             $table .= "<tr>

  31.                     <td class='name'>{$v['goods_name']}</td>

  32.                     <td class='name'>{$v['add_date']}</td>

  33.                     <td class='name'>{$v['storage_name']}</td>

  34.                     <td class='name'>{$v['supplier_name']}</td>

  35.                     <td class='name'>{$v['real_name']}</td>

  36.                     <td class='name'>{$v['num']}</td>

  37.                     <td class='name'>{$v['price']}</td>

  38.                 </tr>";

  39.         }

  40.         $table .= "</tbody>

  41.         </table>";

  42. //通过header头控制输出excel表格

  43.             header("Pragma: public");  

  44.         header("Expires: 0");  

  45.         header("Cache-Control:must-revalidate, post-check=0, pre-check=0");  

  46.         header("Content-Type:application/force-download");  

  47.         header("Content-Type:application/vnd.ms-execl");  

  48.         header("Content-Type:application/octet-stream");  

  49.         header("Content-Type:application/download");;  

  50.         header('Content-Disposition:attachment;filename="入库明细表.xls"');  

  51.         header("Content-Transfer-Encoding:binary");  

  52.         echo $table;

  53.     }

来源: up61技术博客 欢迎分享 (QQ:529857614)

qq交流群:63739043 up61博客-php交流群

上一篇: THINKPHP3.2 Auth权限详细应用
下一篇: 专门针对php爬虫的网页抓取扩展类