[Win32::OLE]在Word文档中画线、插入线段

There's more than one way to do it!
https://metacpan.org http://perlmonks.org
回复
头像
PerlMonk
渐入佳境
渐入佳境
帖子: 49
注册时间: 2016年09月19日 10:20
联系:

[Win32::OLE]在Word文档中画线、插入线段

帖子 PerlMonk »

该脚本需要在使用前先建立 Untitle.docx,以及脚本应保存为 UTF8 编码格式
use warnings;
use Encode;
use utf8;
use strict;
use Cwd;
my $fold = getcwd();
$fold=~s/\//\\/;

use Win32::OLE;
use Win32::OLE::Const ('Microsoft Word');
use Win32::OLE::Variant;

our $shape;


my $word = CreateObject Win32::OLE 'Word.Application' or die $!;
$word->{'Visible'} = 0;

my $document = $word->Documents->Open($fold ."\\untitle.docx");

my $selection = $word->Selection;

$selection -> TypeText(encode('gbk',"大家好"));
$selection -> TypeParagraph;
$selection -> TypeText("How do you feel today");
$selection -> TypeParagraph;

&line(1,1,100,100,1);

#$document->Save();
$word->quit();


sub line {
my ($x1, $y1, $x2, $y2, $color) = @_;
my $msoArrowheadTriangle = 2;
$shape=$document->Shapes->Addline(
$x1, $y1, $x2, $y2
);
$shape->Line->ForeColor->{'SchemeColor'}=$color;
$shape->Line->{'EndArrowheadStyle'}=$msoArrowheadTriangle;

my $test;
$test = $shape=$document->Shapes->AddConnector(
2, 194.4, 141.6, 183, 80.4);
$test = $shape=$document->Shapes->BuildFreeform(
0, 180.9, 226.55);
$test->AddNodes(1, 0, 227.4, 269.55);
$test->AddNodes(1, 0, 114.15, 359.1);
$test->ConvertToShape->{'Select'};
}
回复

在线用户

正浏览此版面之用户: 没有注册用户 和 0 访客