The code is as follows |
Copy Code |
<?php Header ("Content-type:application/vnd.ms-excel; CHARSET=GBK "); Header ("Content-disposition:attachment;filename=test_data.xls"); $link =mysql tutorial _connect (' localhost ', ' root ', ' hhhkkk '); if ($link) { mysql_select_db (' Dataui ', $link); mysql_query ("Set names ' GBK '"); echo "Database Tutorial connection has been successful! "; }else{ echo Database connection Failed! "; } echo "Project name". "; echo "Project Details". "; $sql = "SELECT * from Php168_item_content where fid= ' 11 '"; $query =mysql_query ($sql); while ($rs =mysql_fetch_array ($query)) { echo $rs [title]. "; $sql 2= "SELECT * from php168_item_content_1 where id= ' $rs [id] '"; $query 2=mysql_query ($sql 2); while ($rs 2=mysql_fetch_array ($query 2)) { Echo $rs 2[content]. " "; echo "";
}
} ?> |
When you export Excel, if a column exports an ID number, open the Excel file will find that the ID card automatically using the scientific notation, in any case modify the column properties, can not achieve their own requirements. Some people on the internet said that the column properties should be changed to text after the input is no problem, the actual operation of Excel is true, but, PHP program export can not do
The code is as follows |
Copy Code |
<?php Experimental data, the actual operation, here should be from the database to obtain information $emps tutorial [0][' id '] = ' 00001 '; $emps [0][' name '] = ' abc '; $emps [0][' sexual '] = ' male '; $emps [0][' age '] = 28; $emps [1][' id '] = ' 00002 '; $emps [1][' name '] = ' BBC '; $emps [1][' sexual '] = ' male '; $emps [1][' age '] = 23; $emps [2][' id '] = ' 00003 '; $emps [2][' name '] = ' CBA '; $emps [2][' sexual '] = ' female '; $emps [2][' age '] = 20;
Ini_set (' include_path ', '/data/website/htdocs/includes '); Require_once (' smarty.php '); $smarty = new Smarty (); $smarty->assign (' Emps ', $emps); //Output file headers, indicating that you want to output Excel files Header ("Content-type:application/vnd.ms-excel"); Header ("content-disposition:attachment; Filename=test.xls "); $smarty->display (' Excel-xml.tpl '); ? |