Dumping to Excel

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
toppac
Forum Commoner
Posts: 29
Joined: Fri Jun 14, 2002 10:44 am

Dumping to Excel

Post by toppac »

How can I dump a recordset to an Excel file. I am using the OCI to run a sql query and I need to dump the result set to an Excel spreadsheet
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

Hi,

I just create a comma seperated file with all the records, when opened in Excel a wizard appears to help importing the file.

So logic is

Open a file for writing.
Open result set.
Iterate through result set concatenating field values with commas in between.
Write concatenated string to file.
repeat for each row.
Close file.

Hope this helps
toppac
Forum Commoner
Posts: 29
Joined: Fri Jun 14, 2002 10:44 am

Post by toppac »

Thanks, that will work. Now can you point me to the class/functions to do that with? I am not sure how to write to flatfiles.
User avatar
e+
Forum Commoner
Posts: 44
Joined: Mon Jun 17, 2002 7:07 am
Location: Essex, UK

Post by e+ »

on a side note if you use

Fields terminated by = ,
Fields enclosed by = “
Fields escaped by = \
Lines terminated by = \r\n

Excel won't run the wizard and will just open the file.
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

toppac wrote:Thanks, that will work. Now can you point me to the class/functions to do that with? I am not sure how to write to flatfiles.
You will find them here
Post Reply