woland99 has asked for the wisdom of the Perl Monks concerning the following question:
But if file was not opened manually I get:unless (defined $excel) { eval { $excel = Win32::OLE->GetActiveObject('Excel.Application') }; die "Excel not installed" if $@; } unless (defined $excel) { $excel = Win32::OLE->new('Excel.Application', 'Quit') or die "Oops, cannot start Excel"; } #to avoid excessive dialogs when saving in non-Excel format $excel->{DisplayAlerts} = 0; #$excel->Workbooks->Open({ FileName => $fullname_input_file }) #|| print STDERR "didnt open the file $!\n"; # get a new workbook my $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; } }
So basic problem is that I cannot seem to get hold of $wbook object. If I just open the file and do Ctrl-S to save it and then run the script then everything runs as expected.Win32::OLE(0.1709) error 0x800401e6: "Bad extension for file" at oleli +b.pl line 1286. eval {...} called at olelib.pl line 1286 main::save_excel_file_as_tab_delimited_MS_API_WSC('test2.xls', + '__read_in_excel_file_into_array.txt', 'ANNOUNCEMENT') called at ole +lib.pl line 411 main::save_excel_file_as_tab_delimited('test2.xls', '__read_in +_excel_file_into_array.txt', 'ANNOUNCEMENT') called at olelib.pl line + 1970 main::read_in_excel_file_into_array_WSC('test2.xls', 'ARRAY(0x +2b4a334)', 'ANNOUNCEMENT') called at olelib.pl line 1798 main::read_in_excel_file_into_array('test2.xls', 'ARRAY(0x2b4a +334)', 'ANNOUNCEMENT') called at test_unzip_in_place.pl line 107 Win32::OLE(0.1709) error 0x80020009: "Exception occurred" in METHOD/PROPERTYGET "c:\ecdev\src\src_dev\model\sq\scripts\test\test_unzip\test2.xls" at o +lelib.pl line 1297. Can't call method "Activate" on an undefined value at olelib.pl line 1 +298.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Win32::OLE for Excel fails to open newly generated XLS file
by Corion (Patriarch) on Jan 26, 2016 at 08:40 UTC | |
by woland99 (Beadle) on Jan 26, 2016 at 09:35 UTC | |
by Corion (Patriarch) on Jan 26, 2016 at 09:39 UTC |