php寫出Excel報表格式或函數

来源:互联网 发布:图章制作软件在线 编辑:程序博客网 时间:2024/04/30 16:52

 

 //開始寫,相當于打開文件流

function xlsBOF() {
    echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0); 
    return;
}

//格式字符串文本,$Row代表行號,$Col代表列,$Value代表寫出的值

//$Row和$Col第一個都從0開始,$Value,一般使用iconv("UTF-8", "本地系統支持的編碼",$value))后使用

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 xlsEOF() {
    echo pack("ss", 0x0A, 0x00);
    return;
}

這是一個固定的模式

$filename = "delaytask";
$ext = "xls";
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
$content_disp = (NETOFFICE_USR_BROWSER_AGENT == 'IE') ? 'inline' : 'attachment';
header('Content-Disposition:  ' . $content_disp . '; filename="' .$filename. '.' . $ext . '"');
header("Content-Transfer-Encoding: binary ");

在接著調用上面的寫入Excel的函數
原创粉丝点击