CSV is the abbreviation of comma-separated values. It is usually a plain text file. We recommend that you use WORDPAD or notepad (NOTE) to enable it. Then, save a new file and enable it in EXCEL. You can also open it in excel, just like in excel.
The php reference code for generating an excel file (csv) is as follows:
The Code is as follows: |
Copy code |
<? Php Header ("Content-type: application/vnd. ms-excel "); Header ("Content-Disposition: attachment; filename = www. bKjia. c0m test_data.xls "); // The output content is as follows: Echo "name". "t "; Echo "Age". "t "; Echo "education". "t "; Echo "n "; Echo "James". "t "; Echo "25". "t "; Echo "www.111Cn.net section". "t "; ?>
|
The following method is extracted from a project (only 1997-2003 supported) t is a Tab
The Code is as follows: |
Copy code |
<? Php /** * Export an Excel table * */ Public function excel (){ // Indicates that an excel file is output. Header ("Content-type: application/vnd. ms-excel ;"); // The output file name is lamp_dtype.xls. Header ("Content-Disposition: filename=lamp_dtype.xls "); $ Exc. = "type name t dormitory category t dormitory area t number of people t monthly rent/person t remarks tn "; $ Dtype = D ('dtype '); // Query information in the database $ Datas = $ dtype-> select (); // Output each piece of information cyclically Foreach ($ datas as $ data ){ $ Exc. = "{$ data ['name']} t {$ data ['type']} t {$ data ['region']} t {$ data ['capacity ']} t {$ data ['rent ']} t {$ data ['remark']} tn "; } // UTF-8 to GB2312 $ Exc = iconv ("UTF-8", "GB2312", $ exc ); Echo $ exc; // Avoid outputting the following content Exit (); } ?> |
========================================================== ==========
Generate csv: comma is Tab