in reply to Re: Win32::OLE for Excel fails to open newly generated XLS file
in thread Win32::OLE for Excel fails to open newly generated XLS file

You have switched off DisplayAlerts - this means that Excel will not tell you what it thinks is wrong.
True. I did it because otherwise I get extra dialogs on SaveAs as eg. text. I tried adding it back in with:
$Win32::OLE::Warn = 2;
Also, you don't show us how you save the file, or what the filename is. "Bad extension for file" suggests that Excel expects something different than what you give it.
This is a bit of grey area. I use Excel 2013 that expects XLSX extension but file that I get come with older XLS extension.
In any case - I changed my Workbook code to:
# get a new workbook my $wbook; $wbook = $excel->Workbooks->Open({ FileName => $fullname_input_fil +e }); $wbook->Save(); unless(defined $wbook) { if($wbook = Win32::OLE->GetObject($fullname_input_file)){;} else { $wbook = $excel->{Workbooks}->{"$fullname_input_file"}; if($wbook->Activate()){;} else { print STDERR "Could not open the file $fullname_input_ +file: $!\n"; exit; } } }
and it seemed to work but it still feels like doing voodoo.
Also see maybe Text::CSV_XS to read the file, or Spreadsheet::Read.
Thank you for these suggestions - I went OLE way because I need to modify a lot of Excel files in place and I have not found a module that would cover it. For this particular issue - Excel files come as database-generated reports and extracting data from them is the only task so OLE is not strictly speaking necessary.

Replies are listed 'Best First'.
Re^3: Win32::OLE for Excel fails to open newly generated XLS file
by Corion (Patriarch) on Jan 26, 2016 at 09:39 UTC

    Maybe I misunderstand you - if you have .xls files, you cannot rename them to .xlsx and expect them to work.

    If you want to read .xls files from Perl, see Spreadsheet::ParseExcel.