Easy way to create XLS file from PHP
Posted on Wednesday, October 11 @ 09:52:55 ICT by apples

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();

 

 

資料來源:http://www.appservnetwork.com/modules.php?name=News&file=article&sid=82007/05/21
如何將 PHP 設定在 IIS 5 上面 ?

這是一份說明如何將 PHP 設定在 IIS 5 上面,使得 PHP 可以在 IIS 5 的環境中可以使用。

設定步驟如下:

  1. 啟動 Internet Services Manager
  • 由 開始/程式集/Administrative Tools/Internet Services Manager
  • 由 開始/執行,執行 Inetmgr.exe 程式

 

  1. 選定 預設網站/內容 (Default Web Site / Properties)

 

  1. 選定 Home Directory 頁簽,並點選 規劃 按鈕。

 

  1. 選定 App Mappings 頁簽,並點選 新增 按鈕。

 

  1. 新增資料的設定視窗被打開

 

  1. 依下列的內容加以設定。
    (若是 php5isapi.dll 和範例不同,請自行調整。)

 

  1. 設定完成後,請注意 重新啟動 IIS

 

  1. 測試 PHP 是否在 IIS 上,可以正常運作。
資料建立者:Perton Chang

2007/12/01

 

如何表示 Crystal Report 記錄的內容?

(2007/12/19)
如何在 Crystal Report 中下指令,用以判斷列印記錄內容與前一筆或是下一筆的關係?

可以用 Preview()、Next() 函數。
舉例說:
if {CUIV_P01.ap_no}=Previous ({CUIV_P01.ap_no}) then 
true
else
false