Excel Import issue in PHP

Discussion in 'PHP' started by prassunair, Mar 12, 2007.

  1. #1
    Hai All,

    I have a complex excel sheet ,wich contains details of companies and I need to import that using php and will store in a database…In the data base also multiple tables to manage this fields. How I can do this one using php??


    regards,

    Prasanth
     
    prassunair, Mar 12, 2007 IP
  2. rays

    rays Active Member

    Messages:
    563
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #2
    Prasanth,

    One option can be done is export excel document in CSV format and then use plain text file handling logic for grabbing data from file..

    If you want to incorporate excel as it is then you may need some extra libraries which can read the meta data of excel file and process the file.

    honestly i have done data exporting in excel using some open source excel php library ...

    but CSV seems to be beat option in first iteration
     
    rays, Mar 13, 2007 IP
  3. DeViAnThans3

    DeViAnThans3 Peon

    Messages:
    785
    Likes Received:
    83
    Best Answers:
    0
    Trophy Points:
    0
    #3
    CSV is indeed one of the better options; but note that it *might* be easier to use excel classes too phpExcel
     
    DeViAnThans3, Mar 13, 2007 IP
  4. jitesh

    jitesh Peon

    Messages:
    81
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Please review following scripts.
    It may be useful.

    <?php
    $row = 1;
    $handle = fopen("test.csv", "r");
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
    $num = count($data);
    echo "<p> $num fields in line $row: <br /></p>\n";
    $row++;
    for ($c=0; $c < $num; $c++) {
    echo $data[$c] . "<br />\n";
    }
    }
    fclose($handle);
    ?>
     
    jitesh, Mar 15, 2007 IP