.iqy ファイルを使用して「データ ソース」に接続された Excel ファイル (.xlsx) があります。Perl を使用して Excel ファイルを開き、データを更新しました。最初は、私のコードは機能しました。ただし、スプレッドシートがリンクされている .iqy ファイルを変更する必要がありました。これを行うと、Perl スクリプトが壊れたようです (実際にはスクリプト自体の内部は何も変更されていません)。呼び出すと失敗するようになりました
my $LastRow = $Sheet->UsedRange->Find({What=>"*",
SearchDirection=>xlPrevious,
SearchOrder=>xlByRows})->{Row};
cmd の出力は次のとおりです。私はこれをデバッグしようとしましたが、Win32::OLE モジュールの内臓について、デバッガーで問題が発生した場所や理由をキャッチする方法を知るには十分ではありません。私のスクリプトのソースコードは次のとおりです。
#!/usr/bin/perl
use Win32::OLE;
use Win32::OLE qw(in with);
use Win32::OLE::Variant;
use Win32::OLE::Const 'Microsoft Excel';
$Excel = Win32::OLE->GetActiveObject('Excel.Application') ||
Win32::OLE->new('Excel.Application');
$Excel->{'Visible'} = 0; #0 is hidden, 1 is visible
$Excel->{DisplayAlerts}=0; #0 is hide alerts
# Open File and Worksheet
my $Book = $Excel->Workbooks->Open ('C:\shareP\sp.xlsx'); # open Excel file
$Sheet = $Book->Worksheets(1);
# Refresh Data (ActiveWorkbook.RefreshAll)
$Book->RefreshAll();
# Find Last Column and Row
my $LastRow = $Sheet->UsedRange->Find({What=>"*",
SearchDirection=>xlPrevious,
SearchOrder=>xlByRows})->{Row};
my $LastCol = $Sheet->UsedRange->Find({What=>"*",
SearchDirection=>xlPrevious,
SearchOrder=>xlByColumns})->{Column};
####### EDIT: I initially didn't post this portion because it stops
# before reaching it unless I make $LastCol and $LastRow constants
my @hasher;
my $c = "a";
for (my $cn=1; $cn <= $LastCol; $cn++){
for (my $r=2; $r <= $LastRow; $r++){
# stops here with same error if I make $LastCol and $LastRow constants
$hasher[$r-2]{ $Sheet->Range($c.'1')->{Value} } = $Sheet->Range($c.$r)->{Value};
}
$c++;
}
####### end of EDIT
# Save as Excel
$Book->Save();
$Book->Close();
$Excel->Quit();
あらゆるアドバイスを事前にありがとうございます。私は本当にこれにこだわっています。