Page 1 of 1

how send db data to an excel file through php ?!?

Posted: Fri Mar 07, 2003 3:41 am
by Laura Croft
Hi all.

I'm developing an intranet with php and it's almost finished but there's one section that doesn't work.

When someone wants to get reports of some data stored in a data base, i give them the possibility of watching the reports on the screen (a table showing the results of the query) or watching them in an EXCEL file (through a php page) by clicking on an "excel format" button.

The problem is that when i click on that button an excel file opens into the php page (as desired) but it's completely empty, though i try and send the result of the query to the file.

Do you have any idea of how to make it in an easy way? I wouldn't like to use big and complicated php classes as i've seen while looking for solutions on the internet.

Thank you very much.

Posted: Sat Mar 08, 2003 10:48 am
by Redcircle
how are you sending the data to an excel file.

what I would do is. If they have excel 97 or later.

Code: Select all

$query = 'select * from table';
$result = mysql_query($query);
header('Content-type: application/');
echo '<table>';
while($row = mysql_fetch_array($result))
  echo '<tr><td>'.$row['field1'].'</td><td>'.$row['field2'].'</td><td>'.$row['field3'].'</td></tr>';

echo '</table>';

that should open up excel within the browser and have your data in it.

another way to do it is put the info in a .csv file deliminated by ','

if you have an excel file already do an export to .csv and you will see what I mean.

Posted: Mon Mar 10, 2003 6:33 am
by Laura Croft
Thank you very much!

Problem solved! :D

Posted: Mon Mar 10, 2003 6:36 am
by Laura Croft
...oh no. It shows data as a table, but NOT an excel file...

Posted: Mon Mar 10, 2003 7:06 am
by Oleg Butuzov
if you want to create xls file you must use COM objects