PHP exports Excel (xls or xlsx) (resolves long digital display issues)

Source: Internet
Author: User

1) Demo

$titles=Array(' Order number ', ' Commodity Settlement code ', ' contract number ', ' Supplier name ', ' counter ', ' Product name ', ' Commodity item number ', ' commodity price ', ' commodity price ', ' Supplier settlement amount ', ' quantity of goods ', ' product promotion offer ', ' Platform discount ', ' Brand Order discount ');//Export PreparationOb_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) Format selection

If you need to export XLS, use

Header (' Content-type:application/vnd.ms-excel ');

If you need to export xlsx, use

Header (' Content-type:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet ');

The difference between XLS and xlsx is the problem of storing data size, XLS can only save about 5, 6w data, xlsx can be about 100w

3) long digital full display solution

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

is to first spell the HTML special character ï»&iquest, and then turn back to the meaning

PS: This is the way to get back from the Phpexcel.

I copied the phpexcel generated numbers into the TXT file and explained what it was, and then I found this thing.

PHP exports Excel (xls or xlsx) (resolves long digital display issues)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.