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 5 of 5
  1. #1
    New Coder
    Join Date
    Nov 2012
    Posts
    33
    Thanks
    23
    Thanked 0 Times in 0 Posts

    Question php Excel Reader code problem

    This is my mydata.xls excel sheet image:

    php code :
    PHP Code:
    <?php
        
    // include class file
        
    include("Excel/reader.php");
        
        
    // initialize reader object
        
    $excel = new Spreadsheet_Excel_Reader();
        
        
    // read spreadsheet data...
        
    $excel->read('mydata.xls');    
        
        
    // iterate over Excel sheet cells and save to database table//////////
        
    $x=2;
        while(
    $x<=$excel->sheets[0]['numRows']) {
          
          
    $y=1;
          while(
    $y<=$excel->sheets[0]['numCols']) {
              
        
    //check empty cell...
       
    if(isset($excel->sheets[0]['cells'][$x][$y])){
         
    //save data to an array..
         
    $z=$y-1;
         
    $data[$z]=$excel->sheets[0]['cells'][$x][$y];
        
           }
            
    $y++;
          } 
    //end 2 while 
          
          //store array values to variables..
          
    $st_id=$data[0];
          
    $marks=$data[1];
          
    $co_type=$data[2];
          
    $status=$data[3];
          
          echo 
    $st_id."</br>";
          
          
    $x++;
        }
    //end 1 while

        
    ?>
    out put :
    problem: how to stop showing last row repeated.....?????????????last row value print many no of times how to stop that?? plzz tell the code error & how to fix this problem???? Actually I'm trying to insert those data to my database table..before do that I tried to print one of this variable & see the result...
    Last edited by ebookz; 11-19-2012 at 03:57 PM.

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,084
    Thanks
    11
    Thanked 100 Times in 98 Posts
    even an empty excel file has a couple of thousand rows
    so you need to query how many rows actually have data in them... or at least test for when the data stops.

    I have never parsed excel spreadsheets but I guess you would watch for an empty cell to guess where the spreadsheet data is no more ... or set a flag.. this is a total guess by the way.

    PHP Code:
    while($x<=$excel->sheets[0]['numRows']) { 
        if(empty(
    $excel->sheets[0]['cells'][$x][0])){
           
    #first cell is empty , is this the end of the usable data ?
           
    break;
        }
    ... 
    etc 
    also please stop with the massive red text, its annoying
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • Users who have thanked firepages for this post:

    ebookz (11-19-2012)

  • #3
    New Coder
    Join Date
    Nov 2012
    Posts
    33
    Thanks
    23
    Thanked 0 Times in 0 Posts

    Question

    Quote Originally Posted by firepages View Post
    even an empty excel file has a couple of thousand rows
    so you need to query how many rows actually have data in them... or at least test for when the data stops.

    I have never parsed excel spreadsheets but I guess you would watch for an empty cell to guess where the spreadsheet data is no more ... or set a flag.. this is a total guess by the way.

    PHP Code:
    while($x<=$excel->sheets[0]['numRows']) { 
        if(empty(
    $excel->sheets[0]['cells'][$x][0])){
           
    #first cell is empty , is this the end of the usable data ?
           
    break;
        }
    ... 
    etc 
    also please stop with the massive red text, its annoying
    I tried ur idea..but can not fix my error...still probelm is going

  • #4
    New Coder
    Join Date
    Nov 2012
    Posts
    33
    Thanks
    23
    Thanked 0 Times in 0 Posts
    can anyone plzz tell me how to insert above excel sheet data to mysql daatabse by using phpexcel??????????
    Last edited by ebookz; 11-19-2012 at 05:00 PM.

  • #5
    New Coder
    Join Date
    Nov 2012
    Posts
    33
    Thanks
    23
    Thanked 0 Times in 0 Posts
    my actual problem is :Import Excel (XLS) document into MySQL database


  •  

    Posting Permissions

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