2012-08-06 74 views
1

我一直在使用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

回答

0

事實證明,發生的,因爲在不同的問題Excel 2010和Excel 2003之間的OLE對象庫。 在Win XP系統上,安裝了Excel 2003。在Windows 7系統上,安裝了Excel 2010。保存Excel文件時,我正在指示它使用「xlExcel8」OLE常量將其保存爲Excel 2003「xls」格式(而不是Excel 2010的「xlsx」格式)。

事實證明,這個常量在OLE 2003對象庫中不存在。

解決方案很簡單:保存文件時不指定格式 - 它使用默認值。

另請參閱:http://www.perlmonks.org/?node_id=985780

相關問題