[Perl][Win32::OLE]在Excel中插入线段、箭头

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

[Perl][Win32::OLE]在Excel中插入线段、箭头

帖子 PerlMonk »

use Win32::OLE qw (in with);
use Win32::OLE::Const ('Microsoft Excel');
use Win32::OLE::Variant;
use Cwd;

my $fold = getcwd();
$fold=~s/\//\\/g;

# 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);

$msoArrowheadTriangle = 2;
my $ang;
my ($cx, $cy, $R) = (200.0, 200.0, 200.0);
for my $part (0..30) {
$ang = ($part / 30.0) * 6.28;
$shape = $sheet->Shapes->Addline($cx, $cy, $cx+cos($ang)*$R, $cy+sin($ang)*$R);
$shape->Line->ForeColor->{'SchemeColor'} = $part;
$shape->Line->{'EndArrowheadStyle'} = $msoArrowheadTriangle;
}

# save and exit
$ex->{DisplayAlerts} = 'False';
$book->SaveAs( $fold ."\\Line.xlsx");
undef $book;
undef $ex;
excelline.png
回复

在线用户

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