PHP头条
热点:

两款php导出excel实例


两款php教程导出excel实例

<?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 "项目名称"."t";
echo "项目详情"."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";
     
   }
                       
}


?>

导出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');
?>

www.phpzy.comtrue/php/25529.htmlTechArticle两款php导出excel实例 两款php教程导出excel实例 ?php header(content-type:application/vnd.ms-excel; charset=gbk); header(content-disposition:attachment;filename=test_data.xls); $link=mysql教程_connect('localhost','root','hhhkkk...

相关文章

    暂无相关文章

PHP之友评论

今天推荐