Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

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

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

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

Postby 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.
Laura Croft
New php-forum User
New php-forum User
 
Posts: 5
Joined: Fri Mar 07, 2003 1:00 am

Postby Redcircle » 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/vnd.ms-excel');
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.
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

Postby Laura Croft » Mon Mar 10, 2003 6:33 am

Thank you very much!

Problem solved! :D
Laura Croft
New php-forum User
New php-forum User
 
Posts: 5
Joined: Fri Mar 07, 2003 1:00 am

Postby Laura Croft » Mon Mar 10, 2003 6:36 am

...oh no. It shows data as a table, but NOT an excel file...
Laura Croft
New php-forum User
New php-forum User
 
Posts: 5
Joined: Fri Mar 07, 2003 1:00 am

Postby Oleg Butuzov » Mon Mar 10, 2003 7:06 am

if you want to create xls file you must use COM objects
Oleg Butuzov
Last Samuray
Last Samuray
 
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 7 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron