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

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;

Replies are listed 'Best First'.
Re^3: cygwin, make, perl, win32::ole (excel) problem
by Bloodnok (Vicar) on Dec 03, 2008 at 12:23 UTC
    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.

        Always give absolute filenames to Excel. The "current directory" for an OLE object can very well differ from what your application thinks its current directory is. So if you change filereport.xls to become Y:\In\filereport.xls in your call to $excel->Workbooks->Add() it should work, or fail in a different way.

        You are sure that the containing directory In exists in Y:\\ and has the same permissions as the mount point ??

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