perlscript for comparing values of two excel sheets cell by cell

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Anuja T
    New Member
    • Jan 2012
    • 12

    perlscript for comparing values of two excel sheets cell by cell

    I have to compare values of two excel sheets cell by cell.
    can anybody suggest me how to do it?
    In advance Thanks.
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    Have you googled how to do this comparison? This may be a good start.

    Regards,

    Jeff

    Comment

    • Anuja T
      New Member
      • Jan 2012
      • 12

      #3
      yes,i have done that. I am posting the code-
      Here is my updated code-
      Code:
      use strict;
      use warnings;
      use Spreadsheet::ParseExcel;
      use Spreadsheet::WriteExcel;
          my $parser   = Spreadsheet::ParseExcel->new();
          my $workbook = $parser->parse('C:\\Documents and Settings\\atol\\perl_test\\file.xls');
      	
      	print $workbook ,"\n";
      	my $parser1   = Spreadsheet::ParseExcel->new();
          my $workbook1 = $parser->parse('C:\\Documents and Settings\\atol\\perl_test\\file1.xls');
      	
      	print $workbook1 ,"\n";
      	
          if ( !defined $workbook ) {
              die $parser->error(), ".\n";
          }
      	
      
         
      		 for my $worksheet ( $workbook1->worksheets())
      		 {
              my ( $row_min, $row_max ) = $worksheet->row_range();
              my ( $col_min, $col_max ) = $worksheet->col_range();
      		
      		
              for my $row ( $row_min .. $row_max ) {
                  for my $col ( $col_min .. $col_max ) {
      
                      my $cell = $worksheet->get_cell( $row, $col );
                     
                      my $cell1 = $worksheet->get_cell( $row, $col );
                      next unless $cell and $cell1;
      
              my $data = $cell->value();
      		#print $data;
              my $search = $cell1->value();
      print $search;
                       
      		
      		
      	}
      	}
      }
      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.
      Last edited by numberwhun; Mar 27 '12, 06:56 AM. Reason: Please use code tags!

      Comment

      • numberwhun
        Recognized Expert Moderator Specialist
        • May 2007
        • 3467

        #4
        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:

        Code:
        for my $worksheet ( $workbook1->worksheets())
        From that point on it is only acting on workbook1. Where is the code to act on and compare to workbook?

        Regards,

        Jeff

        Comment

        • Anuja T
          New Member
          • Jan 2012
          • 12

          #5
          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.

          Comment

          • numberwhun
            Recognized Expert Moderator Specialist
            • May 2007
            • 3467

            #6
            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

            Comment

            Working...