in reply to Determining if excel workbook is open
# Eval block traps errors in Excel file creation; local # redirection of $SIG{__WARN__} allows error message # to be checked to see if the file cannot be created because # it is open. The redirect is only valid within the enclosing # block. { local $SIG{__WARN__} = sub { $errmsg = $_[0] }; eval {$workbook = Spreadsheet::WriteExcel->new($Excelfilename);}; if ($errmsg) { if ($errmsg =~ /may be in use/) { print "$Excelfilename is open.\n"; } else { print "Excel file could not be created: $!\n"; } } }
|
|---|