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

Hello,

I am having a bit of a problem.... I wrote a perl script that generates a report in excel. I am using cygwin perl. I made two batch files one calls perl directly and the other calls a makefile that calls perl.

Admin: make and batch work perfectly Power User: make and batch work perfectly User: batch work fine, but when i use the makefile i get this error: "Can't call method "SaveAs" on an undefined value at Y:/In/FileReport.pl line 183."

and make: *** fun error 9

Because of security reasons I am "forced" to get it to work on basic user rights.

I have also done some sort of fault tree analisis and it would come to some possibilities :

1. Restricted acces to excel services (over-ruled because batch still works)

2. Make environment somehow incompatible with basic user rights security policies (50% over-ruled because other makefiles still work under basic user rights)

3. Perl version not adequate for this such situation (20% over-ruled because it does work along with upscaling the user rights)

Can someone give me a hand with this, I am not an expert in these environments

  • Comment on cygwin, make, perl, win32::ole (excel) problem

Replies are listed 'Best First'.
Re: cygwin, make, perl, win32::ole (excel) problem
by Bloodnok (Vicar) on Dec 02, 2008 at 12:39 UTC
    A little context e.g. pertinent file contents, would help significantly...that being said, it does sound like, within your perl script, your attempt to create a Win32::OLE object has failed, but you haven't died on the error - I strongly suspect that had you done so, it might point you in the right direction.

    A user level that continues to overstate my experience :-))
      Hello, I have included the sub function that handles the excel file. The nasty thing is that I am facing this error only when running with limmited access rights (basic user rights). So I believe that the perl script is not the blame, because when I call it from batch it works fine.
      sub generate_reports { LogStart(); $Excel = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;}); ###### handling of files my @file_parts = split (/\//,$warning_files[0]); my $file = $file_parts[-1]; chomp($file); $file =~ s/\r//g; $file =~ s/\.txt//g; my $xls_filename = "$xls_files[0]"; open XLSFILE, $xls_filename or my $flag_die = 1; close XLSFILE; if ($flag_die eq 1) { printf ("\nDEBUG: Excel is: $Excel"); printf ("\nDEBUG: template_path is: $template_path"); #$template_path =~ s/\r//g; #$template_path =~ s/^\s*//g; #$template_path =~ s/\s*$//g; #$template_path =~ s/\//\\/g; #printf ("\nDEBUG: template_path (modified) is: $template_path\n"); $Excelbook = $Excel->Workbooks->Open("$template_path.\\filereport.xls" +); printf ("\nDEBUG: xls_filename is: $xls_filename\n"); #$xls_filename =~ s/\r//g; #$xls_filename =~ s/^\s*//g; #$xls_filename =~ s/\s*$//g; #$xls_filename =~ s/\//\\/g; #printf ("\nDEBUG: xls_filename (modified) is: $xls_filename\n\n"); printf ("\nDEBUG: Excelbook is: $Excelbook\n"); $Excelbook->SaveAs($xls_filename); } else { # file exists -> open it for update if (!(-w $xls_filename)) { printf ("\n$xls_filename is write-protected and can't be cr +eated."); die; } $xls_filename =~ s/\r//g; # remove control characters $xls_filename =~ s/^\s*//g; # Kill leading blanks $xls_filename =~ s/\s*$//g; # Kill trailing blanks $xls_filename =~ s/\//\\/g; # replace "/" by "\" $Excelbook = $Excel->Workbooks->Open($xls_filename); } my $firstSheet = $Excelbook->Worksheets(2); # activate warning sheet $firstSheet->Activate(); $Report_Sheet = $firstSheet;
        Hi ,

        My point was that the error tells you that the call $Excelbook->SaveAs is being made against an undefined value, hence $Excelbook is undefined after $Excelbook = $Excel->Workbooks->Open("$template_path.\\filereport.xls"); has executed, so if you changed it to read

        $Excelbook = $Excel->Workbooks->Open("$template_path.\\filereport.xls" +) || die "Cannot open - $template_path.\\filereport.xls" . Win32::OLE-> +LastError;
        instead, then, in all probability, you'd get a bit, tho' probably not much, more help from Windoze itself as to why the open failed.

        A user level that continues to overstate my experience :-))