Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Mar 2005
    Location
    UK
    Posts
    79
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #3
    New Coder
    Join Date
    Mar 2005
    Location
    UK
    Posts
    79
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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

  • #4
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #5
    New Coder
    Join Date
    Mar 2005
    Location
    UK
    Posts
    79
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I want it to fit in to a template like http://www.andrewthomas.org.uk/matt/template.htm.
    Andrew,
    AKA ItsMe

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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.

  • #7
    New Coder
    Join Date
    Mar 2005
    Location
    UK
    Posts
    79
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Im afraid i dont know what you mean.
    Andrew,
    AKA ItsMe

  • #8
    New Coder
    Join Date
    Mar 2005
    Location
    UK
    Posts
    79
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.
    Last edited by ItsMe; 06-21-2005 at 09:44 PM.
    Andrew,
    AKA ItsMe

  • #9
    New Coder
    Join Date
    Mar 2005
    Location
    UK
    Posts
    79
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Can anyone help me with this?

    I know we are so close to it!

    Thanks
    Andrew,
    AKA ItsMe


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •