dede缁囨ⅵ绯荤粺鎬庢牱瀵煎嚭鍚庡彴鐨勬枃绔犳垨鑷畾涔夋ā鍨嬩腑鐨勬暟鎹埌excel,骞朵笖涓嶅嚭鐜颁贡鐮?/p>
鍦ㄥ悗鍙扮洰褰曞垱寤轰竴涓猵hp鏂囦欢toexcel.php,鍦ㄦ渶涓婇潰鍔犲叆浠g爜;
require_once(dirname(__FILE__).'/config.php');require_once(DEDEINC.'/typelink.class.php');require_once(DEDEINC.'/datalistcp.class.php');require_once(DEDEADMIN.'/inc/inc_list_functions.php');
鍔犲叆瀵煎嚭鍒癳xcel绫?
class Excel{ private $head; private $body; public function addHeader($arr){ foreach($arr as $headVal){ $headVal = $this->charset($headVal); $this->head .= "{$headVal}\t "; } $this->head .= "\n"; } public function addBody($arr){ foreach($arr as $arrBody){ foreach($arrBody as $bodyVal){ $bodyVal = $this->charset($bodyVal); $this->body .= "{$bodyVal}\t "; } $this->body .= "\n"; } } public function downLoad($filename=''){ if(!$filename) $filename = date('YmdHis',time()).'.xls'; header("Content-type:application/vnd.ms-excel"); header("Content-Disposition:attachment;filename=$filename"); header("Content-Type:charset=gb2312"); if($this->head) echo $this->head; echo $this->body; } public function charset($string){ return mb_convert_encoding($string,'GBK','auto'); } }
浠g爜瑙i噴:
1.杈撳嚭鍒楀悕鏁扮粍,骞惰浆鐮?/p>
public function addHeader($arr){ foreach($arr as $headVal){ $headVal = $this->charset($headVal); $this->head .= "{$headVal}\t "; } $this->head .= "\n"; }
2.杈撳嚭瀵煎嚭鍐呭鏁扮粍,骞惰浆鐮?/p>
public function addBody($arr){ foreach($arr as $arrBody){ foreach($arrBody as $bodyVal){ $bodyVal = $this->charset($bodyVal); $this->body .= "{$bodyVal}\t "; } $this->body .= "\n"; } }
3.璁剧疆header澶撮儴淇℃伅鍜屽鍑哄埌excel鍐呭,骞惰緭鍑哄埌娴忚鍣?/p>
public function downLoad($filename=''){ if(!$filename) $filename = date('YmdHis',time()).'.xls'; header("Content-type:application/vnd.ms-excel"); header("Content-Disposition:attachment;filename=$filename"); header("Content-Type:charset=gb2312"); if($this->head) echo $this->head; echo $this->body; }
4.杞爜,杩欓噷涓嶇敤iconv鍑芥暟,鏈夊彲鑳戒細涓巊d鍐茬獊瀵艰嚧杈撳嚭绌虹櫧銆傜敤
public function charset($string){ return mb_convert_encoding($string,'GBK','auto'); }
7.璋冪敤鏂规硶;
$excel = new Excel(); $excel->addHeader(array('鍒椾竴','鍒椾簩','鍒椾笁','鍒楀洓')); global $dsql; $sql="select 鍒椾竴瀛楁,鍒椾簩瀛楁,鍒椾笁瀛楁,鍒楀洓瀛楁 from 琛ㄥ悕"; $dsql->SetQuery($sql);$dsql->Execute();while($row = $dsql->GetArray()){$list[]=$row;}unset($row);$excel->addBody($list); $excel->downLoad();
鍚庡ぉ娣诲姞瀵煎嚭鍒癳xcel浠g爜:
鎵惧埌鍚庡彴鐩綍涓嬬殑templets鐩綍,涓嬮潰鏈変釜content_list.htm鏂囦欢,
鎵惧埌鍒犻櫎灞炴€?/a>
鍦ㄥ悗闈㈠姞涓€娈典唬鐮?/p>
<?php if($channelid==1) echo " 瀵煎嚭鍒癳xcel\r\n”; ?>
$channelid灏辨槸浣犵殑妯″瀷id,鏍规嵁浣犲鍑虹殑琛ㄥ~鍐欍€傚~鍐欏畬涔嬪悗鎵撳紑鍚庡彴鏍忕洰鍒楄〃灏卞嚭鐜板鍑烘寜閽?/p>
娉ㄦ剰浜嬮」
杞爜闂,鏍规嵁鑷繁鐨勫疄闄呮儏鍐?/p>
瀵煎嚭瀛楁,澶氳〃鎴栬嚜瀹氫箟妯″瀷鐨勮〃鍙互閫氳繃left join