Excel がインストールされている場合、これを行うのはほとんど簡単Win32::OLE
です。Win32::OLE
自身のドキュメントの例を次に示します。
use Win32::OLE;
# use existing instance if Excel is already running
eval {$ex = Win32::OLE->GetActiveObject('Excel.Application')};
die "Excel not installed" if $@;
unless (defined $ex) {
$ex = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;})
or die "Oops, cannot start Excel";
}
# get a new workbook
$book = $ex->Workbooks->Add;
# write to a particular cell
$sheet = $book->Worksheets(1);
$sheet->Cells(1,1)->{Value} = "foo";
# write a 2 rows by 3 columns range
$sheet->Range("A8:C9")->{Value} = [[ undef, 'Xyzzy', 'Plugh' ],
[ 42, 'Perl', 3.1415 ]];
# print "XyzzyPerl"
$array = $sheet->Range("A8:C9")->{Value};
for (@$array) {
for (@$_) {
print defined($_) ? "$_|" : "<undef>|";
}
print "\n";
}
# save and exit
$book->SaveAs( 'test.xls' );
undef $book;
undef $ex;
基本的にWin32::OLE
、VBA または Visual Basic アプリケーションで使用できるすべてのものを提供します。これには、Excel および Word の自動化から、Windows スクリプト ホストを介したネットワーク ドライブの列挙およびマウントまで、さまざまなものが含まれます。これは、ActivePerl の最近のいくつかのエディションに標準装備されています。