| 代碼如下 |
複製代碼 |
|
<?php
header("content-type:application/vnd.ms-excel; charset=gbk");
header("content-disposition:attachment;filename=test_data.xls");
$link=mysql教程_connect('localhost','root','hhhkkk');
if($link){
mysql_select_db('dataui',$link);
mysql_query("set names 'gbk'");
echo "資料庫教程串連已經成功!";
}else{
echo "資料庫連接失敗!";
}
echo "項目名稱"." ";
echo "項目詳情"." ";
$sql="select * from php168_item_content where fid='11'";
$query=mysql_query($sql);
while($rs=mysql_fetch_array($query)){
echo $rs[title]." ";
$sql2="select * from php168_item_content_1 where id='$rs[id]'";
$query2=mysql_query($sql2);
while($rs2=mysql_fetch_array($query2)){
echo $rs2[content]." ";
echo " ";
}
}
?>
|
匯出excel時,如果某列匯出的是社會安全號碼的話,開啟excel檔案以後會發現,社會安全號碼自動採用科學計數法,無論如何修改該列屬性,都無法實現自己的要求。網上有人說,先把該列屬性改為文本以後,再輸入就沒有問題,實際操作excel確實如此,但是,php程式匯出就無法做到了
| 代碼如下 |
複製代碼 |
|
<?php
// 實驗資料,實際作業中,這裡應該是從資料庫取得資料
$emps教程[0]['id'] = '00001';
$emps[0]['name'] = 'abc';
$emps[0]['sexual'] = '男';
$emps[0]['age'] = 28;
$emps[1]['id'] = '00002';
$emps[1]['name'] = 'bbc';
$emps[1]['sexual'] = '男';
$emps[1]['age'] = 23;
$emps[2]['id'] = '00003';
$emps[2]['name'] = 'cba';
$emps[2]['sexual'] = '女';
$emps[2]['age'] = 20;
ini_set('include_path', '/data/website/htdocs/includes');
require_once('smarty.php');
$smarty = new smarty();
$smarty->assign('emps', $emps);
// 輸出檔案頭,表明是要輸出 excel 檔案
header("content-type: application/vnd.ms-excel");
header("content-disposition: attachment; filename=test.xls");
$smarty->display('excel-xml.tpl');
?> |