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

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
Laura Croft

Fri Mar 07, 2003 3:41 am

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.

User avatar
Posts: 826
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

Sat Mar 08, 2003 10:48 am

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.

Laura Croft

Mon Mar 10, 2003 6:33 am

Thank you very much!

Problem solved! :D

Laura Croft

Mon Mar 10, 2003 6:36 am

...oh no. It shows data as a table, but NOT an excel file...

Oleg Butuzov
Last Samuray
Last Samuray
Posts: 824
Joined: Sun Jun 02, 2002 3:09 am

Mon Mar 10, 2003 7:06 am

if you want to create xls file you must use COM objects

Post Reply