PHP export Excel Format data problem

Source: Internet
Author: User
Tags closing tag xmlns

  This article is mainly on the PHP export Excel format data in the introduction of the problem, the need for friends can come to the reference, I hope to help you.

Solve 2 questions: 1. The problem of automatic conversion of text data such as ID card to scientific counting method. 2. Chinese garbled questions   How Excel derives from the Web page. When we send this data to the client, we want the client program (browser) to read it in Excel format, so the MIME type is set to: application/ Vnd.ms-excel, when Excel reads a file, it renders the data in the format of each cell, and if the cell does not have a specified format, Excel renders the cell's data in the default format. This gives us the space to customize the data format, and of course we have to use the format that Excel supports. Listed below are some of the most commonly used formats:   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) Percent: Vnd.ms-excel.numberformat: # 0.00%   These formats you can also customize, such as years you can define as: yy-mm and so on. So how do you add these formats to the cell when you know these formats? Quite simply, we just need to add the style to the corresponding label pair (that is, the closing tag). such as <td></td&gt, add a style to the label <td></td>, as follows: <td  style= "vnd.ms-excel.numberformat:@" > 410522198402161833</td> Also, we can give <div></div> add style, also can give <tr></tr>,<table></ table> add style; which style will the data be rendered when we add a style to both the parent tag pair and the child label pair? After testing, it renders in the style closest to the data.   For example <td> style of ID card column:   echo "<td style= ' vnd.ms-excel.numberformat:@ ' >". $printable. " </td>n ";     code is as follows: $filename =iconv ("UTF-8", "Gb2312//ignore", "member name. xls");//date (' y-m-d-h-i-s '). XLS "; Header ("Content-type:application/vnd.ms-excel");             Header ("accept-ranges:bytes");             Header ("Content-disposition:attachment;filename=". $filename); $filename exported filename             header ("Pragma:no-cache");             header ("expires:0");   Echo ' <html xmlns:o= "Urn:schemas-microsoft-com:office:office"     xmlns:x= "urn: Schemas-microsoft-com:office:excel "    xmlns=" HTTP://WWW.W3.ORG/TR/REC-HTML40 ">  <head>     <meta http-equiv= "Expires" content= "Mon, A. 1999 00:00:01 GMT" >     <meta http-equiv= Content-type content= "text/html; charset=gb2312 ">     <!--[if GTE mso 9]><xml>     <x:ExcelWorkbook>   &NBSP ; <x:ExcelWorksheets>      <x:ExcelWorksheet>       <x:Name></x:Name>       <X: worksheetoptions>         <x:DisplayGridlines/>       </x: worksheetoptions>       </x:ExcelWorksheet>     </x:ExcelWorksheets>   & nbsp </x:ExcelWorkbook>     </xml><! [endif]-->   </head> '; echo "<table><tr>       <th>". Iconv ("UTF-8", "Gb2312//ignore", "member name"). " </th>       <th> ". Iconv (" UTF-8 "," Gb2312//ignore "," Account ")." </th>       <th> ". Iconv (" UTF-8 "," Gb2312//ignore "," Contacts ")." </th> </tr> ";             foreach ($list as $v)               {  & nbsp              echo "<tr>";                  echo "<td>". icoNV ("UTF-8", "Gb2312//ignore", $v ["user_name"]). " </td> ";                  echo "<td style= ' vnd.ms-excel.numberformat:@ ' >". $v [" account_id "]." </td> ";                  echo "<td>" Iconv ("UTF-8", "Gb2312//ignore", $v ["cont Act_name "])." </td> ";              echo "</tr>";                         echo "</table>";

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.