473,472 Members | 1,747 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

count last row in a excel file

ganesanji
16 New Member
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 19243
Atli
5,058 Recognized Expert Expert
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
ganesanji
16 New Member
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 Recognized Expert Expert
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
ganesanji
16 New Member
hi Atli,

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

Again thank a lot...........
Oct 11 '07 #5
zensunni
101 New Member
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 Recognized Expert Expert
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
vannthns
2 New Member
@Atli

where to download the 'OLERead.php' file that required in line 31..?
Apr 12 '12 #8
johny10151981
1,059 Top Contributor
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.