本來我試圖用Excel打開一個XML文件。但是,由於這需要很長時間,我自己將XML解析爲一個製表符分隔的文本文件。我以爲我在互聯網上找到了正確的語法。我使用Excel宏記錄的值嘗試了下面的代碼。我有一個18列製表符分隔文件。調用「工作表」方法時,下面代碼的最後一行出現錯誤。如何使用Perl和OLE在Excel中打開製表符分隔的文本文件?
錯誤消息: 無法調用「工作單」,而不在./PostProcessingDev.pl行包或對象引用70
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Excel';
Win32::OLE->Option(Warn => 3);
use strict;
my $Excel;
my $Sheet;
my $Workbook;
$Excel = CreateObject OLE "Excel.Application";
$Workbook = $Excel->Workbooks->OpenText({Filename =>"$inSelf->{'TXT'}",
Origin => xlMSDOS,
StartRow => 1,
DataType => xlDelimited,
TextQualifier => xlDoubleQuote,
ConsecutiveDelimiter => "False",
Tab => "True",
Semicolon => "False",
Comma => "False",
Space => "False",
Other => "False",
FieldInfo => [[1, xlTextFormat],
[2, xlTextFormat],
[3, xlTextFormat],
[4, xlTextFormat],
[5, xlTextFormat],
[6, xlTextFormat],
[7, xlTextFormat],
[8, xlTextFormat],
[9, xlTextFormat],
[10, xlTextFormat],
[11, xlTextFormat],
[12, xlTextFormat],
[13, xlTextFormat],
[14, xlTextFormat],
[15, xlTextFormat],
[16, xlTextFormat],
[17, xlTextFormat],
[18, xlTextFormat]],
TrailingMinusNumbers => "True"});
$Sheet = $Workbook->Worksheets(1);
您不應該使用split/regexes分析xSV文件。與CSV相同,使用適當的模塊(文本:CSV_CS) – DVK 2011-02-15 13:34:34