還是不死心找了一下如何使用 Example PHP export to XLS file format 產生 XLS 的

方法,發現使用 require_once 方式或是 include XLS function 輸出的格式都給他有點怪

怪的,如果直接加在程式尾端則一切正常,發現產生檔案的格式在檔案前被多加了0x20。

程式碼:

<?php
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");;
header("Content-Disposition: attachment;filename=test1.xls ");
header("Content-Transfer-Encoding: binary ");
 
xlsBOF();
xlsWriteLabel(0,0,"編號 ");
xlsWriteLabel(0,1,"姓名 ");
xlsWriteLabel(1,0,"1 ");
xlsWriteLabel(1,1,"小明 ");
xlsEOF();
 
function xlsBOF() {
    echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);  
    return;
}
 
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;
} 
 
?>

 

執行結果:

 

2010-03-31_153544 

 

 

 

參考網站:http://www.neatstudio.com/show-463-1.shtml

arrow
arrow
    全站熱搜

    iammic 發表在 痞客邦 留言(0) 人氣()