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