2
votes

I have been working on a project on a Windows 7 system, using StrawberryPerl v 5.014 and Win32::OLE.

I am trying to use a second PC running Windows XP SP3, to have the same project developed in parallel. On the new system, I have installed Strawberry Perl v 5.016, and used cpanp to install Win32::OLE and Win32::OLE::Const.

I am using the same script sources in the new system.

It turns out that in the new system, somehow

use Win32::OLE::Const 'Microsoft Excel';

is not having an effect. I am getting the error:

Bareword "xlExcel8" not allowed while "strict subs" in use in StatementExcel.pm line 159.

This error does not show up in the first, original system I mentioned.

What to do?

TIA, Helen

Here's some excerpts from the program:

package  StatementExcel;
require  Exporter;
@ISA   = qw(Exporter);
@EXPORT  = qw(LoadExcel ProcessPreparedSheet);
use strict;
use warnings;
use Encode;
use 5.016;
use utf8;
use Win32::Console;
use autodie; 
use warnings    qw< FATAL  utf8     >;
use StateConversion;
use Carp;
use Win32::OLE  qw(CP_UTF8);
use Win32::OLE::Const 'Microsoft Excel';
use Cwd;
use Text::CSV::Unicode;
use File::BOM qw( :all );
use List::MoreUtils 'first_index';
...
$xlBook -> SaveAs( $xlFile, xlExcel8);

$i = Win32::OLE->LastError();
if ($i) {
   PrintT $parms{LogStructRef}{HANDLE}, "Error trying to save Excel file:\n", $i;
}   # end if ($i)
PrintT $parms{LogStructRef}{HANDLE}, 'Press <return> to continue...';   # Wait for user input...
$j = <STDIN>;
# Clean up
$xlBook->{Saved} = 1;
$xlApp->Quit;
$xlBook = 0;
$xlApp = 0;
...

Note: cross-posted on PerlMonks: http://www.perlmonks.org/?node_id=985596

1

1 Answers

1
votes

It turns out that the problem occurs because of differences in the OLE object library between Excel 2010 and Excel 2003. On the Win XP system, Excel 2003 is installed. On the Windows 7 system, Excel 2010 is installed. When saving the Excel file, I am instructing it to save it as an Excel 2003 "xls" format (and not in the "xlsx" format of Excel 2010) using the "xlExcel8" OLE constant.

It turns out that this constant does not exist in the OLE 2003 object library.

The solution was simple: save the file without specifying format - it used the default.

See also: http://www.perlmonks.org/?node_id=985780