Home  >  Article  >  Backend Development  >  PHP export excel, excelUntil_PHP tutorial

PHP export excel, excelUntil_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:45:04800browse

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 export starts
function xlsBOF() {
echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
Return;
}
//Excel export ends
function xlsEOF() {
echo pack("ss", 0x0A, 0x00);
Return;
}
//Export text format
function xlsWriteNumber($Row, $Col, $Value) {
echo pack("sssss", 0x203, 14, $Row, $Col, 0x0);
echo pack("d", $Value);
Return;
}
//Export text format
function xlsWriteLabel($Row, $Col, $Value) {
$L = strlen($Value);
echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);
echo $Value;
return;
}
//Set title value
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 content output settings
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)){//The output type is numeric
xlsWriteNumber($i+1,$j,$value);
}else{//text type output
       }
}
}
}
}
}
?>


Called PHP:
require_once ('../../common/excelUntil.php');//Import excelUntil
require_once('../adminGlobal.inc.php'); //Introduce background global files
/*Permission verification*/
require(ABSPATH . 'admin/include/head.inc.php'); //Introduce head content
require(ABSPATH . 'admin/include/navigation.inc.php'); //Introduce head content

$titleList = array('serial number','service name','data bank name','user name','backup strategy');//excel title

$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); //Get 1.7 records 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 export method 1�7姄1�7
setTitleValue($titleList);//Export title
setValues($dataList);//Export data
xlsEOF();//Excel export ends
?>

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...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn