亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 2298 | 回復(fù): 0
打印 上一主題 下一主題

perl操作ppt自動化報告 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2017-04-04 00:23 |只看該作者 |倒序瀏覽
win32ppt.zip (292.18 KB, 下載次數(shù): 4)

直接上代碼:
  1. package Win32::PPT;
  2. use Moose;
  3. use Win32::OLE;
  4. use MooseX::NonMoose::InsideOut;
  5. use Data::Printer;

  6. extends 'Win32::PowerPoint';

  7. my $intro=<<'EOF';

  8. ########################################################
  9. #                   Win32::PPT模塊
  10. #      Author: TianYv
  11. #      Blog: http://tianyv.github.io
  12. #      Blog: http://blog.chinaunix.net/uid/22674875.html
  13. ########################################################
  14. EOF
  15. p $intro;

  16. has config => (
  17.     is      => 'rw',
  18.     default => sub { {} }
  19. );

  20. has app => ( is => 'rw' );

  21. #通過PPT vba增加打開方法
  22. sub open_ppt {
  23.     my ( $self, $file ) = @_;
  24.     return unless defined $file;

  25.     $self->{app} = Win32::OLE->GetActiveObject('PowerPoint.Application');
  26.     $self->{app}->{Visible} = 1;
  27.     my $objppt = $self->{app}->Presentations->Open($file);
  28.     return $self;
  29. }

  30. #重寫創(chuàng)建PPT方法
  31. sub new_ppt {
  32.     my $self = shift;
  33.     $self->new_presentation(
  34.         background_forecolor => [ 255, 255, 255 ],
  35.         background_backcolor => 'RGB(255,255,255)',
  36.     );
  37. }

  38. #新建幻燈片,并輸入Title和Body文字
  39. sub slide2TB {
  40.     my ( $self, $texTitle, $texBody, $hT, $hB ) = @_;
  41.     $hT = ref($hT) eq 'HASH' ? $hT : $self->{config}->{title};
  42.     $hB = ref($hB) eq 'HASH' ? $hB : $self->{config}->{body};
  43.     $self->new_slide();
  44.     $self->add_text( $texTitle, $hT );
  45.     $self->add_text( $texBody,  $hB );
  46. }

  47. #新建幻燈片,并輸入Title和Picture文字
  48. sub slide2TP {
  49.     my ( $self, $texTitle, $img, $hT, $hP ) = @_;
  50.     $hT = ref($hT) eq 'HASH' ? $hT : $self->{config}->{title};
  51.     $hP = ref($hP) eq 'HASH' ? $hP : $self->{config}->{picture};
  52.     $self->new_slide();
  53.     $self->add_text( $texTitle, $hT );
  54.     $self->add_picture( $img, $hP );

  55. }

  56. #$hash={texT=>,texB=>,img=>,type=>}
  57. sub slide2TBBPP {
  58.     my ( $self, $hash, $hT, $hB, $hP ) = @_;
  59.     $hT = ref($hT) eq 'HASH' ? $hT : $self->{config}->{def_tbp}->{title};
  60.     $hB = ref($hB) eq 'HASH' ? $hB : $self->{config}->{def_tbp}->{body};
  61.     $hP = ref($hP) eq 'HASH' ? $hP : $self->{config}->{def_tbp}->{picture};
  62.     my ( $texTitle, $texBody, $img );
  63.     if ( ref($hash) eq 'HASH' ) {
  64.         $texTitle = defined( $hash->{texT} ) ? $hash->{texT} : '標題定義錯誤!';
  65.         $texBody  = defined( $hash->{texB} ) ? $hash->{texB} : '正文定義錯誤!';
  66.         $img      = defined( $hash->{img} )  ? $hash->{img}  : '';
  67.     }
  68.     $self->new_slide();
  69.     $self->add_text( $texTitle, $hT );

  70.     my $type = $hash->{type};
  71.     if ( $type == 1 ) {
  72.         $self->add_text( $texBody, $hB );
  73.         $self->add_picture( $img, $hP );
  74.     }
  75.     else {
  76.         $self->add_picture( $img, $hP );
  77.         $self->add_text( $texBody, $hB );
  78.     }
  79. }

  80. #重寫創(chuàng)建PPT保存并關(guān)閉方法,保存在當(dāng)前文件夾
  81. sub save_ppt {
  82.     my ( $self, $name ) = @_;
  83.     $self->save_presentation($name);
  84.     $self->close_presentation();
  85.     $self->quit();
  86. }

  87. package main;
  88. use Cwd;
  89. use File::Spec;
  90. use YAML::Syck;
  91. use Data::Printer;

  92. my $ppt  = Win32::PPT->new();
  93. my $dir  = Cwd::getcwd();
  94. my $file = $dir . '/模板.ppt';

  95. #讀取配置文件config.yaml信息:設(shè)置(title body picture)位置;
  96. #設(shè)置字體名稱[name]、字體大小[size]、字體是否加粗[bold]、圖片寬高[width | hight]
  97. #如$ppt->{config}->{body}->{size} 為正文字體大小
  98. my $confile = File::Spec->rel2abs('config.yaml');
  99. $ppt->{config} = LoadFile($confile);

  100. #p $ppt->{config};
  101. #$ppt->new_ppt();

  102. #打開模版PPT
  103. $ppt->open_ppt($file);

  104. #1.1使用config.yaml內(nèi)設(shè)的默認屬性
  105. $ppt->slide2TB( '一、測試標題', '測試正文' );

  106. #1.2可以改變局部屬性,如$ht ,也可像$hb一樣更改所有屬性
  107. my $ht = {
  108.     top  => 40,
  109.     size => 24,
  110.     name => '楷體'
  111. };
  112. my $hb = {
  113.     left   => 35,
  114.     top    => 85,
  115.     width  => 625,
  116.     height => 400,
  117.     size   => 24,
  118.     bold   => 1,
  119.     name   => '宋體'
  120. };
  121. $ppt->slide2TB( '一、測試標題', '測試正文', $ht, $hb );

  122. #2.1使用config.yaml內(nèi)設(shè)的默認屬性;插入圖片
  123. $ppt->slide2TP( '二、測試標題圖片', 'img/jx.png' );

  124. #2.2更改圖片局部屬性
  125. my $hp = {
  126.     width  => 200,
  127.     height => 130,
  128. };
  129. $ppt->slide2TP( '二、測試標題圖片', 'img/jx.png', $ht, $hp );

  130. #3.1左右2列的幻燈片,type=1,左正文+右圖片
  131. my $h1 = {
  132.     texT => '三、左正文+右圖片',
  133.     texB => '1234567890正文',
  134.     img  => 'img/3D.png',
  135.     type => 1
  136. };
  137. $ppt->slide2TBBPP($h1);

  138. #3.2上下2列的幻燈片,type=0,上圖片+下正文
  139. my $h2 = {
  140.     texT => '三、上圖片+下正文',
  141.     texB => '1234567890正文',
  142.     img  => 'img/3D.png',
  143.     type => 0
  144. };
  145. my $hb2 = {
  146.     top    => 450,
  147.     height => 200,
  148. };
  149. my $hp2 = {
  150.     top    => 85,
  151.     width  => 400,
  152.     height => 360,
  153. };
  154. $ppt->slide2TBBPP( $h2, $ht, $hb2, $hp2 );
  155. $ppt->save_ppt("結(jié)果.ppt");
復(fù)制代碼


您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP