suvendu4urs has asked for the wisdom of the Perl Monks concerning the following question:

Hello Guys, I have wrote one WIN32:OLE perl script to compare two .xls file and update one .xls In short: file.xls column 1conatins:
\SUM\SUM_cam.c \SUM\SUM_cam.h \SUM\SUM_command.c \SUM\SUM_command.h \SUM\SUM_dab.c \SUM\SUM_dmb.c \SUM\SUM_eventHandler.h \SUM\SUM_eventHandler_dab.c \SUM\SUM_eventHandler_dmb.c \SUM\SUM_fap.c \SUM\SUM_fap.h \SUM\SUM_private.h \SUM\SUM_task_dab.c \SUM\SUM_task_dmb.c \SUM\Makefile \SUM\SUM_cam.c
V3.xls column 1contains :
\SUM\SUM_cam.c@@\main\base2ucm_source\600_int\1 \NEW\NEW_calc.c@@\main\base2ucm_source\600_int\1 \NEW\NEW_FAP.c@@\main\base2ucm_source\600_dev_dmb\1 \SIN\COM\SIN_COMconnection.c@@\main\base2ucm_source\600_int\1 \SIN\COM\COMconnection.sm@@\main\base2ucm_source\600_int\1 \SIN\IN\SIN_INdevice.c@@\main\base2ucm_source\600_int\1 \SUM\SUM_cam.c@@\main\base2ucm_source\600_int\1

Now i am comparing each element of file.xls with V3.xls If the element of each row of file.xls is present in V3.xls then i am updating the corresponding row of second column in file.xls with (*) mark

#!/usr/bin/perl -w use strict; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel'; #$Win32::OLE::Warn = 3; # die on errors +... # get already active Excel application or open new my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit'); # open Excel file my $Book = $Excel->Workbooks->Open("u:/file.xls"); my $Book1 = $Excel->Workbooks->Open("u:/v3.xls"); # select worksheet number 1 (you can also select a worksheet by name) my $Sheet = $Book->Worksheets(1); my $Sheet1 = $Book1->Worksheets(1); my $val1; my $cnt=0; my $line; foreach my $row (1..3000) { foreach my $col (1) { my $val; next unless defined $Sheet->Cells($row,1)->{'Value'}; $val = $Sheet->Cells($row,1)->{'Value'}; #findl($val); for($cnt=1;$cnt<=65536;$cnt++){ $val1 = $Sheet1->Cells($cnt,1)->{'Value'}; if ((defined $val1) && (index($val1,$val) != -1)){ $line =$cnt if (!defined $line); $Sheet->Cells($row,2)->{'Value'}= *; last; } } } } $Book->SaveAs ("u:/file.xls") ; # clean up after ourselves $Book->Close; $Book1->Close;
But after executing the .exe generated from the script there is no ouput. Anyone please guide me where is the problem

Replies are listed 'Best First'.
Re: WIN32OLE program to compare
by marto (Cardinal) on Aug 19, 2010 at 15:37 UTC

    "But after executing the .exe generated from the script there is no ouput. Anyone please guide me where is the problem"

    So it runs as you'd expect as a perl script prior to packaging? Are you running the exe on the same computer as the script? Can you show us how you generate the exe?

      Yes i am executing the exe on the same computer where i have the script....... But the exe is not generated by me as i donot have WIN32OLE package installed in my PC. Hope my friend is doing ccperl file.pl then if it is ok... converting this to perlfile to exe .....

        ccperl? Clear Case Perl by IBM or do you mean perlcc? Either way perlcc states:

        The code generated in this way is not guaranteed to work. The whole codegen suite (perlcc included) should be considered very experimental. Use for production purposes is strongly discouraged.

        Install Win32::Ole and pp on the machine which script does run, and package your script yourself.

        Update: For clarification, I'm suggesting you package this script on your own computer using pp.

Re: WIN32OLE program to compare
by dasgar (Priest) on Aug 19, 2010 at 18:51 UTC

    My initial thoughts kind of echo marto's. I'd suggest trying to test the script in Perl first before trying to create a stand alone executable. If the Perl script works and the executable does not, that probably means that some required modules were not packaged in the executable.

    Ignoring that issue for the moment, I do so a potential problem in your code. When you open the workbooks (i.e. Excel files), I'd strongly suggest that you do error trapping. If there's errors in the syntax or if Excel can't find the file, the rest of your code becomes useless. Speaking from experience, you need to give Excel the full path to the file (in proper syntax) or Excel won't be able to find the file.