Page 1 of 1

PHP and EXCEL docs

Posted: Tue Sep 17, 2002 9:21 am
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

Posted: Tue Sep 17, 2002 11:01 am
by Takuma
Use COM, search through Google!

Posted: Tue Sep 17, 2002 11:11 am
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);
}

?>

Posted: Tue Sep 17, 2002 12:14 pm
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

Posted: Tue Sep 17, 2002 12:16 pm
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

Posted: Tue Sep 17, 2002 1:06 pm
by Wandrer

Posted: Tue Sep 17, 2002 1:20 pm
by jason

php & excel author

Posted: Thu Sep 19, 2002 7:31 am
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?

Posted: Thu Sep 19, 2002 7:34 am
by Takuma

Posted: Thu Sep 19, 2002 7:38 am
by twigletmac