Export excel in PHP and excel

Source: Internet
Author: User
Tags php excel

Export excel in PHP and excel

<? Php
Header ('content-Type: application/vnd. ms-excel ');

Header ("Accept-Ranges: bytes ");
Header ('content-Disposition: attachment; filename=demo.xls ');
Header ('pragma: no-cache ');
Header ('expires: 0 ');

$ Title = array (
'Chief _ id' => 'employee id ',
'Name' => 'foreman name ',
'Mobile' => 'long phone ',
'Invitation' => 'invited ',
'Sign' => 'sign-In information ',
'Sign _ time' => 'sign-in time ',
'Imei' => 'device information'
);
$ Sign_in_list = Array
(
[0] => Array
(
[Chief_id] => 5
[Name] => test temporary table 2
[Mobile] = & gt; 13520037563
[Invitation] => Yes
[Sign] => √
[Sign_time] = & gt; 1478576359
[Imei] => Test 1
)
)

Array_unshift($sign_in_list, $title);
Method 1


Echo iconv ('utf-8', 'gbk', implode ("\ t", $ title), "\ n ";
Foreach ($ sign_listas $ value ){
Echo iconv ('utf-8', 'gbk', implode ("\ t", $ value), "\ n ";
}

Method 2
Echo '<! -- [If gte mso 9]>
<Xml>
<X: ExcelWorkbook>
<X: ExcelWorksheets>
<X: ExcelWorksheet>
<X: Name> </x: Name>
<X: WorksheetOptions>
<X: DisplayGridlines/>
</X: WorksheetOptions>
</X: ExcelWorksheet>
</X: ExcelWorksheets>
</X: ExcelWorkbook>
</Xml>
<! [Endif] -->
</Head> '; // No gridlines after excel export without the head label
Echo "<table> ";
Foreach ($ sign_in_list as $ key => $ value ){
Echo "<tr> ";
Echo "<td>". iconv ('utf-8', 'gbk', $ value ['Chief _ id']). "</td> ";
Echo "<td>". iconv ('utf-8', 'gbk', $ value ['name']). "</td>". "\ t ";
Echo "<td>". iconv ('utf-8', 'gbk', $ value ['mobile']). "</td>". "\ t ";
Echo "<td>". iconv ('utf-8', 'gbk', $ value ['invitation']). "</td>". "\ t ";
Echo "<td>". iconv ('utf-8', 'gbk', $ value ['sign']). "</td>". "\ t ";
Echo "<td> ". iconv ('utf-8', 'gbk', $ value ['sign _ time']). "</td> ". "\ t ";
Echo "<td>". iconv ('utf-8', 'gbk', $ value ['imei']). "</td>". "\ t ";
Echo "</tr> ";
Echo "\ n ";
// Echo iconv ('utf-8', 'gbk', implode ("\ t", $ value), "\ n ";
}
Echo "</table> ";
/*
1) Text: vnd. ms-excel.numberformat :@
2) Date: vnd. ms-excel.numberformat: yyyy/mm/dd
3) number: vnd. ms-excel.numberformat: #,## 0.00
4) Currency: vnd. ms-excel.numberformat: ¥ #, #0.00
5) percentage: vnd. ms-excel.numberformat: # 0.00%
Usage <td style = 'vnd. ms-excel.numberformat: @ '> ". $ printable." </td> mainly solves the problem of data format
Both of the above are flaws in the simplest PHP excel export method.
First, if text data such as a mobile phone number is displayed, scientific notation is displayed. If you stretch the table with the mouse, the length is displayed completely.
When an excel file is opened again, the system prompts
Which of the following solutions can be solved?
*/


?>

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.