how can i view data in the excel sheet

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
softsolvers
Forum Commoner
Posts: 75
Joined: Fri Feb 13, 2004 4:26 am
Location: India

how can i view data in the excel sheet

Post by softsolvers »

hello friends i want to view my data in the excell sheet which will be fetched by the mysql.could you help me
User avatar
softsolvers
Forum Commoner
Posts: 75
Joined: Fri Feb 13, 2004 4:26 am
Location: India

Plz help on this matter

Post by softsolvers »

hello friends,
i want to view the data fetched from the mysql data base o the excel sheet can u suggest me that what should i do.
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

And once you have the MySQL stuff down:
http://builder.com.com/5100-31-5077752.html
Suppose you're running an intranet Web site that has data stored in Microsoft SQL Server, and your users need that data in Excel format. You can have PHP run the necessary SQL queries and format the output, then use COM to open Excel, dump the data stream into it, and save the file on the user's desktop.
User avatar
Dr Evil
Forum Contributor
Posts: 184
Joined: Wed Jan 14, 2004 9:56 am
Location: Switzerland

Post by Dr Evil »

- Make a page that fetches all the data by line in CSV format.
- dont forget to add the right header :

Here is a code I wrote a moment ago (in French) PHP:

Code: Select all

<?php

header("Content-type: application/octet-stream"); 
header("Content-Disposition: attachment; filename=table.csv"); 
header("Content-Transfer-Encoding: binary"); 

include ("Connections/localhost.php"); //contains all connection params 

$connection = mysql_connect ("$hostname_localhost", "$username_localhost", "$password_localhost"); 
   $query = "SELECT * FROM sirca_concours"; 
   $result= mysql_db_query ("$database_localhost", $query); 
   $numOfRows = mysql_num_rows($result); 

for ($i = 0; $i < $numOfRows; $i++){ 
   $civilite    = mysql_result ($result, $i, civilite); 
   $prenom      = mysql_result ($result, $i, prenom); 
   $nom      = mysql_result ($result, $i, nom); 
   $adresse1    = mysql_result ($result, $i, adresse1); 
   $adresse2   = mysql_result ($result, $i, adresse2); 
   $ville      = mysql_result ($result, $i, ville); 
   $npa      = mysql_result ($result, $i, npa); 
   $pays      = mysql_result ($result, $i, pays); 
   $email      = mysql_result ($result, $i, email); 

print ""$civilite","$prenom","$nom","$adresse1","$adresse2","$ville","$npa","$pays","$email"\n"; 
} 
?>
Did I understand correctly ?
User avatar
softsolvers
Forum Commoner
Posts: 75
Joined: Fri Feb 13, 2004 4:26 am
Location: India

dispalying on excel sheety

Post by softsolvers »

hello friends,
can you tell me what these header exactly stand for and what should be the actual code in that header if i am running code on local machine
looking f/w for result
User avatar
softsolvers
Forum Commoner
Posts: 75
Joined: Fri Feb 13, 2004 4:26 am
Location: India

Post by softsolvers »

hello friends
can u help me it is urgent,plz. send me the snap shot of source code
User avatar
Dr Evil
Forum Contributor
Posts: 184
Joined: Wed Jan 14, 2004 9:56 am
Location: Switzerland

Post by Dr Evil »

I don't quite get your question. These headers tell the browser that a csv document is being sent. So in fact the main page must simply link to this one. When the user clicks the link he'll get a" do you want to open or save?" box.
This works locally or on a remote machine.
If my answer is beside the point be more specific.


Evil
User avatar
softsolvers
Forum Commoner
Posts: 75
Joined: Fri Feb 13, 2004 4:26 am
Location: India

how can i take the drop down menu's value on the same page

Post by softsolvers »

hello friends
i want to take the value of the drop down menu on the same page means if user has selected his choice and the corresponding action has perform according to the selection.
User avatar
softsolvers
Forum Commoner
Posts: 75
Joined: Fri Feb 13, 2004 4:26 am
Location: India

Post by softsolvers »

thanks dr.
but problem is still the same,i.e. it is not displaying the excel sheet should i need to modify the php.ini file,i am using versio 4.3.4 is it make any difference.
plz. do help me
User avatar
Dr Evil
Forum Contributor
Posts: 184
Joined: Wed Jan 14, 2004 9:56 am
Location: Switzerland

Post by Dr Evil »

I'm lost in your problem. The excel software is running locally on the user's PC/MAC so I do not see what the php.ini config has to do with this. Can you show me the page ?

Dr Evil
User avatar
softsolvers
Forum Commoner
Posts: 75
Joined: Fri Feb 13, 2004 4:26 am
Location: India

Post by softsolvers »

thanks dr.
actually i was not running it properly ,it is running well thanks very much
i will be very greatful if i would help u by any mean
Sinemacula
Forum Contributor
Posts: 110
Joined: Sat Feb 08, 2003 2:36 am
Location: San Jose, CA

An additional wrinkle...

Post by Sinemacula »

I'm trying to do something similar, and I follow the script you've posted... but I've got another piece to what I'm trying which leaves me unsure how to proceed...

I want to be able to choose between several tables, which one I want to download as a csv file... (I've figured this part out, using a variable for the table name)... the catch is that each table has a different number of (and names of) fields, so I can't use the fieldnames to create the output. Is there a way to write the script so that it will figure that out on it's own?

Thanks,
Scott
Post Reply