• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

php导出excel(xls或xlsx)

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
$titles                = array('订单号','商品结算码','合同号','供应商名称','专柜','商品名称','商品货号','商品单价','商品总价','供应商结算金额','商品数量','商品促销优惠','平台优惠抵扣','品牌订单优惠抵扣');

//导出准备
ob_get_clean();
ob_start();
echo implode("\t", $titles),"\n";

$currencyModel      = app::get('ectools')->model('currency');
foreach ($lists as $key=>$value) {
    $row                             = array();
    $row['order_id']                = html_entity_decode("".$value['order_id']);
    $row['supplier_num']            = $value['supplier_num'];
    $row['agreement_code']            = $value['agreement_code'];
    $row['supplier_name']            = $value['supplier_name'];
    $row['shoppe_name']                = $value['shoppe_name'];
    $row['name']                    = $value['name'];
    $row['bn']                        = $value['bn'];
    $row['price']                   = $value['price'];
    $row['nums']                    = $value['nums'];
    $row['g_price']                 = $value['g_price'];
    $row['settlement_amount']       = $value['settlement_amount'];
    $row['goods_amount_off']         = $value['goods_amount_off'];
    $row['amount_off']                 = $value['amount_off'];
    $row['brand_amount_off']         = $value['brand_amount_off'];

    echo implode("\t", $row),"\n";
}

header('Content-Disposition: attachment; filename='.$filename);
header('Accept-Ranges:bytes');
header('Content-Length:' . ob_get_length());
header('Content-Type:application/vnd.ms-excel');
ob_end_flush();

2)格式选择

需要导出xls的话,用

header('Content-Type:application/vnd.ms-excel');

需要导出xlsx的话,用

header('Content-Type:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');

xls和xlsx的区别的话,是储存数据量大小的问题,xls只可以保存大概5、6w数据,xlsx可以100w左右

3)长数字完整显示解决办法

$row['order_id']                = html_entity_decode("".$value['order_id']);

 

 

转:  https://www.cnblogs.com/tujia/p/5999806.html

 

download.php下载

<?php
//获取要下载的文件名
$filename = $_GET['filename'];
//设置头信息
header('Content-Disposition:attachment;filename=' . basename($filename));
header('Content-Length:' . filesize($filename));
//读取文件并写入到输出缓冲
readfile($filename);

 

https://www.cnblogs.com/xiaopiyuanzi/p/7243051.html

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
[转]php实时输出内容发布时间:2022-07-10
下一篇:
php把一个二维数组中下标一样的取到一个新的数组中发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap