Two php tutorials to export excel examples
When exporting excel, if a certain column exports an ID number, you will find after opening the excel file that the ID number automatically uses scientific notation. No matter how you modify the column attributes, you will not be able to achieve your requirements. Some people on the Internet said that after changing the column attribute to text, there will be no problem when inputting it. This is indeed the case in Excel, but it cannot be done when exporting from the PHP programheader("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"."t";
echo "Project details"."t";
$sql="select * from php168_item_content where fid='11'";
$query=mysql_query($sql);
while($rs=mysql_fetch_array($query)){
echo $rs[title]."t";
$sql2="select * from php168_item_content_1 where id='$rs[id]'";
$query2=mysql_query($sql2);
While($rs2=mysql_fetch_array($query2)){
echo $rs2[content]."t";
echo "n";
}
}
?>
//Experimental data, in actual operations, the data should be obtained from the database
$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[2]['id'] = '00003';
$emps[1]['sexual'] = 'male';
$emps[1]['age'] = 23;
$emps[2]['name'] = 'cba';
$smarty->assign('emps', $emps);
$emps[2]['sexual'] = 'female';
$emps[2]['age'] = 20;
ini_set('include_path', '/data/website/htdocs/includes');
require_once('smarty.php');
$smarty = new smarty();
// Output the file header, indicating that the excel file is to be output
header("content-type: application/vnd.ms-excel");
header("content-disposition: attachment; filename=test.xls");
$smarty->display('excel-xml.tpl');
?>