View Full Version : Use PHP to take data out of a spreadsheet
06-21-2005, 03: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!
06-21-2005, 04: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.
06-21-2005, 04: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.
06-21-2005, 04: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.
06-21-2005, 04:14 PM
I want it to fit in to a template like http://www.andrewthomas.org.uk/matt/template.htm.
06-21-2005, 04: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).
06-21-2005, 05:04 PM
Im afraid i dont know what you mean. :confused:
06-21-2005, 09:37 PM
I have now got the fgetcsv working to some extent but its not quite there.
My code is:
$handle = fopen("info.csv", "r");
$data = fgetcsv($handle, 1000, ";");
# column headers from 1st row of CSV:
foreach($data as $value)
# data rows:
$thisRow = 1;
while (($data = fgetcsv($handle, 1000, ";")) !== FALSE)
if($thisRow++ % 2 == 0)
$bg = "silver";
$bg = "white";
echo "<tr style='background-color: $bg'>";
foreach($data as $value)
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.
06-22-2005, 04:59 PM
Can anyone help me with this?
I know we are so close to it!
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.