SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Sep 2008
    Posts
    235
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    export data to xlsx format (need it quickly please )

    dear everyone
    i am exporting my data to *.xls format and it working very well and here it is my code

    PHP Code:
    <?
    session_start
    ();
        if(
    $_SESSION['archived_b']==1)
        {
            include(
    'DBconnect_archived.php');
        
    //    echo 'here';
        
    }
        else
        {
            include(
    'DBconnect.php');
        }    
    function 
    xlsBOF() {
        echo 
    pack("ssssss"0x8090x80x00x100x00x0);  
        return;
    }

    function 
    xlsEOF() {
        echo 
    pack("ss"0x0A0x00);
        return;
    }

    function 
    xlsWriteNumber($Row$Col$Value) {
        echo 
    pack("sssss"0x20314$Row$Col0x0);
        echo 
    pack("d"$Value);
        return;
    }

    function 
    xlsWriteLabel($Row$Col$Value ) {
        
    $L strlen($Value);
        echo 
    pack("ssssss"0x204$L$Row$Col0x0$L);
        echo 
    $Value;
    return;

    ?>
    <?
     
    // Query Database

        
    $table_name='';
        
    $select_query1 =  $_SESSION['query'];
        
    //print "select_query1: " . $select_query1 . "<br>";
        
    $res_query1 mysql_query($select_query1)
        or die (
    "table error: " mysql_error());
    $res_rows mysql_num_rows($res_query1);
    //echo $res_rows;
    //$tr_res_query1 = mysql_fetch_array($res_query1);

    //or


         
    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-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        
    header("Content-Disposition: attachment;filename=Action_Report_".date('dmys').".xls");
        
    header("Content-Transfer-Encoding: binary ");
        
        
    //      dato                          
        // XLS Data Cell

                     
    xlsBOF();
                    
    xlsWriteLabel(0,0,"No.");
                    
    xlsWriteLabel(0,1,"Action Date");
                    
    xlsWriteLabel(0,2,"Action");
                    
    xlsWriteLabel(0,3,"Travel Agency");                
                    
    xlsWriteLabel(0,4,"Office ID");
                    
    xlsWriteLabel(0,5,"Terminal ID");
                    
    xlsWriteLabel(0,6,"SignInitials");        
                    
    xlsWriteLabel(0,7,"Comments");        
                    
    xlsWriteLabel(0,8,"Insert Date");                                                        

                    
    $xlsRow 1;    
                        while (
    $tr_res_query1 mysql_fetch_array($res_query1))
                        {
                                                
                    
                                                                 if(
    $_SESSION['archived_b']==1)
                                                                {
                                                                    
    $inserted_dato='N/A';
                                                                }
                                                                else
                                                                {    
    $inserted_dato=date("M j, Y h:i A"strtotime($tr_res_query1['datetimeo']));
                                                                }
                                                                
                                                                        
                        ++
    $i;
                              
    xlsWriteNumber($xlsRow,0,"$i");
                              
    xlsWriteLabel($xlsRow,1date('D dS \ M Y'strtotime($tr_res_query1['ActionDate'])));
                              
    xlsWriteLabel($xlsRow,2$tr_res_query1['Action']);
                              
    xlsWriteLabel($xlsRow,3,select_travel($tr_res_query1['OID']));                          
                              
    xlsWriteLabel($xlsRow,4$tr_res_query1['OID']);
                              
    xlsWriteLabel($xlsRow,5$tr_res_query1['ATID']);
                              
    xlsWriteLabel($xlsRow,6$tr_res_query1['SignInitials']);        
                              
    xlsWriteLabel($xlsRow,7$tr_res_query1['Comments']);    
                              
    xlsWriteLabel($xlsRow,8,$inserted_dato);                                                                                                
                
                        
    $xlsRow++;
                        
                        }
                    
                         
    xlsEOF();
                     exit();

    ?>

    my problem is that i need to export these data to *.xlsx format, i tried to make the name to
    PHP Code:
    Action_Report_".date('dmys').".xlsx
    but it did not work

    does anyone has a module or source code to make this task

    i need it quickly please

  2. #2
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,440
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    Hi John,

    You might want to take a look at the PHPExcel library, it can convert between quite a few different spreadsheet formats, including .xls and .xlsx


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •