茫茫網海中的冷日 - 對這文章發表回應
茫茫網海中的冷日
         
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已!
 恭喜您是本站第 1729059 位訪客!  登入  | 註冊
主選單

Google 自訂搜尋

Goole 廣告

隨機相片
IMG_0159.jpg

授權條款

使用者登入
使用者名稱:

密碼:


忘了密碼?

現在就註冊!

對這文章發表回應

發表限制: 非會員 可以發表

發表者: 冷日 發表時間: 2009/1/17 6:23:58

         Everybody knows phpMyAdmin can export file to Excel format but phpMyAdmin just export .csv file,not real Excel file format. If you are interest in PHP programming and need to export to the real Excel format please check it out !

Example PHP export to XLS file format.

1. Create Function for XLS

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;
}



2. Send Header to Browser in download format.

    // Query Database
    
$result = mysql_db_query ( $dbname , "select id,prename,name,sname,grade from appdata where course='$courseid' and sec='$section'" )

    
// Send Header
    
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=$courseid-$sec.xls " ); // �ล้วนี่�็ชื่อไฟล์
    
header ( "Content-Transfer-Encoding: binary " );

    
// XLS Data Cell


                
xlsBOF ();
                
xlsWriteLabel ( 1 , 0 , "Student Register $semester/$year" );
                
xlsWriteLabel ( 2 , 0 , "COURSENO : " );

                
xlsWriteLabel ( 2 , 1 , "$courseid" );
                
xlsWriteLabel ( 3 , 0 , "TITLE : " );
                
xlsWriteLabel ( 3 ,
1 , "$title" );
                
xlsWriteLabel ( 4 , 0 , "SETION : " );
                
xlsWriteLabel ( 4 , 1 , "$sec" );
                

xlsWriteLabel ( 6 , 0 , "NO" );
                
xlsWriteLabel ( 6 , 1 , "ID" );
                
xlsWriteLabel ( 6 , 2 , "Gender"
);
                
xlsWriteLabel ( 6 , 3 , "Name" );
                
xlsWriteLabel ( 6 , 4 , "Lastname" );
                
$xlsRow = 7 ;

                while(list(
$id , $prename , $name , $sname , $grade )= mysql_fetch_row ( $result )) {
                    ++
$i ;
                          
xlsWriteNumber
( $xlsRow , 0 , "$i" );
                          
xlsWriteNumber ( $xlsRow , 1 , "$id" );
                          
xlsWriteLabel ( $xlsRow , 2
, "$prename" );
                          
xlsWriteLabel ( $xlsRow , 3 , "$name" );
                          
xlsWriteLabel ( $xlsRow , 4 , "$sname" );

                    
$xlsRow ++;
                    }
                    
xlsEOF ();
                 exit();



原文出處:AppServNetwork - Easy way to create XLS file from PHP
內容圖示
url email imgsrc image code quote
樣本
bold italic underline linethrough   












 [詳情...]
validation picture

注意事項:
預覽不需輸入認證碼,僅真正發送文章時才會檢查驗證碼。
認證碼有效期10分鐘,若輸入資料超過10分鐘,請您備份內容後,重新整理本頁並貼回您的內容,再輸入驗證碼送出。

選項

Powered by XOOPS 2.0 © 2001-2008 The XOOPS Project|