php匯出excel、excelUntil_PHP教程

來源:互聯網
上載者:User
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 < $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:
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匯出結束
?>

http://www.bkjia.com/PHPjc/478680.htmlwww.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...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.