php匯出excel(xls或xlsx)(解決長數字顯示問題)

來源:互聯網
上載者:User

標籤:xls   images   art   bytes   uml   ice   file   class   office   

1)demo

$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‘]);

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

 

PS:這個辦法,是從PHPExcel上逆回去找到的

我把PHPExcel產生的數字複製到txt檔案裡,再解釋它是什麼東東,然後就發現這個東西了

 

php匯出excel(xls或xlsx)(解決長數字顯示問題)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.