[thelist] MySQL to Excel Problem

Jeremy Ashcraft ashcraft at 13monkeys.com
Wed May 1 11:57:01 CDT 2002


I guy I work has used  psxlsgen ( http://psxlsgen.sourceforge.net ) to
generate Excel reports in PHP.....pretty cool stuff......

hth

jeremy

Jay Blanchard wrote:

>Howdy all!
>
>Some of my users want Excel reports from MySQL databases, so I have done the
>following with PHP;
>
><!--BEGIN CODE-->
><?
>header("Content-Type:  application/x-excel");
>header("Content-Disposition: inline;
>filename=\"excel.xls\"");
>
>header("Expires: 0");
>
>header("Cache-Control: must-revalidate, post-check=0,
>pre-check=0");
>
>//connect to and select database
>if(!($dbconnect = mysql_pconnect("127.0.0.1", "user", "password"))){
>	print("Failed to connect to database!\n");
>	exit();
>	}
>if(!mysql_select_db("rcr", $dbconnect)){
>	print("Failed to select database!\n");
>	exit();
>	}
>//query
>$qrecord = "SELECT DISTINCT RecordID ";
>$qrecord .= "FROM tblClass10 ";
>?>
>
><table>
><tr>
><td></td>
><?
>while($dbrow = mysql_fetch_object($dbrecord)){
>	print("<td>");
>	print($dbrow->RecordID);
>	print("</td>\n");
>	}
>?>
></tr>
></table>
><!--END CODE-->
>
>If I name the file with a .xls extension it displays the code in the excel
>worksheet in the browser. If I name the file with the .php extension it
>opens Excel seperately, gives me a file download option (I click 'Open') and
>then asks me to tell it what created the file, so I pick Excel. Then the
>data is displayed  properly in the Excel worksheet, outside of the browser.
>I want the file to open an Excel worksheet in the browser (IE, on an
>Intranet). Is there something I am missing?
>
>Thanks!
>
>Jay
>
>
>






More information about the thelist mailing list