標籤: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)(解決長數字顯示問題)