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 11-19-2012, 02:40 PM   PM User | #1
ebookz
New Coder

 
Join Date: Nov 2012
Posts: 33
Thanks: 23
Thanked 0 Times in 0 Posts
ebookz is an unknown quantity at this point
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..
ebookz is offline   Reply With Quote
Old 11-19-2012, 03:53 PM   PM User | #2
firepages
Super Moderator


 
Join Date: May 2002
Location: Perth Australia
Posts: 3,896
Thanks: 5
Thanked 79 Times in 78 Posts
firepages will become famous soon enough
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)
firepages is offline   Reply With Quote
Users who have thanked firepages for this post:
ebookz (11-19-2012)
Old 11-19-2012, 04:25 PM   PM User | #3
ebookz
New Coder

 
Join Date: Nov 2012
Posts: 33
Thanks: 23
Thanked 0 Times in 0 Posts
ebookz is an unknown quantity at this point
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
ebookz is offline   Reply With Quote
Old 11-19-2012, 04:57 PM   PM User | #4
ebookz
New Coder

 
Join Date: Nov 2012
Posts: 33
Thanks: 23
Thanked 0 Times in 0 Posts
ebookz is an unknown quantity at this point
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..
ebookz is offline   Reply With Quote
Old 11-19-2012, 05:26 PM   PM User | #5
ebookz
New Coder

 
Join Date: Nov 2012
Posts: 33
Thanks: 23
Thanked 0 Times in 0 Posts
ebookz is an unknown quantity at this point
my actual problem is :Import Excel (XLS) document into MySQL database
ebookz 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 10:59 PM.


Advertisement
Log in to turn off these ads.