SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: PHP Class problem
-
Apr 7, 2009, 07:24 #1
- 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; } }
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();
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
-
Apr 7, 2009, 08:12 #2
enable error reporting in your files:
PHP Code:<?php
ini_set("display_errors", 1);
error_reporting(E_ALL);
PHP Code:xlsWriteLabel(0, 0, $excelsheettitle);
PHP Code:$xlsdownload->xlsWriteLabel(0, 0, $excelsheettitle);
my mobile portal
ghiris.ro
-
Apr 7, 2009, 08:23 #3
- Join Date
- Nov 2005
- Posts
- 43
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Bookmarks