Excelパスワードの設定
Excelがインストールされている必要があります。
use strict;
use warnings;
use Win32::OLE;
my $excel;
eval {
Win32::OLE->GetActiveObject('Excel.Application');
};
if ($@) {
die "Excelが入っていません。 $@";
}
unless (defined $excel) {
$excel = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;})
or die "Excelが起動できません。";
}
my $filename = 'C:\Documents and Settings\user1\My Documents\test.xls';
my $password = 'password';
$| = 1;
printf "%s ... ", $filename;
my $book = $excel->Workbooks->Open($filename)
or die Win32::OLE->LastError();
set_password($book, $password);
print "done.\n";
$book->Save();
$book->Close();
$excel->Quit();
exit;
sub set_password {
my $book = shift; # Excelワークブック
my $password = shift; # パスワード文字列
$book->{Password} = $password;
$book->{WritePassword} = $password;
}
