[code] Xuất dữ liệu ra file excel trong php

Thảo luận trong 'Source code' bắt đầu bởi hongoctrien, 17 Tháng hai 2012.

  1. Offline

    hongoctrien

    • Friends

    Số bài viết:
    2.449
    Đã được thích:
    2.464
    Điểm thành tích:
    2.431
    Mã:
    [COLOR=#000000][FONT=monospace]<?php
    
    function xlsBOF() { [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0); [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]return; [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]} [/FONT][/COLOR]
    
    [COLOR=#000000][FONT=monospace]function xlsEOF() { [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]echo pack("ss", 0x0A, 0x00); [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]return; [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]} [/FONT][/COLOR]
    
    [COLOR=#000000][FONT=monospace]function xlsWriteNumber($Row, $Col, $Value) { [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]echo pack("sssss", 0x203, 14, $Row, $Col, 0x0); [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]echo pack("d", $Value); [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]return; [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]} [/FONT][/COLOR]
    
    [COLOR=#000000][FONT=monospace]function xlsWriteLabel($Row, $Col, $Value ) { [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]$L = strlen($Value); [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L); [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]echo $Value; [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]return; [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]} [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]header("Pragma: public"); [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]header("Expires: 0"); [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]header("Content-Type: application/force-download"); [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]header("Content-Type: application/octet-stream"); [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]header("Content-Type: application/download");; [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]header("Content-Disposition: attachment;filename=php2xls.xls "); // แล้วนี่ก็ชื่ภไฟล์ [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]header("Content-Transfer-Encoding: binary "); [/FONT][/COLOR]
    
    [COLOR=#000000][FONT=monospace]// XLS Data Cell [/FONT][/COLOR]
    
    [COLOR=#000000][FONT=monospace]xlsBOF(); [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]xlsWriteLabel(1,0,"PHP Group VN"); [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]xlsWriteLabel(2,0,"Website : "); [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]xlsWriteLabel(2,1,"http://phpbasic.com"); [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]xlsWriteLabel(3,0,"TITLE : "); [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]xlsWriteLabel(3,1,"Dien dan thao luan PHP"); [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]xlsWriteLabel(4,0,"Copyright @ "); [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]xlsWriteLabel(4,1,"PHP Group VN"); [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]xlsWriteLabel(6,0,"NO"); [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]xlsWriteLabel(7,0,"1"); [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]xlsWriteLabel(6,1,"ID"); [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]xlsWriteLabel(7,1,"2104"); [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]xlsWriteLabel(6,2,"Gender"); [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]xlsWriteLabel(7,2,"Male"); [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]xlsWriteLabel(6,3,"Name"); [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]xlsWriteLabel(7,3,"TG"); [/FONT][/COLOR]
    
    [COLOR=#000000][FONT=monospace]xlsEOF(); [/FONT][/COLOR]
    [COLOR=#000000][FONT=monospace]?>[/FONT][/COLOR]
    Code sưu tầm. Hi vọng giúp ích cho các lập trình viên
    interpol thích bài này.

Chia sẻ trang này

Advertising: Linux system admin | nukeviet | nukeviet 4 | Upload ảnh miễn phí