473,388 Members | 1,600 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

count last row in a excel file

ganesanji
Hi all,


I have written a php coding for uploading a csv file to database. I want to know the last row of the csv file. How to calculate the the last row of the excel file using php coding. Please anyone give me help.... I am not good in english if u found any mistake in my words plz dont mistake me......

Please send me the php coding to calculate the last row of excel file....


thanks.
Oct 9 '07 #1
8 19224
Atli
5,058 Expert 4TB
Hi.

Have you made any attempt at this yourself?
Could we see what you did?
Why (how) did it not work?
Are you getting any errors?

We are more than happy to help you solve problems you are having with your code, but we won't write the code for you.
Oct 9 '07 #2
Hi.

Have you made any attempt at this yourself?
Could we see what you did?
Why (how) did it not work?
Are you getting any errors?

We are more than happy to help you solve problems you are having with your code, but we won't write the code for you.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3. ?>
  4. <?php
  5.   $name1=$_SESSION['name'];  
  6.   $file1=$_SESSION['path'];
  7.   echo $file1;
  8.   echo "<br/>";
  9.   require_once('reader.php'); // include the class
  10.   $data = new Spreadsheet_Excel_Reader(); // instantiate the object
  11.   $data->setOutputEncoding('CP1251'); // select output encoding
  12.   $data->read("$file1/*.xls"); // specify the file to read
  13. /* We start reading the file from row 4 because that's where the 
  14.   data in the table starts */
  15.    $startRow = 2;
  16.  
  17. /* Get all the cells of the sheet */
  18.   $cells = $data->sheets[0]['cells'];
  19. /* We create a nice table to display the data */
  20. //  echo "<table border='1' style='font-size:14px;font-family:Arial;'>
  21. //  <tr><td>Phone No.</td><td>First Name</td><td>Last Name</td><td>Address1</td><td>Address2</td><td>State</td><td>City</td>
  22. //  <td>Zip</td></tr>";
  23. /* Loop through the table. In this case we know that the table has only
  24.   4 rows.*/
  25.   for ($row = $startRow;$row <= 10;$row++) 
  26.  
  27.   {
  28.   /* Assign all the columns */
  29.   $phone = $cells[$row][1]; 
  30.   $firstname = $cells[$row][2];
  31.   $lastname = $cells[$row][3];
  32.   $address1 = $cells[$row][4];
  33.   $address2 = $cells[$row][5];
  34.   $state = $cells[$row][6];
  35.   $city = $cells[$row][7];
  36.   $zip = $cells[$row][8];
  37.   $id = $cells[$row][9];
  38.  /* Then display them 
  39.   echo "<tr><td>" . $phone . "</td>";
  40.   echo "<td>" . $firstname . "</td>";
  41.   echo "<td>" . $lastname . "</td>";
  42.   echo "<td>" . $address1 . "</td>";
  43.   echo "<td>" . $address2 . "</td>";
  44.   echo "<td>" . $state . "</td>";
  45.   echo "<td>" . $city . "</td>";
  46.   echo "<td>" . $zip . "</td>";
  47.   echo "<td>" . $id . "</td></tr>";  */
  48.   mysql_connect('localhost','root','123456');
  49.   mysql_select_db("dialer");  
  50.   mysql_query("insert into $name1(phone,firstname,lastname,address1,address2,state,city,zip)values('$phone','$firstname',
  51.   '$lastname','$address1','$address2','$state','$city','$zip')");  
  52.   }
  53.   echo "Successfully Inserted";
  54.   ?>
  55.  
In this code I used one for loop that loop I specified the range limit that is 10 ,
we don't know how many rows data is there .so that I want the last
row in every file how to find .
Oct 10 '07 #3
Atli
5,058 Expert 4TB
OK. I think I understand how the Spreadsheet_Excel_Reader object works.

You should be able to find the last row somewhat like this:
Expand|Select|Wrap|Line Numbers
  1. # Get first sheet
  2. $sheet = $data->sheets[0];
  3.  
  4. # Get all rows in the sheet
  5. $rows = $sheet['cells'];;
  6.  
  7. # Find total number of rows
  8. $rowCount = count($rows);
  9.  
  10. # Show data from last row
  11. echo "<table><tr>";
  12. foreach($rows[$rowCount -1] as $col) {
  13.   echo "<td>$col</td>";
  14. }
  15. echo "</tr></table>";
  16.  
P.S.
Please use [code] tags when posting source code. It is impossible to read your code without them!
Oct 10 '07 #4
hi Atli,

I thank a lot.........
Its now working perfectly.......

Again thank a lot...........
Oct 11 '07 #5
zensunni
101 100+
May I ask where you got that reader.php script? I would like very much to be able to read xls documents.

Thanks.
Nov 30 '07 #6
Atli
5,058 Expert 4TB
Hi.

I Googled the class name and I found this link.

I think this is what he is using, tho there may be a small bug in the reader.php code. Namely the require_once function at line 31 may need to be altered to fit the downloaded files.
Dec 1 '07 #7
@Atli

where to download the 'OLERead.php' file that required in line 31..?
Apr 12 '12 #8
johny10151981
1,059 1GB
I didnt read your code.

But from you initial question I am totally confused.

I want to know the last row of the csv file. How to calculate the the last row of the excel file using php coding.

What do you want last row of csv file or last row or excel file or both?

do you actually need last row of the file or count of rows?

in case of php you dont need any special software. But in case of excel I would suggest you to try PHPExcel. If you download PHPExcel you will also get OLERead.php file.
Apr 12 '12 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: deko | last post by:
Below are the contents file that has the IP address and time of visit of visitors to a website. 68.122.69.241|1089822686 68.122.69.241|1089823630 68.122.69.241|1089823638
22
by: Ling Lee | last post by:
Hi all. I'm trying to write a program that: 1) Ask me what file I want to count number of lines in, and then counts the lines and writes the answear out. 2) I made the first part like this: ...
6
by: Hari Om | last post by:
Here are the details of my error log files: I execute the command and get following message at console: ---------------------------------------------------------------------- ../sqlldr...
17
by: keith | last post by:
I am trying to get a exact count of different distinct entries in an Access column. At first, I was trying to work with three columns, but I've narrowed it down to one to simplify it. I've searched...
68
by: Martin Joergensen | last post by:
Hi, I have some files which has the following content: 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0
1
by: TechnoPup | last post by:
Greetings, I am very new to working with databases, and I am not sure how to go about structuring the query I need. What I have is an Access database with approx. 400,000 records in 5 fields. ...
1
by: danibecr | last post by:
I'm trying to make a table that will daily count the records imported and save them to a seperate table along with the date imported. But as of now after all the processing is complete I delete...
3
by: marianowic | last post by:
Hello. I'm trying to get a real number of used (where is any data) rows in a Excel file in a C# code. I found some examples abount Excel.Range but it still isn't good. Does anyone have any ide...
16
by: lovecreatesbea... | last post by:
It takes mu so time to finish this C source code line count function. What do you think about it? / ******************************************************************************* * Function ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.