
如何使用perl脚本处理excel的边框粗细
1个回答
展开全部
用Excel的宏录制功能copy代码就可以了
use Win32::OLE qw(in with);
use Win32::OLE::Variant;
use Win32::OLE::Const 'Microsoft Excel';
use strict;
my $excel;
my $excel_book;
$| = 1;
create_excel();
edge(get_range([1,1]), 'out', xlThick);
edge(get_range([2,2]), 'out', xlThin);
edge(get_range([3,3]), 'out', xlMedium);
sub col_name {
my $col = shift;
my $n = "";
do {
$col--;
$n = chr($col % 26 + ord('A')) . $n;
$col = int($col/26);
} while($col > 0);
return $n;
}
sub get_row_col {
my ($row, $col) = @_;
return col_name($col) . $row;
}
sub get_range {
my $range = shift;
my $r;
if ($#$range == 1) {
$r = get_row_col($range->[0], $range->[1]);
}
if ($#$range == 3) {
$r = get_row_col($range->[0], $range->[1]) . ":" .
get_row_col($range->[2], $range->[3]);
}
return $excel->Range($r);
}
sub edge {
my $range = shift;
my $type = shift;
my $weight = shift || xlThin;
if ($type eq 'out' || $type eq 'all') {
with ($range->Borders(xlEdgeLeft),
'LineStyle' => 1,
'ColorIndex' => 0 ,
'Weight' => $weight
);
with ($range->Borders(xlEdgeRight),
'LineStyle' => 1,
'ColorIndex' => 0 ,
'Weight' => $weight
);
with ($range->Borders(xlEdgeTop),
'LineStyle' => 1,
'ColorIndex' => 0 ,
'Weight' => $weight
);
with ($range->Borders(xlEdgeBottom),
'LineStyle' => 1,
'ColorIndex' => 0 ,
'Weight' => $weight
);
}
if ($type eq 'all') {
with ($range->Borders(xlInsideHorizontal),
'LineStyle' => 1,
'ColorIndex' => 0 ,
'Weight' => $weight
);
with ($range->Borders(xlInsideVertical),
'LineStyle' => 1,
'ColorIndex' => 0 ,
'Weight' => $weight
);
}
}
sub create_excel {
$excel = Win32::OLE->new('Excel.Application') or die "oops\n";
$excel->{Visible} = 1;
$excel_book = $excel->Workbooks->Add;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |