zoukankan      html  css  js  c++  java
  • php导出excel(xls或xlsx)(解决长数字显示问题)

    2020 补充:https://www.cnblogs.com/tujia/p/11358096.html

    1)demo

    $titles                = array('订单号','商品结算码','合同号','供应商名称','专柜','商品名称','商品货号','商品单价','商品总价','供应商结算金额','商品数量','商品促销优惠','平台优惠抵扣','品牌订单优惠抵扣');
    
    //导出准备
    ob_get_clean();
    ob_start();
    echo implode("	", $titles),"
    ";
    
    $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("	", $row),"
    ";
    }
    
    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']);

    就是先拼上html 特殊字符 ï»¿,再转回去的意思

    PS:这个办法,是从PHPExcel上逆回去找到的

    我把PHPExcel生成的数字复制到txt文件里,再解释它是什么东东,然后就发现这个东西了

  • 相关阅读:
    css-使不同大小的图片在固定大小的容器中居中
    js-数组中查找特定元素并返回所有该元素的索引
    js-权威指南学习笔记5
    js-权威指南学习笔记4
    js-权威指南学习笔记3
    JavaScript中的类型转换
    js-权威指南学习笔记2
    通过维基API实现维基百科查询功能
    【代码笔记】iOS-FMDBDemo
    【代码笔记】iOS-自定义switch
  • 原文地址:https://www.cnblogs.com/tujia/p/5999806.html
Copyright © 2011-2022 走看看