Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-21-2005, 03:36 PM   PM User | #1
ItsMe
New Coder

 
Join Date: Mar 2005
Location: UK
Posts: 79
Thanks: 1
Thanked 0 Times in 0 Posts
ItsMe is an unknown quantity at this point
Use PHP to take data out of a spreadsheet

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!
__________________
Andrew,
AKA ItsMe
ItsMe is offline   Reply With Quote
Old 06-21-2005, 04:01 PM   PM User | #2
delinear
Regular Coder

 
Join Date: Feb 2005
Location: West Midlands, UK
Posts: 623
Thanks: 0
Thanked 0 Times in 0 Posts
delinear is an unknown quantity at this point
What format is the spreadsheet saved in? If you can save it as a .csv then 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.
__________________
~ Bazzy
delinear is offline   Reply With Quote
Old 06-21-2005, 04:05 PM   PM User | #3
ItsMe
New Coder

 
Join Date: Mar 2005
Location: UK
Posts: 79
Thanks: 1
Thanked 0 Times in 0 Posts
ItsMe is an unknown quantity at this point
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
__________________
Andrew,
AKA ItsMe
ItsMe is offline   Reply With Quote
Old 06-21-2005, 04:09 PM   PM User | #4
delinear
Regular Coder

 
Join Date: Feb 2005
Location: West Midlands, UK
Posts: 623
Thanks: 0
Thanked 0 Times in 0 Posts
delinear is an unknown quantity at this point
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.
__________________
~ Bazzy
delinear is offline   Reply With Quote
Old 06-21-2005, 04:14 PM   PM User | #5
ItsMe
New Coder

 
Join Date: Mar 2005
Location: UK
Posts: 79
Thanks: 1
Thanked 0 Times in 0 Posts
ItsMe is an unknown quantity at this point
I want it to fit in to a template like http://www.andrewthomas.org.uk/matt/template.htm.
__________________
Andrew,
AKA ItsMe
ItsMe is offline   Reply With Quote
Old 06-21-2005, 04:35 PM   PM User | #6
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.

Edit:
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).

Last edited by Fou-Lu; 06-21-2005 at 04:37 PM..
Fou-Lu is offline   Reply With Quote
Old 06-21-2005, 05:04 PM   PM User | #7
ItsMe
New Coder

 
Join Date: Mar 2005
Location: UK
Posts: 79
Thanks: 1
Thanked 0 Times in 0 Posts
ItsMe is an unknown quantity at this point
Im afraid i dont know what you mean.
__________________
Andrew,
AKA ItsMe
ItsMe is offline   Reply With Quote
Old 06-21-2005, 09:37 PM   PM User | #8
ItsMe
New Coder

 
Join Date: Mar 2005
Location: UK
Posts: 79
Thanks: 1
Thanked 0 Times in 0 Posts
ItsMe is an unknown quantity at this point
I have now got the fgetcsv working to some extent but its not quite there.

My code is:
PHP Code:
<?php

echo "<table>";

$handle fopen("info.csv""r");
$data fgetcsv($handle1000";");

# 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($handle1000";")) !== FALSE)
{
if(
$thisRow++ % == 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.
__________________
Andrew,
AKA ItsMe

Last edited by ItsMe; 06-21-2005 at 09:44 PM..
ItsMe is offline   Reply With Quote
Old 06-22-2005, 04:59 PM   PM User | #9
ItsMe
New Coder

 
Join Date: Mar 2005
Location: UK
Posts: 79
Thanks: 1
Thanked 0 Times in 0 Posts
ItsMe is an unknown quantity at this point
Can anyone help me with this?

I know we are so close to it!

Thanks
__________________
Andrew,
AKA ItsMe
ItsMe is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:14 AM.


Advertisement
Log in to turn off these ads.