Tập lệnh này dựa trên bài viết perlmonks từ angiehope theo nhận xét từ @FtLie ở trên. Tôi đã thử nghiệm điều này với Office 2010. Kịch bản lệnh sẽ tạo một tệp có tên ppt_test.ppt trong cùng một tệp với tập lệnh và sẽ đặt mật khẩu 'bí mật' trên tài liệu đã lưu.
use strict;
use warnings;
use v5.10;
use Try::Tiny;
use Data::Dumper;
use Carp;
use FindBin qw ($Bin);
use Win32::OLE qw(in CP_UTF8);
Win32::OLE->Option(CP => CP_UTF8);
$Win32::OLE::Warn = 3;
my $filename = "$Bin/ppt_test.ppt";
unlink $filename if (-e $filename);
print("Starting Powerpoint Object\n");
my $power = Win32::OLE->GetActiveObject('Powerpoint.Application') ||
Win32::OLE->new('Powerpoint.Application', 'Quit');
my $ppt = $power->Presentations->Add();
# 12 = blank layout
my $slide = $ppt->Slides->Add(1,12);
# 1 = text in horizontal direction, the next two numbers describe the position
# and the last numbers the width and height of the box
my $new_textbox = $slide->Shapes->AddTextbox(1,30,30,600,200);
my $text_frame = $new_textbox->TextFrame;
my $text_range = $text_frame->TextRange;
$text_range->{Text} = "Please print \x{03B1},\x{03B2},\x{03B3}";
# Now set the password
my $password = 'secret';
$ppt->{Password} = $password;
$ppt->SaveAs($filename);
$ppt->Close();
Nguồn
2013-10-12 01:29:48
Nói chung bạn không thể. Các tệp Ppt rất độc quyền và tôi không biết bất kỳ mô-đun nào truy cập các tệp này từ Perl. Nếu bạn đã cài đặt PowerPoint trên cùng một máy, bạn có thể tự động PowerPoint từ Perl bằng Win32 :: Ole (ví dụ: xem http://www.perlmonks.org/?node_id=922835 để biết một vài gợi ý để bắt đầu) – FtLie