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?
*/
?>