程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> 導出考核統計php導出Excelde應用

導出考核統計php導出Excelde應用

編輯:關於PHP編程

     // 導出考核統計

    	function daochu(){
    		require_once 'outExcel.class.php';
    		header("Content-Type: application/vnd.ms-excel;charset=utf-8");
    		$kaoheCode = $_GET['kaoheCode'];
    		$dao = new PerformanceServices();
    		$kaoheinfo = $dao->getKaoheInfo($kaoheCode);
    		$filename=$kaoheinfo['KH_NAME']."考核統計";
    
    		$encoded_filename = urlencode($filename);
    		$encoded_filename = str_replace("+", "%20", $encoded_filename);
    		$ua = $_SERVER["HTTP_USER_AGENT"];
    		header('Content-Type: application/octet-stream');
    		
    		if (preg_match("/MSIE/", $ua)) {
    			header('Content-Disposition: attachment; filename="' . $encoded_filename . '.xls"');
    		} else if (preg_match("/Firefox/", $ua)) {
    			header('Content-Disposition: attachment; filename*="utf8''' . $filename . '.xls"');
    		} else {
    			header('Content-Disposition: attachment; filename="' . $filename . '.xls"');
    		}
    		
    				
    		header("Pragma: no-cache");
    		header("Expires: 0");
    		$dates_excel = $dao->getTongjiInfo($kaoheCode); 
    		$mytime = date("Y-m-d H:i:s",$dates_excel['KH_TIME']);
     		$excel=new SimpleExcel();//調用類開始
    		$excel->excelItem(array("統計時間",$mytime));//第一行標題,可以不要
    				$excel->excelItem(array("序號","姓 名","部門","分數"));//第一行標題,可以不要
    		
    		$excel->colsAttrib(array("1","a","a","1"));//定義屬性,數字型為"1",字符型為"a"
    		$scores = explode(',',$dates_excel['KH_SCORES']);
    		//echo $scores;exit();
    		$i=0;
    		foreach ($scores as $v){
    			$i++;
    			$r = explode(':', $v);
    			$userCode = $r[0];
    			$user = $dao->getUserInfo($userCode);
    			$dept=$dao->getCellName($userCode);
    			$excel->excelWrite(array($i,$user['QT_NAME'],$dept,$r[1]));
    		}
    		$excel->excelEnd();
    	}

    以下是excel類 outExcel.class.php

    <?php   
    class SimpleExcel
    {               
    var $rowsNum=0;
    
    var $attrib=array();
    
    var $in_charset = 'UTF-8';
    
    function SimpleExcel()
    {   
    echo pack("ssssss",0x809,0x8,0x0,0x10,0x0,0x0);
    return;
    }           
    
    
    function excelItem($string=array())
    {       
    for ($i=0;$i<count($string);$i++)
    {
    $curStr = $string[$i];
    $curStr = $this->iconvToData($curStr);
    
    $L = strlen($curStr);
    echo pack("ssssss",0x204,8+$L,$this->rowsNum,$i,0x0,$L);
    echo $curStr; 
    }
    $this->rowsNum++;
    return;
    }           
    
    function colsAttrib($string=array())
    {           
    $this->attrib=$string;
    return;
    }       
    
    function excelWrite($string=array())
    {   
    for ($i=0;$i<count($string);$i++)
    {
    $curStr = $string[$i];
    $curStr = $this->iconvToData($curStr);
    
    if ($this->attrib[$i]=="1")
    {
    echo pack("sssss",0x203,14,$this->rowsNum,$i,0x0);
    echo pack("d",$curStr);
    } else {
    $L = strlen($curStr);
    echo pack("ssssss",0x204,8+$L,$this->rowsNum,$i,0x0,$L);
    echo $curStr;
    }
    }
    
    $this->rowsNum++;
    }
    
    function excelEnd()
    {
    echo pack("ss",0x0A,0x00);
    return;
    }
    
    function iconvToData($data)
    {
    return iconv($this->in_charset,'gb2312',$data);
    }
    }
    ?>

     

    1. 上一頁:
    2. 下一頁:
    Copyright © 程式師世界 All Rights Reserved