in reply to cygwin, make, perl, win32::ole (excel) problem

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 :-))
  • Comment on Re: cygwin, make, perl, win32::ole (excel) problem

Replies are listed 'Best First'.
Re^2: cygwin, make, perl, win32::ole (excel) problem
by cugetare (Initiate) on Dec 03, 2008 at 09:42 UTC
    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 :-))
        Hello, I have followed your advice and here is the result:
        Cannot open - Y:\In\filereport.xlsOLE exception from "Microsoft Office + Excel": Excel cannot access 'filereport.xls'. The document may be read-only o +r encrypted. Win32::OLE(0.1703) error 0x800a03ec in METHOD/PROPERTYGET "Open" at Y:/In/FileReport.pl line 172
        The file is not read-only or write protected and it shouldn't be, this is the main reason I'm using Y: drive, which is mapped as a basic user and grants full control to it. I googled the 0x800a03ec error but didn't came up with something relevant, I will continue digging the internet for an answaer to this error. If you have any ideea abut this err please help ! Thanks.