我一直在使用StrawberryPerl v 5.014和Win32 :: OLE在Windows 7系統上工作。Perl + Excel:「使用Win32 :: OLE :: Const」沒有效果
我想使用第二臺運行Windows XP SP3的PC,並行開發相同的項目。在新系統上,我安裝了Strawberry Perl v 5.016,並使用cpanp安裝Win32 :: OLE和Win32 :: OLE :: Const。
我在新系統中使用相同的腳本源。
事實證明,在新系統中,不知何故
use Win32::OLE::Const 'Microsoft Excel';
是不是有效果。我得到錯誤:
Bareword "xlExcel8" not allowed while "strict subs" in use in StatementExcel.pm line 159.
此錯誤不顯示在我提到的第一個原始系統中。
怎麼辦?
TIA,海倫
下面是該程序的一些摘錄:
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;
...
注:PerlMonks交叉貼:http://www.perlmonks.org/?node_id=985596