PHP and EXCEL docs

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
grcodal
Forum Newbie
Posts: 4
Joined: Tue Sep 17, 2002 9:21 am

PHP and EXCEL docs

Post by grcodal »

Is there anyway i can read data from an excel document in a php script, like from a database???

Please help me!!!
Sincerly,
Codrin
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Use COM, search through Google!
User avatar
mr_griff
Forum Commoner
Posts: 64
Joined: Tue Sep 17, 2002 11:11 am
Location: Bozeman, Montana

Post by mr_griff »

Saving the excel doc as a fixed formatted or csv file makes it much easier to work with. Then you can just open the file and read in one line at a time. Then take each line and explode the different columns into an array.

Code: Select all

<?php

//Open the file
$fp = fopen("exceldoc.csv","r");

//Try to read in the first line of the file
$line = fgets($fp,9000);

//Keep reading until the end of the file
while (!feof($fp))
{
  //Split the colums in to an array
  $info_array = explode(",",$line);
  $col1 = $info_arrayї0];
  $col2 = $info_arrayї1];
  $col3 = $info_arrayї2];
  $col4 = $info_arrayї3];

  //Do something with the information

  //Try to read in the next line
  $line = fgets($fp,9000);
}

?>
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

Hey,

Well, if you could parse excels format, then you're in luck, but i'm sure that has to be a very difficult thing to do. There is a project on sourceforge to create excel docs using php, but I'm not sure of the extent of it. I would suggest check with them to see how far they've come or if they can help you.

Another thing: Google is your freind. Try searching there.

One more thing. Does it have to be in an .xls format? I remeber from my much hated MicroRiech days that you could dump excel files into delimited text files. Wouldn't this be easier to deal with?

Cheers,
BDKR
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

Did we all just post at nearly the same time? When I started there were no responses.

And by the way Takuma, that's the smartest idea I've heard yet. Good job!

Cheers,
BDKR
Wandrer
Forum Newbie
Posts: 21
Joined: Thu Jun 06, 2002 8:43 am

Post by Wandrer »

jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

grcodal
Forum Newbie
Posts: 4
Joined: Tue Sep 17, 2002 9:21 am

php & excel author

Post by grcodal »

Thanks for the replys, I'm a beginner in PHP and programming, can you be more specific.

how can I use COM with PHP exactly?
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Post Reply