SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP Class problem

    Hi,

    I've got the following class but on trying to use it the excel file is not created properly and gives an error message (basically stating that it is not in excel format and cannot be opened).

    The code for the class is as follows:

    Code:
    class XLSExport {
    
        function ExportHeader($exportfilename)
        {
            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=" . $exportfilename);
            header("Content-Transfer-Encoding: binary ");
        }
        
        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;
        }
      }
    And the file utilising the class is as follows:

    Code:
      require(DIR_WS_CLASSES . 'export_excel.php');
    
    $customersresult=tep_db_query("SELECT customers_firstname, customers_lastname, customers_telephone from customers order by customers_lastname asc");
    
    $xlsdownload = new XLSExport;
    
    $xlsfilename = 'customerlisting.xls';
    $xlsdownload->ExportHeader($xlsfilename); 
    
    $xlsdownload->xlsBOF();
    
    $excelsheettitle = 'Customer Listing';
    xlsWriteLabel(0,0,$excelsheettitle);
    
    $xlsdownload->xlsWriteLabel(2,0,"Last Name");
    $xlsdownload->xlsWriteLabel(2,1,"First Name");
    
    $xlsRow = 3;
    
    while($customersrow = tep_db_fetch_array($customersresult)){
    $xlsdownload->xlsWriteLabel($xlsRow,0,$customersrow['customers_lastname']);
    $xlsdownload->xlsWriteLabel($xlsRow,1,$customersrow['customers_firstname']);
    
    $xlsRow++;
    }
    $xlsdownload->xlsEOF();
    exit();
    I'm totally new to classes and cannot see where I am falling down?

    The excel file is created and downloaded, albeit with the errors mentioned above? The file size is 200 bytes so I assume there is no data.

    Any help glady received.

    Thanks

  2. #2
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    enable error reporting in your files:
    PHP Code:
    <?php
    ini_set
    ("display_errors"1);
    error_reporting(E_ALL);
    change:
    PHP Code:
    xlsWriteLabel(00$excelsheettitle); 
    to
    PHP Code:
    $xlsdownload->xlsWriteLabel(00$excelsheettitle); 
    my mobile portal
    ghiris.ro

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are a God send!!!

    Thank you! What a thing to miss, lesson learned; don't code when you've only had 4 hours sleep.

    Thanks again!

    Quote Originally Posted by Ernie1 View Post
    enable error reporting in your files:
    PHP Code:
    <?php
    ini_set
    ("display_errors"1);
    error_reporting(E_ALL);
    change:
    PHP Code:
    xlsWriteLabel(00$excelsheettitle); 
    to
    PHP Code:
    $xlsdownload->xlsWriteLabel(00$excelsheettitle); 


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
  •