exceluntil:
<?php
header (“expires: mon, 26 jul 1997 05:00:00 gmt”);
header (“last-modified: ” . gmdate(“d,d m yh:i:s”) . ” gmt”);
header (“cache-control: no-cache, must-revalidate”);    
header (“pragma: no-cache”);    
header (‘content-type: application/x-msexcel’);
header (“content-disposition: attachment; filename=empllist.xls” ); 
header (“content-description: php/interbase generated data” );

//excel导出开始
function xlsbof() {
    echo pack(“ssssss”, 0x809, 0x8, 0x0, 0x10, 0x0, 0x0); 
    return;
}
//excel导出结束
function xlseof() {
    echo pack(“ss”, 0x0a, 0x00);
    return;
}
//导出文字格式
function xlswritenumber($row, $col, $value) {
    echo pack(“sssss”, 0x203, 14, $row, $col, 0x0);
    echo pack(“d”, $value);
    return;
}
// 导出文本格式
function xlswritelabel($row, $col, $value ) {
    $l = strlen($value);
    echo pack(“ssssss”, 0x204, 8 + $l, $row, $col, 0x0, $l);
    echo $value;
 return;
}
//设置标题值
function settitlevalue($titlelist){
 $leg = count($titlelist);
 if($leg !=0){
  for ($i = 0; $i < $leg; $i++) {
   xlswritelabel(0,$i,mb_convert_encoding($titlelist[$i],”gb2312″,”utf-8″));
  }
 }
}
//excel内容输出设置
function setvalues($datelist){
 if(count($datelist) !=0){
  for ($i = 0; $i < count($datelist); $i++) {
   $list = $datelist[$i];
   $leg = count($list);
   if ($leg !=0){
    for ($j = 0; $j < $leg; $j++) {
     $value = $list[$j];
     if(is_numeric($value)){//输出类型是数字
      xlswritenumber($i+1,$j,$value);
     }else{//text类型的输出
      xlswritelabel($i+1,$j,mb_convert_encoding($value,”gb2312″,”utf-8″));
     }
    }
   }
  }
 }
}
?>
 
 
调用的php:
<?php
require_once (‘../../common/exceluntil.php’);//导入exceluntil
require_once(‘../adminglobal.inc.php’); //引入后台全局文件
/*权限验证*/
require(abspath . ‘admin/include/head.inc.php’); //引入head内容
require(abspath . ‘admin/include/navigation.inc.php’); //引入head内容

$titlelist = array(‘序号’,’服务噄1�7′,’数据庄1�7′,’用户各1�7′,’备份策略’);//excel标题
$sql = “select * from zxb_db”;
$result = $mysqlobj->query($sql);
$rows = $mysqlobj->getrows($result);
$datalist = array();
if(count($rows) >0){
 
 for ($i = 0; $i < count($rows); $i++) {
  $db = $rows[$i];
 
  $serverid = $db[‘server_id’];
  if($serverid){
   $row = $mysqlobj->getbyid(“zxb_db_server”, $serverid); //取得丄1�7条记彄1�7
   $db_server_name = $row[‘db_server_name’];
  }
 
  $list = array($i+1,$db_server_name,$db[‘db_name’],$db[‘user’],$db[‘bak_strategy’]);
  $datalist[$i]=$list;
 }
}
 
xlsbof();//excel导出弄1�7姄1�7
settitlevalue($titlelist);//导出标题
setvalues($datalist);//导出数据
xlseof();//excel导出结束
?>