473,322 Members | 1,287 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,322 software developers and data experts.

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 8906
numberwhun
3,509 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,509 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,509 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

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

Similar topics

8
by: Ilan | last post by:
Hi all I need to add data from two Excel sheets (both on the same workbook) to an existing table in my SQL DB. The problem is that each sheet holds different fields for the same record, though...
2
by: Osiris Sawiris | last post by:
I inherited an Inventory control application that updates the stock from the branches at the end of each day. We receive the stock transactions via e-mail attachments (Excel Sheets). Those...
0
by: Dwight Trumbower | last post by:
Has anyone done any testing on what ways are quicker for reading and manipulating excel sheets? I'm currently maintaining some programs that move all the data into multidimensional array...
1
by: sk | last post by:
Please forgive me if the same topic is already posted. But i havent found I have got an error while accessing the excel file as below. Can somebody reply if there is a solution Access is denied....
0
by: bero81 | last post by:
Hi to everyboby, how can i read the names of excel sheets with vb6?i'm using from my references Microsoft excel 11.0 object library.. could someone help me,please?
1
by: msanger | last post by:
Hi, I have several excel sheets in Office 2007, which has all kinds of standard calculations, and a consolidated Excel Sheet with totals and rollup of all the other excel files. The issue I am...
1
by: Rohan | last post by:
Hello, I would like to write a script which does the following job. Take column1 and 7 from 10 different excel sheets and pasthe them into a new excel worksheet. Any ideas on how to do it Thanks,
2
by: sumuka | last post by:
Hello Everyone, I'm doing a project in VB 6.0 and i've a flexgrid which contains some numerical values in it's cell now i need to compare these values present in flexgrid with the values in...
1
by: Aswanth | last post by:
I'm Using Asp.Net with C# & SSRS 2005 for Generating Reports.. I'm Having HUGE Data in Microsoft Excel Sheets .. I want to Get this Data from this Microsoft Excel Sheets & to Generate REPORTS in...
1
by: Sekhar C | last post by:
I have 100 excel sheets with same field name,with same number of fields,with similar datatype. i want to transfer data from all excel sheets to one Sql database Table using one Package, i am using...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.