Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Dec 2008
    Posts
    127
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    xls <> xlsx.
    If would probably be easier to work with their schema instead and provide it with XML than to build it from packed binary. Microsoft lists the schema's available here: http://msdn.microsoft.com/en-us/libr...ice.12%29.aspx
    As you can see, they are *not* simple. It would be best to save an existing as an xml format, and study the structure. It is somewhat easy to follow once you've gone over it a few times (I use xml based xlsx files stacked with xslt to import into an *cough*access dbms*cough* ).
    Alternatively, someone may have a library up to deal with these files at a binary level. I haven't a clue where to even start with those. A website I found here: https://phpexcel.codeplex.com/wikipage?title=Examples may have more information about that.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

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