#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2009
    Posts
    106
    Rep Power
    6

    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
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    xls and xlsx are completely different. All the "x" microsoft documents are XML based (hence the X) and is a completely different file format. You're going to have to start from scratch.

    Though there's really no reason for this requirement in the first place.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  4. #3
  5. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7171
    The easiest way to export to XLSX from PHP is to use a library like PHPExcel.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

IMN logo majestic logo threadwatch logo seochat tools logo