您的位置:首页 > 编程语言 > PHP开发

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

2017-06-29 20:17 411 查看
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'>入库日期</th>
<th class='name'>入库库位</th>
<th class='name'>供货商</th>
<th class='name'>入库人</th>
<th class='name'>数量</th>
<th class='name'>单价</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>";
//通过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="入库明细表.xls"');
header("Content-Transfer-Encoding:binary");
echo $table;
}
http://www.cankaojishu.com/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: