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 created."); 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;