Php generates simple code for an excel file (csv. 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 use EXCEL to enable it. you can also use CSV to separate values with commas, 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: |
|
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: |
|
/** * 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
The abbreviation of delimiter (comma-separated values), which is usually a plain text file. We recommend that you use WORDPAD or notepad (NOTE) to enable it, and then save a new file and use EXCEL to enable it...