...

View Full Version : Use PHP to take data out of a spreadsheet



ItsMe
06-21-2005, 04:36 PM
I dont know if this is possible but if anyone could help me it would be great.

I have data of several people in an excel spreadsheet (eg. name, email etc.) and want to take certain columns out and put them into a PHP page.

So i want to take details about users that they have provided, such as name and email and for the PHP to take the data for every person and put it in a table on the page.

Hope you understand!

delinear
06-21-2005, 05:01 PM
What format is the spreadsheet saved in? If you can save it as a .csv then fgetcsv (http://uk2.php.net/fgetcsv) lets you read a csv file and returns the data in an array ready for you to display on your page as you want.

ItsMe
06-21-2005, 05:05 PM
I have looked at fgetcsv but because i am fairly new to PHP do not understand how to make it look as i want. i can get to display on a page as seen here http://www.andrewthomas.org.uk/matt/excel.php but dont know where to go from there.

Thanks

delinear
06-21-2005, 05:09 PM
Well, getting it to look the way you want is an HTML issue rather than a PHP issue. If you have a HTML template of how you want the data to look, though, we can help you with getting the data to match your template.

ItsMe
06-21-2005, 05:14 PM
I want it to fit in to a template like http://www.andrewthomas.org.uk/matt/template.htm.

Fou-Lu
06-21-2005, 05:35 PM
Excel can be saved as an XML, which I would recommend.
Actually, I'm in the works with a project right now thats very similar, I take a spreadsheet containing employee's numbers, firstname and last name and insert them into a database. I use the php DOM functions to do this.
Sorry, as of right now though, I haven't started the work with the XML from the spreadsheets yet, just the word documents. In the near future I'll have a better answer for you.
Now, if you simply want to display as html, look at using an xsl stylesheet instead, the xml guys can help you with that one. If you need to extract and use the information with php, its dom your after, which I will be able to help you with.


Looks like your after an xsl. Once you create one, it would be simple to use either as an embedded stylesheet (browser specific) or by server side conversion (universal).

ItsMe
06-21-2005, 06:04 PM
Im afraid i dont know what you mean. :confused:

ItsMe
06-21-2005, 10:37 PM
I have now got the fgetcsv working to some extent but its not quite there.

My code is:

<?php

echo "<table>";

$handle = fopen("info.csv", "r");
$data = fgetcsv($handle, 1000, ";");

# column headers from 1st row of CSV:
echo "<tr>";
foreach($data as $value)
{
echo "<th>$value</th>";
}
echo "</tr>\n";

# data rows:
$thisRow = 1;
while (($data = fgetcsv($handle, 1000, ";")) !== FALSE)
{
if($thisRow++ % 2 == 0)
{
$bg = "silver";
}
else
{
$bg = "white";
}
echo "<tr style='background-color: $bg'>";
foreach($data as $value)
{
echo "<td>$value</td>";
}
echo "</tr>\n";
}
echo "</table>\n";
?>
This outputs http://andrewthomas.org.uk/matt/csv%20test.php.

What i now wish to do it put it in a table with the data in seperate columns, as opposed to just next to each other in a row as it is now.

Thanks for all your help so far and i hope someone can help me finish the project off.

ItsMe
06-22-2005, 05:59 PM
Can anyone help me with this?

I know we are so close to it!

Thanks :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum