Code: [show] | [select all]
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;