建站學(xué)堂

excel導(dǎo)出方式源碼

建站學(xué)堂

2460

字體:
public function  exportDayInner(){

         $start_date = input('start');

         $end_date = input('end');

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

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

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

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

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

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

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

             //->limit(5)

             ->order('inner.id desc')

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

             ->select();

         $table = '';

         $table .= "<table>

             <thead>

                 <tr>

                     <th class='name'>名稱</th>

                     <th class='name'>入庫(kù)日期</th>

                     <th class='name'>入庫(kù)庫(kù)位</th>

                     <th class='name'>供貨商</th>

                     <th class='name'>入庫(kù)人</th>

                     <th class='name'>數(shù)量</th>

                     <th class='name'>單價(jià)</th>

                 </tr>

             </thead>

             <tbody>";

         foreach ($innerdata as $v) {

             $table .= "<tr>

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

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

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

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

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

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

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

                 </tr>";

         }

         $table .= "</tbody>

         </table>";

 //通過(guò)header頭控制輸出excel表格

            header("Pragma: public");  

         header("Expires: 0");  

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

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

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

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

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

         header('Content-Disposition:attachment;filename="入庫(kù)明細(xì)表.xls"');  

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

         echo $table;

     }

[聲明]原創(chuàng)不易,請(qǐng)轉(zhuǎn)發(fā)者備注下文章來(lái)源(hbsjsd.cn)【速建時(shí)代】。