PHP generates an Excel file (CSV) reference code as follows:
| The code is as follows |
Copy Code |
<?php
Header ("Content-type:application/vnd.ms-excel");
Header ("Content-disposition:attachment;filename= www.111cn.net Test_data.xls");
The output reads as follows:
echo "Name". " T ";
echo "Age". T ";
echo "Education". T ";
echo "n";
echo "John". T ";
echo "25". " T ";
echo "This Www.111Cn.net". T ";
?>
|
The following method is extracted from a project (only supports 1997-2003) T is tab
| The code is as follows |
Copy Code |
|
<?php
/**
* Export Excel Table
*
*/
Public function Excel () {
Indicates that the output is an Excel file
Header ("content-type:application/vnd.ms-excel;");
Indicates that the output file name is Lamp_dtype.xls
Header ("Content-disposition:filename=lamp_dtype.xls");
$exc. = "type T dormitory category T dormitory area T accommodates the number T month rent/person T remark TN";
$dtype = D (' Dtype ');
Querying information within a database
$datas = $dtype->select ();
Loop output per message
foreach ($datas as $data) {
$exc. = "{$data [' name ']}t{$data [' type ']}t{$data [' area ']}t{$data [' Capacity ']}t{$data [' Rent ']}t{$data [' remark ']}tn] ";
}
UTF-8 converted into GB2312
$exc =iconv ("UTF-8", "GB2312", $exc);
Echo $exc;
Avoid outputting the contents below
Exit ();
}
?>
|
=================================================
Generate csv: comma is tab