- 优点
无需安装模块依赖,功能强大 - 缺点
无法实现跨平台,必须依赖 win 系统和 office 软件
如果想实现跨平台处理 excel 请移步 perl 处理 Excel(跨平台)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| use FindBin qw($Bin);
use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel';
my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit');
$Excel->{DisplayAlerts} = 0;
my $Book = $Excel->Workbooks->Open($file); my $Sheet = $Book->Worksheets(1);
my $maxRow = $Sheet->UsedRange->Rows->Count; my $maxCol = $Sheet->UsedRange->Columns->Count;
foreach my $row(1..$maxRow){ foreach my $col(1..$maxCol){ next if $Sheet->Range("$row:$row")->EntireRow->{Hidden};
my $value = $Sheet->Cells($row,$col)->{Value};
$Sheet->Cells($row,$col)->Interior->{Color} = $InColor;
$sheet -> Range("G7:H7") -> Font -> {Bold} = "True";
$sheet -> Range("G7:H7") -> Font -> {Italic} = "True";
$sheet -> Range("G7:H7") -> Font -> {Underline} = xlUnderlineStyleSingle;
$sheet -> Range("G7:H7") -> Font -> {Size} = 8;
$sheet -> Range("G7:H7") -> Font -> {Name} = "Arial";
$sheet -> Range("G7:H7") -> Font -> {ColorIndex} = 4;
$sheet -> Range('A:A') -> {ColumnWidth} = 9.14;
$sheet -> Range("8:8") -> {RowHeight} = 30; } }
$Book->Save(); $Book->Close(); $Excel->Quit();
|