最新消息: 新版网站上线了!!!

php输出excel实例解析

header("Content-type:txt/html;charset=utf-8");
function exportData($filename,$title,$data){
    header("Content-type: application/vnd.ms-excel");
    header("Content-disposition: attachment; filename="  . $filename . ".xls");
    if (is_array($title)){
        foreach ($title as $key => $value){
            echo $value."\t";
        }
    }
    echo "\n";
    if (is_array($data)){
        foreach ($data as $key => $value){
            foreach ($value as $_key => $_value){
                echo $_value."\t";
            }
            echo "\n";
        }
    }
}
$array1=array('编号','标题','内容');
$data = array(array('title'=>'标题','content'=>'内容'),array('title'=>'标题2','content'=>'内容2'),array('title'=>'标题3','content'=>'内容3'));
foreach($data as $key=>$val) {

    $data2[$key] =array($key+1,$val['title'],$val['content']);

}
exportData('a.xsl',$array1,$data2);

转载请注明:谷谷点程序 » php输出excel实例解析