469,352 Members | 1,836 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

perlscript for comparing values of two excel sheets cell by cell

12
I have to compare values of two excel sheets cell by cell.
can anybody suggest me how to do it?
In advance Thanks.
Mar 26 '12 #1

✓ answered by numberwhun

Ok, so inside of the loop for workbook1 start another loop for workbook. You take a value from workbook1 and compare it to the workbook values. If no match, grab another and then re-enter the workbook loop. Its a vicious cycle, but its a way to do it. Code it, paste the code in here (in code tags) if you get stuck and we will try to help.

Regards,

Jeff

5 8180
numberwhun
3,503 Expert Mod 2GB
Have you googled how to do this comparison? This may be a good start.

Regards,

Jeff
Mar 26 '12 #2
Anuja T
12
yes,i have done that. I am posting the code-
Here is my updated code-
Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3. use Spreadsheet::ParseExcel;
  4. use Spreadsheet::WriteExcel;
  5.     my $parser   = Spreadsheet::ParseExcel->new();
  6.     my $workbook = $parser->parse('C:\\Documents and Settings\\atol\\perl_test\\file.xls');
  7.  
  8.     print $workbook ,"\n";
  9.     my $parser1   = Spreadsheet::ParseExcel->new();
  10.     my $workbook1 = $parser->parse('C:\\Documents and Settings\\atol\\perl_test\\file1.xls');
  11.  
  12.     print $workbook1 ,"\n";
  13.  
  14.     if ( !defined $workbook ) {
  15.         die $parser->error(), ".\n";
  16.     }
  17.  
  18.  
  19.  
  20.          for my $worksheet ( $workbook1->worksheets())
  21.          {
  22.         my ( $row_min, $row_max ) = $worksheet->row_range();
  23.         my ( $col_min, $col_max ) = $worksheet->col_range();
  24.  
  25.  
  26.         for my $row ( $row_min .. $row_max ) {
  27.             for my $col ( $col_min .. $col_max ) {
  28.  
  29.                 my $cell = $worksheet->get_cell( $row, $col );
  30.  
  31.                 my $cell1 = $worksheet->get_cell( $row, $col );
  32.                 next unless $cell and $cell1;
  33.  
  34.         my $data = $cell->value();
  35.         #print $data;
  36.         my $search = $cell1->value();
  37. print $search;
  38.  
  39.  
  40.  
  41.     }
  42.     }
  43. }
  44.  
its only showing values of workbook1 which is file1.xls but not getting values of workbook which is "file.xls".
i am trying to utilize multiple conditions in for loop so that loop would also work for workbook also. but unable to do it.
please help me out.
Mar 26 '12 #3
numberwhun
3,503 Expert Mod 2GB
First, you need to please use Code tags around your code in the forum. They are covered in the site FAQ if you are unsure how to use them.

You are only showing results from workbook1 because that is all you have written code to work on. If you look at this:

Expand|Select|Wrap|Line Numbers
  1. for my $worksheet ( $workbook1->worksheets())
  2.  
From that point on it is only acting on workbook1. Where is the code to act on and compare to workbook?

Regards,

Jeff
Mar 27 '12 #4
Anuja T
12
I have mentioned that i have tried to utilize multiple conditions in forloop that means using "&&" operator i tried to make that loop work for "workbook" also but unable to do it.
Mar 27 '12 #5
numberwhun
3,503 Expert Mod 2GB
Ok, so inside of the loop for workbook1 start another loop for workbook. You take a value from workbook1 and compare it to the workbook values. If no match, grab another and then re-enter the workbook loop. Its a vicious cycle, but its a way to do it. Code it, paste the code in here (in code tags) if you get stuck and we will try to help.

Regards,

Jeff
Mar 28 '12 #6

Post your reply

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

Similar topics

2 posts views Thread by Osiris Sawiris | last post: by
reply views Thread by Dwight Trumbower | last post: by
1 post views Thread by sk | last post: by
1 post views Thread by Rohan | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.