php导出excel、excelUntil_PHP教程

WBOY
풀어 주다: 2016-07-13 17:45:04
원래의
778명이 탐색했습니다.

excelUntil:
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    xlsWriteLabel(0,$i,mb_convert_encoding($titleList[$i],"gb2312","utf-8"));
  }
 }
}
//excel内容输出设置
function setValues($dateList){
 if(count($dateList) !=0){
  for ($i = 0; $i    $list = $dateList[$i];
   $leg = count($list);
   if ($leg !=0){
    for ($j = 0; $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:
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   $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导出结束
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/478680.htmlTechArticleexcelUntil: ?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...
관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!