PHP Classes

bad xls file

Recommend this page to a friend!

      MS-Excel Stream Handler  >  All threads  >  bad xls file  >  (Un) Subscribe thread alerts  
Subject:bad xls file
Summary:the code generates a .xls file, but content is in a single cell
Messages:31
Author:Jim A
Date:2005-01-21 03:07:09
Update:2009-10-09 05:13:59
 
  1 - 10   11 - 20   21 - 30   31 - 31  

  31. Re: bad xls file   Reply   Report abuse  
Picture of greatknowledge greatknowledge - 2009-10-09 05:13:59 - In reply to message 30 from greatknowledge
I managed to modify the codes, it will read from database, format the data generate the excel and download the excel.


<?php
/**
* MS-Excel stream handler
* Excel export example
* @author Ignatius Teo <ignatius@act28.com>
* @copyright (C)2004 act28.com <http://act28.com>
* @date 21 Oct 2004
*/
require_once "excel.php";
$xlsfilename = "ApprovedMember_".strftime('%Y%m%d%H%M%S').".xls";
$export_file = "xlsfile://tmp/".$xlsfilename;
$fp = fopen($export_file, "wb");
if (!is_resource($fp))
{
die("Cannot open $export_file");
}

// typically this will be generated/read from a database table
$assoc = array();
$arrayIndex = 0;
$username="database_user";
$password="database_password";
$database="database_name";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$result = mysql_query("SELECT a.ID, a.MemberNo, a.IssueDate, a.Name, a.Occupation, b.nationality_desc, a.Email, a.Address, a.ICPPNO, a.Contact, a.Gender, a.Type, a.MembershipStatus, a.RecieveEmail, a.CardPostage, a.PaymentMode, a.nricpp_doc FROM TABLE_Member a, TABLE_nationality b where b.nationality_code = a.Nationality and a.MembershipStatus = 'APPROVED'");
while($row = mysql_fetch_array($result))
{
$ID = $row['ID'];
$MemberNo = $row['MemberNo'];
$IssueDate = $row['IssueDate'];
$Name = $row['Name'];
$Occupation = $row['Occupation'];
$nationality_desc = $row['nationality_desc'];
$Email = $row['Email'];
$Address = $row['Address'];
$ICPPNO = $row['ICPPNO'];
$Contact = $row['Contact'];
$Gender = $row['Gender'];
$Type = $row['Type'];
$Status = $row['MembershipStatus'];
$RecieveEmail = $row['RecieveEmail'];
$CardPostage = $row['CardPostage'];
$PaymentMode = $row['PaymentMode'];
$nricpp_doc = $row['nricpp_doc'];
$assoc[$arrayIndex] = array("Member No." => $MemberNo, "Issue Date" => $IssueDate, "Name" => $Name, "Gender" => $Gender, "Nationality" => $nationality_desc, "Email" => $Email, "Address" => $Address);
$arrayIndex = $arrayIndex + 1;
}
mysql_close();


fwrite($fp, serialize($assoc));
fclose($fp);

#header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
#header ("Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
header ("Content-type: application/x-msexcel");
header ("Content-Disposition: attachment; filename=\"" . basename($export_file) . "\"" );
header ("Content-Description: PHP/MySQL Generated Data" );
readfile($export_file);
exit;

?>

 
  1 - 10   11 - 20   21 - 30   31 - 31